Skip to content

schematics-cli: --dry-run=false, --debug=false and other built-in boolean flags are treated as true #34199

Description

@rsreimer

Command

other

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When a built-in boolean CLI option gets an inline value (--dry-run=false, --debug=false, --force=false, --interactive=false, ...), the value is parsed as the string 'false' not the boolean false.

In packages/angular_devkit/schematics_cli/bin/schematics.ts, parseOptions calls parseArgs with strict: false.
In non-strict mode, Node doesn't validate inline values for type: 'boolean' options. It returns them as raw strings:

const { parseArgs } = require('node:util');
parseArgs({
  args: ['--dry-run=false', '--debug=true'],
  strict: false, allowPositionals: true, allowNegative: true,
  options: { 'dry-run': { type: 'boolean' }, debug: { type: 'boolean' } },
}).values;
// => { 'dry-run': 'false', debug: 'true' }   <-- strings, not booleans

The token loop in parseOptions skips these options (if (name in CLI_OPTION_DEFINITIONS) continue;). That means the 'true'/'false' conversion added in #32362 never runs for them, and values is returned unchanged as cliOptions. Then in main:

const debug = cliOptions.debug ?? isLocalCollection;   // 'false' -> truthy
const dryRun = cliOptions['dry-run'] ?? debug;         // 'false' -> truthy

Minimal Reproduction

// package.json
{
  "name": "repro",
  "dependencies": {
    "@angular-devkit/schematics-cli": "22.2.0"
  }
}
// my-schematics/collection.json
{
  "schematics": {
    "hello": {
      "description": "x", "factory": "./index.js#hello"
    }
  }
}
// my-schematics/index.js
exports.hello = () => (tree) => {
  tree.create('hello.txt', 'hi');
  return tree;
};
npx schematics ./my-schematics/collection.json:hello --dry-run=false
Debug mode enabled by default for local collections.
CREATE hello.txt (2 bytes)
Dry run enabled. No files written to disk.

Exception or Error

`Dry run enabled. No files written to disk.`

Your Environment

@angular-devkit/schematics-cli: 22.2.0
Node: v22.22.3
OS: macOS

Anything else relevant?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions