ngxtension / ngxtension-platform

Utilities for Angular
https://ngxtension.netlify.app/
MIT License
531 stars 77 forks source link

fix(inject-migration): ng CLI option name problem #403

Closed ilirbeqirii closed 1 month ago

ilirbeqirii commented 1 month ago

For the "inject-di-migration", a new option "useESPrivateFieldNotation" was added to support replacing TS "private" properties with ES private field properties.

However, an issue is found when executing the generator with the newly added option, and it's because of the option's name, "useESPrivateFieldNotation".

Running with Angular CLI

When running the schematic in a plain Angular app, i.e through Angular CLI with the "--help" option to get more insights about the schematic itself, we get the following:

ng-cli generator options

Listed as the last one, besides the alias name provided in schema json , ngCLI also generates another, default alias: dash-separated name ( --use-esprivate-field-notation ).

Till now it's ok. but when we execute the schematic to do the work it's intended to and check the options at runtime, you can see that neither the alias nor the option name in the schema is being used:

ng-cli options at runtime

As you can notice, the original name option, "useESPrivateFieldNotation" is undefined, and ngCLI has created another option under the hood, "useEsprivateFieldNotation", which is the same as the original option name but with "...ESP..." subsection in lowercase:

                           useESPrivateFieldNotation -> useEsprivateFieldNotation

Because of this when running with Angular CLI, the schematic never applied the feature offered with that option.

Running with Nx

If you check the same config of the generator with Nx, there are no extra aliases generated, and naming is non-sensitive:

Screen Shot 2024-06-03 at 09 43 35

and the generator executes normally, see the options at runtime:

Screen Shot 2024-06-03 at 09 44 25

The fix

Use the same alias as the initial option name, but just update the option name internally at the source code.