angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.79k stars 11.98k forks source link

[Schematics CLI] Numeric strings in schematics options #24360

Open dgp1130 opened 2 years ago

dgp1130 commented 2 years ago

Command

generate

Is this a regression?

The previous version in which this bug was not present was

No response

Description

From http://b/196605664.

Apparently you can't pass in a numeric value into a string argument in schematics. This appears to be interpreted as number and leads to a validation error.

Minimal Reproduction

$ schematics run test --stringValue "1234"
Schematic input does not validate against the Schema: {"stringValue":1234}
Errors:

  Data path ".stringValue" should be string.

Minimist seems to interpret "1234" as a number instead of a string, and schematics treats that as a type mismatch.

Exception or Error

No response

Your Environment

See http://b/196605664.

Anything else relevant?

No response

alan-agius4 commented 2 years ago

In schematics CLI we don’t really configure the parser based on the schematics schema.

We could probably port this logic from the Angular CLI. (Maybe have the logic in a shared ts_libraary) when the legacy build system is removed.

dgp1130 commented 2 years ago

Yeah, I know minimist doesn't work that way. We'd probably have to change argument parser to actually declare specific options with specific types based on the schematics schema for the ideal solution. Not sure if there's a simpler fix worth exploring, but it's a relatively minor bug so I'm not too worried.

alan-agius4 commented 2 years ago

Just for the record we no longer use minimist. We use yargs-parser.

Note: this would also solve https://github.com/angular/angular-cli/issues/12152

alan-agius4 commented 2 years ago

Same root cause/resolution of https://github.com/angular/angular-cli/issues/16320.

We could combine these issues.