Skip to content

feat: make clean/setup/deploy prefer user scripts over built-in commands#11118

Merged
zkochan merged 6 commits intomainfrom
clean-cmd
Mar 27, 2026
Merged

feat: make clean/setup/deploy prefer user scripts over built-in commands#11118
zkochan merged 6 commits intomainfrom
clean-cmd

Conversation

@zkochan
Copy link
Copy Markdown
Member

@zkochan zkochan commented Mar 27, 2026

Summary

  • 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
  • When running from a workspace subdirectory where the workspace root has one of these scripts, an error is thrown with guidance
  • Added purge as an alias for the built-in clean command (always runs the built-in, regardless of scripts)

Closes #6816

Test plan

  • pnpm clean with a "clean" script in package.json → runs the script
  • pnpm purge → always runs the built-in clean command
  • pnpm clean in a workspace subdir when root has a "clean" script → throws ERR_PNPM_SCRIPT_OVERRIDE_IN_WORKSPACE_ROOT error
  • pnpm clean without any script → runs the built-in as before

zkochan added 5 commits March 27, 2026 15:16
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.
@zkochan zkochan marked this pull request as ready for review March 27, 2026 18:02
Copilot AI review requested due to automatic review settings March 27, 2026 18:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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 overridableByScript command capability and apply it to clean, setup, and deploy (and currently also rebuild).
  • 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/purge behaviors 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
@zkochan zkochan merged commit 36b3826 into main Mar 27, 2026
11 of 12 checks passed
@zkochan zkochan deleted the clean-cmd branch March 27, 2026 19:04
@zkochan zkochan added this to the v11.0 milestone Mar 27, 2026
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.

Feature: pnpm clean

2 participants