Repository navigation
fix(package-manager): honor scriptShell for lifecycle scripts - #13453
Conversation
`scriptShell` reached only `pnpm run` / `pnpm exec` (and `pnpm version`). Every lifecycle script the install spawns passed `script_shell: None` and so ran under the platform default, `sh` or `cmd`, however the workspace had configured its shell. The TypeScript CLI threads `scriptShell` into the same runs through `scriptsOpts`, so a workspace whose scripts assume its configured shell worked there and not here. Thread `config.script_shell` to the three contexts that spawn scripts during an install: dependency build scripts, a project's own lifecycle scripts, and `pnpm:devPreinstall`. Deliberately unchanged, because the TypeScript CLI does not pass `scriptShell` there either and matching it is the point: - git-hosted dependency preparation (`install_package_by_snapshot`, `patch`), whose counterpart `exec/prepare-package` builds its `RunLifecycleHookOptions` without the field. - `pack` and `publish` lifecycle scripts, likewise. The tests spawn through a shell shim that records each script it is handed, so a context that ignores the setting fails rather than silently falling back to the default shell. Unix-only: the probe is a shell script, and `select_shell` rejects `.cmd` / `.bat` shims on Windows.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesLifecycle script shell selection
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WorkspaceConfig
participant Install
participant BuildModules
participant RunPostinstallHooks
participant LifecycleScripts
WorkspaceConfig->>Install: configure scriptShell
Install->>RunPostinstallHooks: pass configured shell for project hooks
Install->>BuildModules: pass configured shell
BuildModules->>RunPostinstallHooks: pass configured shell for dependency hooks
RunPostinstallHooks->>LifecycleScripts: spawn lifecycle scripts with selected shell
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoHonor scriptShell for install-time lifecycle scripts
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "test(cli): derive the probe shell's log ..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@pnpm/crates/cli/tests/lifecycle_scripts.rs`:
- Line 2280: Update the generated shell script in the lifecycle script test to
stop interpolating the Rust-formatted log path into its contents. In the script
template around the `format!` call, derive the log destination at runtime from
the shim location (such as via `$0` and its parent directory), preserving
invocation logging without allowing temporary path contents to be interpreted as
shell syntax.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 15248099-16f6-4d6e-9367-c28f74a8c503
📒 Files selected for processing (6)
.changeset/script-shell-for-lifecycle-scripts.mdpnpm/crates/cli/tests/lifecycle_scripts.rspnpm/crates/package-manager/src/build_modules.rspnpm/crates/package-manager/src/build_modules/tests.rspnpm/crates/package-manager/src/install.rspnpm/crates/package-manager/src/install_frozen_lockfile.rs
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1. scriptShell PATH shadowing
|
Micro-Benchmark ResultsLinux |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13453 +/- ##
==========================================
+ Coverage 87.60% 87.65% +0.04%
==========================================
Files 545 545
Lines 93698 94124 +426
==========================================
+ Hits 82085 82505 +420
- Misses 11613 11619 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The shim had the log path interpolated into its body, so the temp directory's name became `/bin/sh` source. Nothing generates a path with shell metacharacters here — the name comes from `tempfile` — but a test shim that parses part of its own path as code is a bad shape to leave around. Derive the path from `$0` instead, so the shim's body is a constant.
On the
|
|
Code review by qodo was updated up to the latest commit 3a1ce34 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Summary
scriptShellreached onlypnpm run/pnpm exec(andpnpm version). Every lifecycle script the install spawns passedscript_shell: Noneand so ran under the platform default —shon POSIX,cmdon Windows — however the workspace had configured its shell. The TypeScript CLI threadsscriptShellinto the same runs throughscriptsOpts, so a workspace whose scripts assume its configured shell worked there and silently did not here.This threads
config.script_shellto the three contexts that spawn scripts during an install:build_modules.rs(via a newBuildModules::script_shell)preinstall/install/postinstall/prepareinstall.rsrun_projects_lifecycle_scriptspnpm:devPreinstallinstall.rsrun_dev_preinstallFound while reviewing #13403, where a reviewer flagged the missing
scriptShellon the newpnpm:devPreinstallcall. It was not specific to that hook — every lifecycle call site had it — so it was left for its own change rather than fixed for one stage and not the rest.Deliberately unchanged
Not every
script_shell: Noneis a gap. These stay as they are because the TypeScript CLI does not passscriptShellthere either, and matching it is the whole point:install_package_by_snapshot.rs,patch.rs) — the counterpart,exec/prepare-package, builds itsRunLifecycleHookOptionswithdepPath/pkgRoot/rootModulesDir/unsafePerm/userAgentand noscriptShell.packandpublishscripts —publish.tsbindsrunScriptsIfPresentwith the same field set, likewise without it.Changing those would be a unilateral divergence, not a fix.
Testing
The tests point
scriptShellat a shell shim that appends every script it is handed to a log, then execs the real/bin/sh. A context that ignores the setting never appears in the log, so the test fails rather than silently passing on a default-shell fallback. I confirmed both tests fail with the three wirings reverted toNone.Unix-only (
#[cfg(unix)]): the probe is a shell script, andselect_shellalready rejects.cmd/.batshims on Windows.Related to #12042, whose checklist marks
scriptShellas done — accurate forpnpm run, which is presumably what was verified, but not for lifecycle scripts.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
scriptShellwhen running dependency build scripts and project lifecycle scripts during installation.preinstall,install,postinstall,prepare, andpnpm:devPreinstall) now consistently use the selected shell.Tests
scriptShellis applied beyondpnpm run, including for dependency build and lifecycle markers.