ng-samurai `generate-subentry` schematic fails with Angular 12
Closed this issue ยท 2 comments
The Issue
I'm using ng-samurai
to assist in authoring my library. It's been great!
Recently, I updated my library's repo to Angular 12. With the upgrade, I'm unable to get the generate-subentry
schematic to run. The first error I encounter is due to the JSON Schema.
$ ng g ng-samurai:generate-subentry div
"NgSamuraiSubentry" schema is using the keyword "id" which its support is deprecated. Use "$id" for schema ID.
Schematic input does not validate against the Schema: {"name":"div","project":"ng-indigo","generateComponent":true,"generateModule":true,"style":"css","inlineStyle":false,"inlineTemplate":false,"skipTests":false}
Errors:
Data path "" must NOT have additional properties(generateComponent).
I'm able to get past this issue pretty easily... Just navigate to the node_modules/ng-samurai/subentry/schema.json
file and add the $
prefix to the id
property.
With the updated schema, I get a second error that I'm having trouble getting past:
$ ng g ng-samurai:generate-subentry div
Schematic input does not validate against the Schema: {"name":"div","project":"ng-indigo","generateComponent":true,"generateModule":true,"style":"css","inlineStyle":false,"inlineTemplate":false,"skipTests":false}
Errors:
Data path "" must NOT have additional properties(generateComponent).
Replication
I've created a small lib to demonstrate the issue:
https://github.com/vitale232/ng-indigo
That repo has two branches. The default branch, ng12
, and a second branch, ng11
.
To replicate the issue:
- Clone the repo
- Run
npm install
on theng12
branch - Run
ng g ng-samurai:split-lib
The split-lib
schematic runs, but does produce a warning:
Ng-samurai: Something went wrong while ng-samurai tried to update your tsconfig.json, SyntaxError: Unexpected token / in JSON at position 0
- Run
ng g ng-samurai:generate-subentry div
You should see the errors.
Additional Info
For contrast, you can switch to the ng11
branch, delete node_modules
and package-lock.json
, run npm install
, then go through the same workflow. The same warning occurs on split-lib
.
Importantly to my particular use case, the generate-subentry
schematic runs without any issues.
I think we're affected by a v12 behavioral change. In previous versions, schematics could be passed properties that are not specified in the schema. It appears this was rectified in v12.
I may have this sorted locally, but I'm having a bit of trouble testing it out. I'll confirm it's working, then try to submit a PR.
Basically, rather than spreading _options
to get the moduleSchematicOptions
and componentSchematicOptions
, I'm proposing we explicitly access the relevant props from _options
.
๐ This issue has been resolved in version 3.0.0 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐