fix(cli): honor --pm-on-fail when combined with --help / --version#11489
Conversation
…rcuits The CLI argument parser used to drop every parsed option in the --help and --version short-circuits, so universal flags like --pm-on-fail silently disappeared whenever combined with them. This left users no way to bypass a strict packageManager / devEngines.packageManager check just to read help or check the running pnpm version. Pluck universal options back out of the exploratory parse so they reach getConfig as expected; command-specific options stay dropped since the corresponding command isn't being run. Closes #11487
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR ensures universal CLI options (e.g., --pm-on-fail=ignore) are preserved when parsing short-circuit flags like --help and --version by adding a helper that picks and merges universal options into short-circuit return values. ChangesUniversal Options Preservation
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a CLI parsing edge case where --help and --version short-circuits previously discarded other parsed flags, causing universal options (notably --pm-on-fail) to be ignored and triggering strict packageManager/devEngines.packageManager mismatch errors even when the user explicitly requested bypass behavior.
Changes:
- Preserve universal CLI options when returning early for
--helpand--version. - Add unit coverage in
@pnpm/cli.parse-cli-argsto ensure universal options survive short-circuits and command-specific options do not. - Add an e2e regression test to ensure
--pm-on-fail=ignoreworks with both--helpand--versionin strict package-manager-pinned projects.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
cli/parse-cli-args/src/index.ts |
Preserves universal options in --help/--version early-return paths. |
cli/parse-cli-args/test/index.ts |
Adds regression tests for universal-option preservation and non-leakage of command-specific flags under --help/--version. |
pnpm/test/packageManagerCheck.test.ts |
Adds e2e regression coverage ensuring --pm-on-fail=ignore bypasses strict checks even when combined with --help/--version. |
.changeset/pm-on-fail-survives-help-version.md |
Documents the behavior change as a patch release for affected packages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…p/version Without this, --prefix (mapped to dir in pnpm) and --store (mapped to store-dir) would land in cliOptions under their unrenamed keys when combined with --help/--version, while the regular parse path renames them. Apply the same renamedOptions mapping in pickUniversalOptions so consumers see consistent option names regardless of the entry path.
…11489) The CLI argument parser short-circuits `--help` and `--version` and was discarding every other parsed option in the process — including universal flags like `--pm-on-fail`. So `pnpm audit --pm-on-fail=ignore --help` and `pnpm --pm-on-fail=ignore --version` failed with the strict `packageManager` mismatch error instead of doing what was asked. Users had no documented way out: the suggested escape hatch in the error message itself didn't work. The fix plucks universal options back out of the exploratory `nopt` parse and surfaces them through both short-circuits. They were already typed correctly there; only the regular per-command parse adds command-specific options. Command-specific options (e.g. `--frozen-lockfile`) stay dropped, since the matching command isn't being executed. Closes [#11487](#11487).
Summary
The CLI argument parser short-circuits
--helpand--versionand was discarding every other parsed option in the process — including universal flags like--pm-on-fail. Sopnpm audit --pm-on-fail=ignore --helpandpnpm --pm-on-fail=ignore --versionfailed with the strictpackageManagermismatch error instead of doing what was asked. Users had no documented way out: the suggested escape hatch in the error message itself didn't work.The fix plucks universal options back out of the exploratory
noptparse and surfaces them through both short-circuits. They were already typed correctly there; only the regular per-command parse adds command-specific options. Command-specific options (e.g.--frozen-lockfile) stay dropped, since the matching command isn't being executed.Closes #11487.
Test plan
cli/parse-cli-argscovering--helpand--versionshort-circuits with universal options, and a negative test that command-specific options do not leak throughpnpm/test/packageManagerCheck.test.tsexercising all four orderings (--pm-on-fail=ignore --version,--version --pm-on-fail=ignore,audit --pm-on-fail=ignore --help,audit --help --pm-on-fail=ignore) against a strictdevEngines.packageManagerpinpackageManagerCheck.test.tsandcli/parse-cli-argstest suites passWritten by an agent (Claude Code, claude-opus-4-7).
Summary by CodeRabbit