Skip to content

Boolean options not parsed correctly on schematics cli #12150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexeagle opened this issue Sep 4, 2018 · 3 comments · Fixed by #22779
Closed

Boolean options not parsed correctly on schematics cli #12150

alexeagle opened this issue Sep 4, 2018 · 3 comments · Fixed by #22779
Labels
Milestone

Comments

@alexeagle
Copy link
Contributor

From @TinyMan on January 14, 2018 17:11

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

> node --version
v8.9.4
> npm --version
5.6.0
> ver
Microsoft Windows [version 10.0.16299.192]

> npm list -g --depth=0
+-- UNMET PEER DEPENDENCY @angular-devkit/[email protected]
+-- @angular-devkit/[email protected]
+-- @angular/[email protected]
+-- @schematics/[email protected]
+-- @types/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

npm ERR! peer dep missing: @angular-devkit/[email protected], required by @schematics/[email protected]
npm ERR! peer dep missing: @angular-devkit/[email protected], required by @schematics/[email protected]
npm ERR! peer dep missing: @angular-devkit/[email protected], required by @schematics/[email protected]

Repro steps

> schematics @schematics/angular:module --name test --routing true

The log given by the failure

Schematic input does not validate against the Schema: {"name":"test","routing":"true","path":"app","sourceDir":"src","routingScope":"Child","spec":true,"flat":false,"commonModule":true}
Errors:
  .routing should be boolean

Desired functionality

Boolean options should be parsed.
Right now it is true if only --routing is specified but it fails with --routing false or --routing true.
For --routing option it is not really a problem because by default it is false: we can set it to true with --routing.
However it is blocking for custom schematics with boolean option that defaults to true: we can't set it to false.

Mention any other details that might be useful

Only the arguments specified here are parsed as booleans:
https://github.com/angular/devkit/blob/c88d991344a910903c2178b537a919c9da2de03f/packages/angular_devkit/schematics_cli/bin/schematics.ts#L102

After this minimist assigns the string "true" or "false" to the option hence the error.

Copied from original issue: angular/devkit#393

@dxvladislavvolkov
Copy link

Any news about this?

@musou1500
Copy link

How about using coerceTypes option?
here is a coercion rules https://github.com/epoberezkin/ajv/blob/master/COERCION.md

The patch will be as follows.

diff --git a/packages/angular_devkit/core/src/json/schema/registry.ts b/packages/angular_devkit/core/src/json/schema/registry.ts
index 06321af8..5638fa08 100644
--- a/packages/angular_devkit/core/src/json/schema/registry.ts
+++ b/packages/angular_devkit/core/src/json/schema/registry.ts
@@ -115,6 +115,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
       loadSchema: (uri: string) => this._fetch(uri),
       schemaId: 'auto',
       passContext: true,
+      coerceTypes: true
     });

     this._ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants