angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

`ng generate module` with routing doesn't follow component schematics

Open nsebs opened this issue 6 years ago • 3 comments

🐞 ng generate module with routing doesn't follow component schematics

Is this a regression?

I believe it is, since this is working correctly on versions before 11.

Description

When you create a new lazy loaded module with routing using the cli:

ng generate module home -m app --route 'home' --routing

the generated component doesn't follow the schematics.

🔬 Minimal Reproduction

To test this you need to

  • create a new project
  • the component schematics and generate a new lazy loaded module
  • check the output
npx -p @angular/cli@11 ng new test --strict --routing --style=scss

cd test

ng generate module home -m app --route 'home' --routing

The cli will create a .css file instead of an .scss (and the component will point to this css instead of a scss file).

I also modified the angular.json manually to add "changeDetection": "OnPush", and it gets ignored too.

🌍 My Environment

Angular Version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 11.0.0
Node: 12.18.3
OS: linux x64

Angular: 11.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.0
@angular-devkit/build-angular   0.1100.0
@angular-devkit/core            11.0.0
@angular-devkit/schematics      11.0.0
@schematics/angular             11.0.0
@schematics/update              0.1100.0
rxjs                            6.6.3
typescript                      4.0.5


Anything else relevant?

Is worth mentioning that if you create a new component using the cli, the component will follow the schematics without any problem.

nsebs avatar Nov 12 '20 18:11 nsebs

Had a look at this, and this was regression was introduced via https://github.com/angular/angular-cli/pull/18945.

The problem here is that validateOptionsWithSchema options transformer is being invoked prior to defaultOptionTransform which causes the values of getSchematicDefaults to be overridden by the defaults set in the schematics schema.json.

While disabling NodeWorkflow's schemaValidation and adding back validateOptionsWithSchema in SchematicCommand will do the trick. I am not sure if there is a cleaner alternative.

@clydin, mind chiming in.

alan-agius4 avatar Nov 13 '20 09:11 alan-agius4

Thank you, people :heart:

nsebs avatar Nov 16 '20 18:11 nsebs

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.