Conversation
When a project's package.json has a script named "clean", "setup", or "deploy", running `pnpm clean/setup/deploy` now executes the script instead of the built-in command. This prevents surprising behavior for users with existing scripts. When running from a workspace subdirectory where the root package.json has one of these scripts, an error is thrown with guidance on how to proceed. Added "purge" as an alias for the built-in clean command, which always runs the built-in regardless of scripts. Closes #6816
Each command now declares `scriptOverride = true` instead of a centralized list in main.ts. All command names including aliases are overridable by same-named scripts.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes pnpm’s command dispatch so certain built-in commands can be overridden by same-named package.json scripts, and introduces purge as an alternate entrypoint to the clean behavior.
Changes:
- Add an
overridableByScriptcommand capability and apply it toclean,setup, anddeploy(and currently alsorebuild). - Implement main-process redirection to
pnpm run <cmd>when an overridable command has a same-named script, with a workspace-subdir error when the root has the script. - Add tests covering
clean/purgebehaviors and the workspace-root override error.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm/src/main.ts |
Adds runtime redirection from built-in commands to pnpm run when scripts override. |
pnpm/src/cmd/index.ts |
Extends command definition metadata and builds a set of overridable commands. |
pnpm/src/cmd/clean.ts |
Adds purge alias and marks clean as script-overridable. |
pnpm/test/clean.ts |
Adds test coverage for script override, purge behavior, and workspace-root override error. |
releasing/commands/src/deploy/deploy.ts |
Marks deploy as script-overridable. |
engine/pm/commands/src/setup/setup.ts |
Marks setup as script-overridable. |
building/commands/src/build/rebuild.ts |
Marks rebuild as script-overridable (not mentioned in PR description). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix JSDoc to reflect that aliases are also overridable by scripts - Update npm_command env var to 'run-script' when redirecting to run - Add 'purge' alias to clean command help text
This was referenced Mar 27, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
package.jsonhas a script namedclean,setup, ordeploy, runningpnpm clean/setup/deploynow executes the script instead of the built-in commandpurgeas an alias for the built-in clean command (always runs the built-in, regardless of scripts)Closes #6816
Test plan
pnpm cleanwith a "clean" script in package.json → runs the scriptpnpm purge→ always runs the built-in clean commandpnpm cleanin a workspace subdir when root has a "clean" script → throwsERR_PNPM_SCRIPT_OVERRIDE_IN_WORKSPACE_ROOTerrorpnpm cleanwithout any script → runs the built-in as before