Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng g directive generate wrong import in a module #2762

Closed
akomm opened this issue Oct 18, 2016 · 7 comments · Fixed by #2883
Closed

ng g directive generate wrong import in a module #2762

akomm opened this issue Oct 18, 2016 · 7 comments · Fixed by #2883
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@akomm
Copy link

akomm commented Oct 18, 2016

OS?

Ubuntu 14.04 lts

Versions.

angular-cli: 1.0.0-beta.17
node: 5.6.0

Repro steps.

  • ng new test
  • cd test
  • ng g module modulename
  • cd src/app/modulename
  • ng g directive directivename

The log given by the failure.

No failure

Expected result

Generates files:

  • src/app/modulename/modulename.module.ts
  • src/app/modulename/modulename.component.ts
  • src/app/modulename/modulename.component..spec.ts
  • src/app/modulename/modulename.component.html
  • src/app/modulename/modulename.component.css
  • src/app/modulename/directivename/directivename.directive.ts
  • src/app/modulename/directivename/directivename.directive.spec.ts

Content of src/app/modulename/modulename.module.ts:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ModulenameComponent } from './modulename.component';
import { DirectivenameDirective } from './directivename/directivename.directive';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [ModulenameComponent, DirectivenameDirective]
})
export class ModulenameModule { }

Actual result (what's wrong - DIFF)

  • src/app/modulename/directivename.directive.ts
  • src/app/modulename/directivename.directive.spec.ts

Content of src/app/modulename/modulename.module.ts:

// ...
import { DirectivenameDirective } from './modulename/directivename.directive';
// ...

Problem

  1. ng g directive does not behave like ng g component, which generate output similar to the expected one.
  2. Ignoring the 1. problem, it still generates wrong import path, resolving relative to src/app and not src/app/module.
@akomm
Copy link
Author

akomm commented Oct 18, 2016

Found the difference is that the component blueprint has the option flat default set to false and the directive blueprint has it set by default to true. When I use ng g directive modulename/directivename --flat=false problem 1 is fixed, but problem 2 still exists.

@filipesilva
Copy link
Contributor

@Brocco can you have a look?

@filipesilva filipesilva added command: generate P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Oct 23, 2016
@akomm
Copy link
Author

akomm commented Oct 24, 2016

If you want to know whether it was fixed in beta.18: No. Tested it :)

@Brocco
Copy link
Contributor

Brocco commented Oct 25, 2016

This seems to be behaving as expected...

 ~/dev/mlb/bar (master): ng g module modulename
installing module
  create src/app/modulename/modulename.module.ts
installing component
  create src/app/modulename/modulename.component.css
  create src/app/modulename/modulename.component.html
  create src/app/modulename/modulename.component.spec.ts
  create src/app/modulename/modulename.component.ts
 ~/dev/mlb/bar (master): ng g directive directivename
installing directive
  create src/app/directivename.directive.spec.ts
  create src/app/directivename.directive.ts

modulename is created in it's own directory... as expected
directivename is created in the app directory... as expected
and directivename is imported and declared in app.module.ts... as expected (shown here)

...
import { DirectivenameDirective } from './directivename.directive';
@NgModule({
  declarations: [
    AppComponent,
    DirectivenameDirective
  ]
...

@akomm
Copy link
Author

akomm commented Oct 25, 2016

You are not creating it in a module, as I'v shown in the reproduction. As I'v said:
generates wrong import path, resolving relative to src/app and not src/app/module
and ng g directive generate wrong import |in a module|

Since you'v created it in src/app, it obviously works. I assume it is intended to work inside of modules, because the ng g component works, why should directives not?

@Brocco
Copy link
Contributor

Brocco commented Oct 25, 2016

I followed your repro steps...

ng new test
cd test
ng g module modulename
ng g directive directivename

should they be?

ng new test
cd test
ng g module modulename
cd src/app/modulename
ng g directive directivename

With those repro steps I was able to reproduce this issue (I updated your repro steps above)

FYI, this is also an issue with pipe generations.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants