You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6ae7ec7
Browse filesBrowse the repository at this point in the historyBrowse files
feat(pm): handle npm 12 blocked install scripts in create and approve-builds (#2336)
npm 12 (now `latest`) skips dependency install scripts that the
`allowScripts` field in package.json does not cover; the install
succeeds with a warning. Approval only records the allowlist: a
reinstall short-circuits on the up-to-date tree, and only `npm rebuild`
executes previously skipped scripts. npm 12 also stops resolving git and
remote tarball dependencies by default (`EALLOWGIT` / `EALLOWREMOTE`).
vp treated npm as "runs scripts by default", so `vp create` with npm 12
left native direct dependencies silently unbuilt. This PR:
- parses the npm 12 blocked-scripts install warning
(`parseNpmBlockedScripts`) and surfaces gated direct dependencies in `vp
create` like pnpm/bun/yarn; approval runs `vp pm approve-builds <pkg>`
then `vp pm rebuild <pkg>`, and retry hints point at rebuild instead of
reinstall
- version-gates the `vp pm approve-builds` npm note: npm >= 12 explains
the approve-then-rebuild two-step, npm 11.16 - 11.x keeps the advisory
wording (allowlist recorded, scripts still run), denials get no note
- adds the `command_pm_approve_builds_npm12` PTY fixture recorded
against real npm 12.0.2 and re-records the npm11 fixture for the
reworded note
- updates the create and install guides: npm joins the gated-scripts
package managers, new "Dependency build scripts (npm v12+)" section, and
a note on the `allow-git` / `allow-remote` defaults
The npm 11.x wording ("not yet covered") is deliberately not parsed:
those versions still run scripts, so there is nothing to fix up.
Verified end-to-end against npm 12.0.2: install of a project with a
gated direct dep detects it, auto-approval writes `allowScripts` and the
rebuild runs its postinstall. 54 TS unit tests and 34 Rust tests pass;
all three npm approve-builds snapshot fixtures pass.
Audited but left as follow-ups: `vp install -g` has no `--allow-scripts`
plumbing (vp's own global installs have no scripts), `vp migrate`
preserves git/remote specs that now fail under npm 12, and migrate
installs do not surface gated builds (pre-existing, also true for pnpm).
Closes#1823
Copy file name to clipboardExpand all lines: crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_pm_approve_builds_npm11/snapshots/command_pm_approve_builds_npm11.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ No packages with unreviewed install scripts.
37
37
**Exit code:** 1
38
38
39
39
```
40
-
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. Enforcement is planned for a future npm release.
40
+
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. npm 12 enforces the policy.
41
41
npm error code ENOMATCH
42
42
npm error No installed packages match: esbuild
43
43
npm error A complete log of this run can be found in: <home>/.npm/_logs/<timestamp>-debug-0.log
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. Enforcement is planned for a future npm release.
53
+
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. npm 12 enforces the policy.
54
54
npm error code ENOMATCH
55
55
npm error No installed packages match: core-js
56
56
npm error A complete log of this run can be found in: <home>/.npm/_logs/<timestamp>-debug-0.log
@@ -81,6 +81,6 @@ Pass package names as positionals (`vp pm approve-builds <pkg>...`), not after `
81
81
-> npm approve-scripts --all (advisory note)
82
82
83
83
```
84
-
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. Enforcement is planned for a future npm release.
84
+
note: npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. npm 12 enforces the policy.
no args -> npm approve-scripts --allow-scripts-pending (lists pending)
6
+
7
+
```
8
+
No packages with unreviewed install scripts.
9
+
```
10
+
11
+
## `vp pm approve-builds esbuild`
12
+
13
+
-> npm approve-scripts esbuild (npm 12 enforces allowScripts, so vp points at vp pm rebuild)
14
+
15
+
**Exit code:** 1
16
+
17
+
```
18
+
note: npm records the approval in the `allowScripts` field of package.json but does not run scripts a previous install skipped. Run `vp pm rebuild <package>` to execute them.
19
+
npm error code ENOMATCH
20
+
npm error No installed packages match: esbuild
21
+
npm error A complete log of this run can be found in: <home>/.npm/_logs/<timestamp>-debug-0.log
22
+
```
23
+
24
+
## `vp pm approve-builds !core-js`
25
+
26
+
deny-only -> npm deny-scripts core-js (denial keeps the enforced default, no note)
27
+
28
+
**Exit code:** 1
29
+
30
+
```
31
+
npm error code ENOMATCH
32
+
npm error No installed packages match: core-js
33
+
npm error A complete log of this run can be found in: <home>/.npm/_logs/<timestamp>-debug-0.log
34
+
```
35
+
36
+
## `vp pm approve-builds esbuild !core-js`
37
+
38
+
mixed approve+deny -> rejected, exit non-zero
39
+
40
+
**Exit code:** 1
41
+
42
+
```
43
+
npm manages approvals and denials separately. Run them as two invocations, e.g. `vp pm approve-builds <approve-pkg>...` then `vp pm approve-builds !<deny-pkg>...`.
44
+
```
45
+
46
+
## `vp pm approve-builds --all`
47
+
48
+
-> npm approve-scripts --all (rebuild note)
49
+
50
+
```
51
+
note: npm records the approval in the `allowScripts` field of package.json but does not run scripts a previous install skipped. Run `vp pm rebuild <package>` to execute them.
Copy file name to clipboardExpand all lines: crates/vp_pm_cli/src/resolution/commands/approve_builds.rs
+65-2Lines changed: 65 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,9 @@ use crate::resolution::{
5
5
PackageManagerDialect,Pnpm,Resolve,Yarn,
6
6
};
7
7
8
-
constNPM_ADVISORY_NOTE:&str = "npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. Enforcement is planned for a future npm release.";
8
+
constNPM_ADVISORY_NOTE:&str = "npm's allowScripts policy is advisory in npm 11.x: install scripts still run; npm only warns about unreviewed packages at install time. npm 12 enforces the policy.";
9
+
10
+
constNPM_ENFORCED_NOTE:&str = "npm records the approval in the `allowScripts` field of package.json but does not run scripts a previous install skipped. Run `vp pm rebuild <package>` to execute them.";
Copy file name to clipboardExpand all lines: docs/guide/create.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,13 +62,13 @@ See the [Commit hooks guide](/guide/commit-hooks).
62
62
63
63
### Dependency build scripts
64
64
65
-
For security, pnpm, bun, and yarn (Berry) do not run a dependency's build scripts (`install` / `postinstall`, e.g. native builds like `better-sqlite3`) until you approve them. When a template adds such a dependency directly, `vp create` surfaces it after installing instead of leaving the project in a half-built state:
65
+
For security, pnpm, bun, yarn (Berry), and npm (v12+) do not run a dependency's build scripts (`install` / `postinstall`, e.g. native builds like `better-sqlite3`) until you approve them. When a template adds such a dependency directly, `vp create` surfaces it after installing instead of leaving the project in a half-built state:
66
66
67
67
- Interactive: you are asked which of those dependencies to approve and build (nothing is selected by default).
68
68
- Non-interactive: a note lists them and points at `vp pm approve-builds`.
69
69
-`--approve-builds`: approves and builds them automatically, so non-interactive runs (CI) can produce a ready-to-use project.
70
70
71
-
Approval is recorded the way each package manager expects: pnpm's `allowBuilds`, bun's `trustedDependencies`, or yarn's `dependenciesMeta.<pkg>.built` (in the workspace root manifest). Transitive build scripts you did not choose (e.g. `esbuild` pulled in by Vite) are left at the package manager's defaults and are not surfaced. npm runs build scripts by default, so there is nothing to approve there.
71
+
Approval is recorded the way each package manager expects: pnpm's `allowBuilds`, bun's `trustedDependencies`, npm's `allowScripts`, or yarn's `dependenciesMeta.<pkg>.built` (in the workspace root manifest). Transitive build scripts you did not choose (e.g. `esbuild` pulled in by Vite) are left at the package manager's defaults and are not surfaced. npm 11 and older run build scripts during install, so there is nothing to approve there.
With pnpm v10+, bare `vp rebuild` only rebuilds packages whose build scripts are listed in `onlyBuiltDependencies` (or approved via `pnpm approve-builds`); name the package explicitly to force a rebuild that bypasses the approval gate.
169
169
170
+
#### Dependency build scripts (npm v12+)
171
+
172
+
npm v12 skips dependency install scripts (`preinstall` / `install` / `postinstall`, including implicit `node-gyp` builds) unless the `allowScripts` field in package.json covers them; the install succeeds and npm warns about what it skipped. `vp pm approve-builds` manages that allowlist:
173
+
174
+
-`vp pm approve-builds <pkg...>` approves the named packages (`npm approve-scripts`)
175
+
-`vp pm approve-builds !<pkg...>` denies them (`npm deny-scripts`)
176
+
-`vp pm approve-builds --all` approves everything currently pending
177
+
-`vp pm approve-builds` lists the packages whose scripts are not yet covered
178
+
179
+
Approval only records the allowlist: scripts an earlier install skipped do not run until you run `vp rebuild <pkg>`. With npm 11.16 - 11.x the same commands work, but npm treats the allowlist as advisory and still runs scripts.
180
+
181
+
npm v12 also stops resolving git dependencies (`github:`, `git+https:`) and remote tarball URLs by default; such installs fail with `EALLOWGIT` / `EALLOWREMOTE`. Opt back in per project with npm's `allow-git` / `allow-remote` config.
182
+
170
183
#### Advanced
171
184
172
185
Use these when you need lower-level package-manager behavior.
0 commit comments