fix(inject-migration): ng CLI option name problem #403
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
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:
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:
and the generator executes normally, see the options at runtime:
The fix
Use the same alias as the initial option name, but just update the option name internally at the source code.