Skip to content

feat(pm): support npm approve-scripts/deny-scripts in approve-builds#1733

Draft
fengmk2 wants to merge 2 commits into
mainfrom
feat/npm-approve-scripts
Draft

feat(pm): support npm approve-scripts/deny-scripts in approve-builds#1733
fengmk2 wants to merge 2 commits into
mainfrom
feat/npm-approve-scripts

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Jun 1, 2026

Summary

npm 11.16.0 (npm/cli#9360, "Phase 1 of allowScripts opt-in install-script policy") adds npm approve-scripts and npm deny-scripts, which manage an advisory allowScripts field in package.json. This is the npm equivalent of pnpm approve-builds / bun pm trust.

vp pm approve-builds previously warned and exited 0 (no-op) on npm. It now forwards to npm's real commands when the detected npm is >= 11.16.0.

Mapping (npm >= 11.16.0)

vp pm approve-builds invocation npm command
<pkg>... (approves) npm approve-scripts <pkg>...
--all npm approve-scripts --all
(no args) npm approve-scripts --allow-scripts-pending (read-only list)
!<pkg>... (denies, ! stripped) npm deny-scripts <pkg>...
mixed approves + !denies rejected with an actionable error
npm < 11.16.0 warn + exit 0 (no-op), advise upgrade

Notes

  • Mixed approve+deny is rejected rather than silently split: npm separates approve vs. deny into two commands, so vp pm approve-builds esbuild !core-js returns a clear message asking the user to run the two operations separately (pnpm handles the mixed case in one command). This keeps the single-command return type intact.
  • Advisory caveat surfaced: npm 11.x's allowScripts is advisory only (install scripts still run; npm just warns about unreviewed packages). A one-line note is shown after an approve/deny write so users aren't misled. Not shown on the read-only --allow-scripts-pending listing.
  • Version gating reuses the existing version_satisfies/node_semver pattern (npm_supports_allow_scripts = >=11.16.0), matching pnpm's prerelease semantics.
  • Help text for the deny prefix and --all updated from "pnpm only" to reflect pnpm + npm support.

Tests

  • 9 new unit tests in approve_builds.rs (approve-by-name, --all, pending-list, deny-only, multi-deny, mixed-rejected, pass-through, below-gate no-op, prerelease no-op). The Option return type is unchanged, so existing tests are untouched.
  • New global snap test command-pm-approve-builds-npm11/ (npm@11.16.0) exercising the real npm commands end-to-end.
  • 4 existing approve-builds snaps regenerated for the help-text wording change and the updated npm warn message.

Validation

  • cargo test -p vite_install -p vite_pm_cli (510 passed)
  • just check
  • cargo clippy -p vite_install -p vite_pm_cli -- -D warnings
  • pnpm bootstrap-cli + local/global approve-builds snap tests regenerated and reviewed

@fengmk2 fengmk2 self-assigned this Jun 1, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 1, 2026

Deploy Preview for viteplus-preview ready!

Name Link
🔨 Latest commit 2a34ce3
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a1d3065086f230008253e6a
😎 Deploy Preview https://deploy-preview-1733--viteplus-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

npm 11.16.0 (npm/cli #9360) adds `approve-scripts` and `deny-scripts`
commands that manage an advisory `allowScripts` field in package.json.
`vp pm approve-builds` previously warned and no-oped on npm; it now
forwards to these commands when npm >= 11.16.0:

- approves     -> npm approve-scripts <pkg...>
- --all        -> npm approve-scripts --all
- no args      -> npm approve-scripts --allow-scripts-pending (list pending)
- !pkg denies  -> npm deny-scripts <pkg...> (the `!` is stripped)

Mixed approve+deny in a single invocation is rejected with an actionable
message, since npm splits the two operations into separate commands.
A one-line note is shown after a write because npm 11.x's allowScripts
is advisory (install scripts still run). npm < 11.16.0 keeps the
warn + exit-0 no-op, now pointing at the upgrade.
@fengmk2 fengmk2 force-pushed the feat/npm-approve-scripts branch from b690672 to 4e25692 Compare June 1, 2026 05:41
- reject a positional passed via `--` on npm's read-only pending path
  instead of building an invalid `npm approve-scripts --allow-scripts-pending <pkg>`
- collapse the three duplicated advisory-note calls into a single `writes_policy` gate
- fix the now-stale pass-through comment (npm also reaches the shared tail)
- update RFC section 4, which no longer applies to npm >= 11.16.0

Adds unit tests for the pending guard (rejects positionals, still forwards flags)
and a snap-test step covering the rejection.
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.

1 participant