Passing null options to RunSchematicTask leads to CLI crash #21023
Milestone
Comments
|
Sounds like a reasonable change to me, but in this case we need to also fix the casting. Maybe even remove it. Feel free to create a PR. |
|
If no one has taken this Issue yet I would love to use it for my first contribution to angular :) |
|
@martinakraus, go for it! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command (mark with an
x)Is this a regression?
Yes, the previous version in which this bug was not present was: 11.xDescription
Using
context.addTask(new RunSchematicTask(schematicName, Options))inside a schematic, we can schedule another schematic. Until (including) Angular 11 we could simply passnullas secondOptionsparameter.Starting with Angular 12 the CLI will crash with the error message
Cannot read property 'project' of null.Run a schematic (using
ng addorng g) that itself tries to run another schematic usingcontext.addTask(new RunSchematicTask(schematicName, null))(nullis important here).Since the
ng-addschematic of@da-mkay/ng-builder-electronuses the above mentioned code you can use these commands to reproduce the issue:(Version 0.2.0 is important as I will release a new version in a moment)
Anything else relevant?
The issue is caused by the following line inside
SchematicCommandclass:https://github.com/angular/angular-cli/blob/master/packages/angular/cli/models/schematic-command.ts#L247
Here,😉
currentis what we pass as second argument to theRunSchematicTaskconstructor (null). Since that parameter is typed as genericT, IMHO we should be able to passnullhere. But maybe I'm wrongAs a workaround I can pass
{}instead ofnullto theRunSchematicTaskconstructor.A solution would be to change the above line to:
(added
?)I can also create a PR for that gigantic change if needed😋
The text was updated successfully, but these errors were encountered: