Skip to content

fix(cli): honor --pm-on-fail when combined with --help / --version#11489

Merged
zkochan merged 2 commits into
mainfrom
fix/11487-help-pm-on-fail
May 6, 2026
Merged

fix(cli): honor --pm-on-fail when combined with --help / --version#11489
zkochan merged 2 commits into
mainfrom
fix/11487-help-pm-on-fail

Conversation

@zkochan

@zkochan zkochan commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

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.

Test plan

  • New unit tests in cli/parse-cli-args covering --help and --version short-circuits with universal options, and a negative test that command-specific options do not leak through
  • New parameterized e2e test in pnpm/test/packageManagerCheck.test.ts exercising 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 strict devEngines.packageManager pin
  • Existing packageManagerCheck.test.ts and cli/parse-cli-args test suites pass

Written by an agent (Claude Code, claude-opus-4-7).

Summary by CodeRabbit

  • Bug Fixes
    • Universal CLI options (e.g., --pm-on-fail=ignore) are now honored when used with --help or --version, preventing spurious package manager mismatch messages and ensuring the requested action runs.
  • Tests
    • Added regression tests covering help/version short-circuit paths and preservation of universal options.

…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
Copilot AI review requested due to automatic review settings May 6, 2026 11:34
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1408adaa-83e1-4011-bc2f-cff60089184d

📥 Commits

Reviewing files that changed from the base of the PR and between 147a17d and b8b61d7.

📒 Files selected for processing (2)
  • cli/parse-cli-args/src/index.ts
  • cli/parse-cli-args/test/index.ts

📝 Walkthrough

Walkthrough

This 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.

Changes

Universal Options Preservation

Layer / File(s) Summary
Parsing Short-circuit behavior
cli/parse-cli-args/src/index.ts
Short-circuit paths for --version and --help now merge universal options into the returned options object.
Universal options extraction
cli/parse-cli-args/src/index.ts
Introduces pickUniversalOptions() to collect keys defined in universalOptionsTypes from exploratory nopt results for merging.
Help-specific parsing
cli/parse-cli-args/src/index.ts
getParsedArgsForHelp updated to include picked universal options in its returned structure.
Unit tests
cli/parse-cli-args/test/index.ts
Adds regression tests verifying universal options (including renamed options) survive --help/--version short-circuits and that command-specific options do not leak.
Integration test
pnpm/test/packageManagerCheck.test.ts
Adds parameterized test ensuring --pm-on-fail=ignore is honored with --version and --help, avoiding spurious packageManager mismatch errors.
Changelog / release
.changeset/pm-on-fail-survives-help-version.md
Patch-level changeset documenting the behavioral fix for @pnpm/cli.parse-cli-args and pnpm.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A flag once lost to short-circuit ways,
Now blooms bright through help and version days,
--pm-on-fail now always thrives,
In every parse, the option survives!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: honoring --pm-on-fail when combined with --help/--version flags, which is the core issue being addressed.
Linked Issues check ✅ Passed The PR comprehensively addresses all requirements from issue #11487: extracting universal options in short-circuit paths, adding unit and e2e tests, ensuring --pm-on-fail is honored with --help/--version in any flag order.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the --pm-on-fail handling with --help/--version: the changeset, CLI parser refactoring, unit tests, and e2e tests are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/11487-help-pm-on-fail

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --help and --version.
  • Add unit coverage in @pnpm/cli.parse-cli-args to ensure universal options survive short-circuits and command-specific options do not.
  • Add an e2e regression test to ensure --pm-on-fail=ignore works with both --help and --version in 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.

Comment thread cli/parse-cli-args/src/index.ts
…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.
@zkochan zkochan merged commit bcd337f into main May 6, 2026
13 checks passed
@zkochan zkochan deleted the fix/11487-help-pm-on-fail branch May 6, 2026 12:28
zkochan added a commit that referenced this pull request May 6, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: --pm-on-fail=ignore fails to ignore

2 participants