Conversation
The `--prefix` option (renamed to `dir`) was applied to options after `getWorkspaceDir` had already run, so workspace detection fell back to `process.cwd()` and missed the manifest at the prefix dir. As a result, `pnpm --prefix=<dir> install` from a parent directory would overwrite `<dir>/pnpm-workspace.yaml` `allowBuilds` entries with placeholders because the existing settings were never loaded into config. Closes #11535
📝 WalkthroughWalkthroughThis PR fixes a bug where ChangesPrefix Workspace Resolution
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Poem
🚥 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
Fixes workspace root detection when --prefix is used (and renamed to dir) so pnpm --prefix=<dir> install resolves the workspace from the prefixed directory instead of process.cwd(), preventing unintended overwrites of pnpm-workspace.yaml settings (e.g. allowBuilds) as reported in #11535.
Changes:
- Apply
renamedOptions(notablyprefix → dir) before workspace detection in the main parse path. - Teach
--help/--versionshort-circuit paths to resolveworkspaceDirwhile honoringrenamedOptions. - Add a regression test and a changeset documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cli/parse-cli-args/src/index.ts |
Moves option renaming ahead of workspace detection and updates getWorkspaceDir to account for renamed options on short-circuit paths. |
cli/parse-cli-args/test/index.ts |
Adds a regression test ensuring workspaceDir resolves from --prefix (via prefix → dir rename). |
.changeset/prefix-workspace-resolution.md |
Adds a patch changeset for pnpm and @pnpm/cli.parse-cli-args describing the fix for #11535. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… help/version regression tests Address review feedback on #11549: - Skip the rename when the target key is already set (e.g. `--prefix=foo --dir=bar` keeps `dir=bar`), so the alias never silently clobbers an explicitly-passed canonical option. The alias is always dropped. - Add regression tests asserting `workspaceDir` resolves from `--prefix` on the `--help` and `--version` short-circuit paths.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cli/parse-cli-args/test/index.ts (1)
408-415: ⚡ Quick winMove the helper declaration below its call sites to match project style.
setupParentWithChildWorkspaceis declared before usage; this file’s guideline expects hoisted function declarations after use. Please move this helper to the end of the file (no behavior change needed).As per coding guidelines, "Declare functions after they are used, relying on hoisting".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cli/parse-cli-args/test/index.ts` around lines 408 - 415, The helper function setupParentWithChildWorkspace is declared before its call sites; move its entire declaration block so it appears after the tests that call it (i.e., place setupParentWithChildWorkspace at the end of this test file) to follow the project's "declare after use" style, ensuring you do not change the function body or references (keep fs.mkdirSync, fs.writeFileSync, path.join and process.chdir usage intact).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cli/parse-cli-args/test/index.ts`:
- Around line 408-415: The helper function setupParentWithChildWorkspace is
declared before its call sites; move its entire declaration block so it appears
after the tests that call it (i.e., place setupParentWithChildWorkspace at the
end of this test file) to follow the project's "declare after use" style,
ensuring you do not change the function body or references (keep fs.mkdirSync,
fs.writeFileSync, path.join and process.chdir usage intact).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1d2ca5bc-9cda-4caf-a09e-19d681395b3d
📒 Files selected for processing (2)
cli/parse-cli-args/src/index.tscli/parse-cli-args/test/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- cli/parse-cli-args/src/index.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Analyze (javascript)
- GitHub Check: Compile & Lint
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{js,ts,tsx,jsx}: Use trailing commas in code following Standard Style with modifications
Prefer functions over classes
Declare functions after they are used, relying on hoisting
Functions should have no more than two or three arguments; use a single options object for functions needing more parameters
Organize imports in order: standard libraries, external dependencies (sorted alphabetically), then relative imports
Files:
cli/parse-cli-args/test/index.ts
🔇 Additional comments (1)
cli/parse-cli-args/test/index.ts (1)
417-456: Strong regression coverage for the--prefix/--dirworkspace resolution fix.Nice job covering the normal path,
--help/--versionshort-circuits, and canonical-option precedence in one focused block.
The `--prefix` option (renamed to `dir`) was applied to options after `getWorkspaceDir` had already run, so workspace detection fell back to `process.cwd()` and missed the manifest at the prefix dir. As a result, running pnpm from outside the project (e.g. `pnpm --prefix=child install` from the parent dir) silently skipped settings declared in `child/pnpm-workspace.yaml`. Backport of #11549 to release/10. Closes #11535.
Summary
Fixes #11535. Running
pnpm --prefix=<dir> installfrom a parent directory was overwriting<dir>/pnpm-workspace.yaml, replacing user-setallowBuildsvalues (e.g.true) withset this to true or falseplaceholders.The CLI's
--prefix → dirrename was applied aftergetWorkspaceDir(options)had already run, so workspace detection fell back toprocess.cwd()and missed the manifest at the prefix dir. With no workspace manifest loaded,config.allowBuildsended up as{}, and the ignored-builds auto-population step (handleIgnoredBuilds) wrote placeholders over the user's existing settings.The fix moves the rename loop ahead of
getWorkspaceDiron the main parse path, and threadsrenamedOptionsintogetWorkspaceDirso the--help/--versionshort-circuit paths also resolve--prefixcorrectly.Test plan
cli/parse-cli-args/test/index.ts— verified it fails onmainand passes with the fix@pnpm/cli.parse-cli-argspassWritten by an agent (Claude Code, claude-opus-4-7).
Summary by CodeRabbit
Bug Fixes
pnpm --prefix=<dir> installoverwriting a workspace manifest with placeholder values;--prefixnow correctly affects workspace root detection to prevent unintended file changes.Tests
--prefix(and interactions with--dir), including short-circuit paths like--help/--version.