Yes, the previous version in which this bug was not present was: 11.x
Description
Using context.addTask(new RunSchematicTask(schematicName, Options)) inside a schematic, we can schedule another schematic. Until (including) Angular 11 we could simply pass null as second Options parameter.
Starting with Angular 12 the CLI will crash with the error message Cannot read property 'project' of null.
🔬 Minimal Reproduction
Run a schematic (using ng add or ng g) that itself tries to run another schematic using context.addTask(new RunSchematicTask(schematicName, null)) (null is important here).
Since the ng-add schematic of @da-mkay/ng-builder-electron uses the above mentioned code you can use these commands to reproduce the issue:
$ ng new workspace --create-application=false
$ cd workspace
$ ng add @da-mkay/ng-builder-electron@0.2.0
(Version 0.2.0 is important as I will release a new version in a moment)
typeof (current as Record<string, unknown>).project === 'string'
Here, current is what we pass as second argument to the RunSchematicTask constructor (null). Since that parameter is typed as generic T, IMHO we should be able to pass null here. But maybe I'm wrong 😉
As a workaround I can pass {} instead of null to the RunSchematicTask constructor.
A solution would be to change the above line to:
typeof (current as Record<string, unknown>)?.project === 'string'
(added ?)
I can also create a PR for that gigantic change if needed 😋
The text was updated successfully, but these errors were encountered:
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 passnull
as secondOptions
parameter.Starting with Angular 12 the CLI will crash with the error message
Cannot read property 'project' of null
.Run a schematic (using
ng add
orng g
) that itself tries to run another schematic usingcontext.addTask(new RunSchematicTask(schematicName, null))
(null
is important here).Since the
ng-add
schematic of@da-mkay/ng-builder-electron
uses 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
SchematicCommand
class:https://github.com/angular/angular-cli/blob/master/packages/angular/cli/models/schematic-command.ts#L247
Here,😉
current
is what we pass as second argument to theRunSchematicTask
constructor (null
). Since that parameter is typed as genericT
, IMHO we should be able to passnull
here. But maybe I'm wrongAs a workaround I can pass
{}
instead ofnull
to theRunSchematicTask
constructor.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: