Skip to content

[CLI][Schematics] Override Angular Schematics issue - no way to determine which arguments were provided by the user and which ones by the CLI parser #29971

@SlawomiKussowski

Description

@SlawomiKussowski

Command

generate

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

Unknown

Description

If you try to override standard Angular Schematics with a custom one by the use of schematicCollections option in angular.json file like for instance:

"cli": { "analytics": false, "schematicCollections": [ "./schematics", "@schematics/angular" ] }

And create your custom schematics (index.ts):

export function generateComponent(options: ComponentOptions): Rule {
  console.log('options', structuredClone(options));
  return (_tree: Tree, _context: SchematicContext) => {
    return externalSchematic(
      "@schematics/angular",
      "component",
      options
    );
  };
}

And define custom defaults using angular.json file, like for instance:

  "cli": {
    "analytics": false,
    "schematicCollections": [
      "./schematics",
      "@schematics/angular"
    ]
  },
    "schematics": {
    "@schematics/angular:component": {
      "inlineTemplate": false,
      "inlineStyle": false,
      "style": "scss",
      "skipTests": true
    }
  }

You will notice that your defaults are ignored.

Moreover, in options argument from generateComponent function the values are already parsed by the cli making it impossible to distinguish which ones were provided by the user and which ones by the parser.

Minimal Reproduction

Please use the attached repo to reproduce the issue:

Execute schematics:

ng g c test

Options values received in generateComponent function:

options {
  name: 'test',
  path: undefined,
  project: 'schematics-test',
  displayBlock: false,
  inlineStyle: false,
  inlineTemplate: false,
  standalone: true,
  viewEncapsulation: undefined,
  changeDetection: 'Default',
  prefix: undefined,
  style: 'css',
  type: 'Component',
  skipTests: false,
  flat: false,
  skipImport: false,
  selector: undefined,
  skipSelector: false,
  module: undefined,
  export: false,
  exportDefault: false
}

Exception or Error


Your Environment

Angular CLI: 19.2.5
Node: 22.13.0
Package Manager: npm 8.6.0
OS: win32 x64

Angular: 19.2.4
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.5
@angular-devkit/build-angular   19.2.5
@angular-devkit/core            19.2.5
@angular-devkit/schematics      19.2.5
@angular/cli                    19.2.5
@schematics/angular             19.2.5
rxjs                            7.8.1
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions