Skip to content

Framework: Update npm to v12 - #82732

Draft
manzoorwanijk wants to merge 5 commits into
trunkfrom
update/npm-12
Draft

manzoorwanijk wants to merge 5 commits into
trunkfrom
update/npm-12

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

What?

We now have npm v12 available on the build server.

Closes #82328
Supersedes #82689

Moves the repository to npm v12 and records the supply chain policy the new major requires.

Why?

npm v12 is a security release: dependency install scripts, git dependencies and remote URL dependencies all become opt-in. The Node.js Release WG will not bundle it on Node.js 22, 24 or 26, so waiting costs another year unprotected.

How?

allowScripts denies every dependency that ships an install script, so nothing compiles on install. .npmrc adds strict-allow-scripts so an unlisted one fails the install, and refuses local tarballs. test/ai-development installs with --prefix, so it carries its own copy of both.

@wordpress/icons builds from the root postinstall, which the policy does not gate, because npm 12 skips workspace lifecycle scripts under install-strategy=linked (npm/cli#9982).

lockfile-version is removed from .npmrc: the lockfile records its own version, and npm v12 moves to v4 for its patch and extension features.

Testing Instructions

  1. npm install --global npm@12.
  2. Remove every node_modules, then npm ci. The lockfile should be unchanged and packages/icons/src/library populated.
  3. Confirm each gate fires (the third edits package.json):
npm install --dry-run --no-save github:sindresorhus/is-odd
npm install --dry-run --no-save https://registry.npmjs.org/is-odd/-/is-odd-3.0.1.tgz
npm pkg delete allowScripts.esbuild && npm install --dry-run
git checkout package.json

Testing Instructions for Keyboard

N/A, no user interface change.

Use of AI Tools

Claude Code drafted and verified the changes. I reviewed them.

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: lancewillett <lancewillett@git.wordpress.org>
Co-authored-by: johnbillion <johnbillion@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.29 MB

aa03575 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 391b31b trunk % Change
timeToFirstByte 36.8 ms +3.94% -1.36% 37 ms +9.59% -3.51% -0.54%
largestContentfulPaint 60 ms +6.67% -0% 62 ms +9.68% -3.23% -3.23%
lcpMinusTtfb 24.45 ms +3.89% -4.29% 25.1 ms +15.74% -9.16% -2.59%
wpBeforeTemplate 17.33 ms +5.14% -1.67% 17.45 ms +9.51% -1.89% -0.69%
wpTemplate 16.85 ms +2.55% -3.68% 16.56 ms +5.74% -5.07% 1.75%
wpTotal 34.32 ms +3.76% -1.69% 34.43 ms +8.89% -3.46% -0.32%
wpMemoryUsage 7.66 MB +0% -0% 7.63 MB +0% -0% 0.45%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric 391b31b trunk % Change
timeToFirstByte 26.65 ms +6.38% -3% 29.35 ms +6.64% -0.85% -9.2%
largestContentfulPaint 60 ms +6.67% -0% 68 ms +2.94% -2.94% -11.76%
lcpMinusTtfb 34.45 ms +3.48% -2.18% 38.5 ms +1.17% -4.68% -10.52%
wpBeforeTemplate 15.45 ms +2.07% -2.78% 15.14 ms +2.84% -1.59% 2.05%
wpTemplate 9.28 ms +4.09% -1.83% 12.18 ms +3.45% -0.9% -23.81%
wpTotal 24.89 ms +5.18% -3.05% 27.33 ms +7.14% -0.91% -8.93%
wpMemoryUsage 6.15 MB +0% -0% 6.24 MB +0% -0% -1.56%
wpDbQueries 10 +0% -0% 14 +0% -0% -28.57%

media-processing

Metric 391b31b trunk % Change
mediaProcessingJpeg 278.33 ms +2.71% -0.74% 281.15 ms +2.06% -0.8% -1%
mediaProcessingAvif 4064.95 ms +0.47% -0.63% 4049.01 ms +0.79% -0.09% 0.39%
mediaProcessingJpegToAvif 2769.93 ms +0.31% -0.25% 2763.44 ms +1.14% -0.27% 0.23%

media-upload

Metric 391b31b trunk % Change
jpegUploadProcessing 1397.39 ms +1.58% -1.88% 1392.8 ms +0.36% -0.08% 0.33%
pngUploadProcessing 162.94 ms +5.53% -4.61% 157.51 ms +4.27% -3.57% 3.45%
largeJpegUploadProcessing 1395.52 ms +1.09% -0.57% 1399.83 ms +0.7% -0.53% -0.31%
multipleImageUploadProcessing 1448.93 ms +0.63% -0.48% 1445.07 ms +1.21% -0.29% 0.27%

post-editor

Metric 391b31b trunk % Change
serverResponse 260.87 ms +4.63% -10.66% 243.05 ms +7.56% -6.74% 7.33%
firstPaint 167.99 ms +11.01% -18.88% 168.8 ms +21.02% -24.24% -0.48%
domContentLoaded 667.25 ms +1.67% -1.06% 662.31 ms +9.91% -0.88% 0.75%
loaded 668.29 ms +1.65% -1.05% 663.26 ms +9.88% -0.87% 0.76%
firstContentfulPaint 298.98 ms +3.52% -1.32% 300.68 ms +16.08% -2.05% -0.57%
firstBlock 1935.46 ms +1.52% -1.36% 1982.84 ms +0.83% -3.46% -2.39%
type 13.18 ms +0.68% -2.66% 13.23 ms +4.01% -2.12% -0.38%
typeWithoutInspector 13.05 ms +3.45% -4.21% 13.06 ms +3.37% -4.44% -0.08%
typeWithTopToolbar 16.4 ms +8.29% -9.09% 16.21 ms +8.27% -1.6% 1.17%
typeContainer 6.13 ms +7.18% -1.79% 6.59 ms +3.79% -6.37% -6.98%
focus 67.33 ms +4.59% -5.32% 80.15 ms +1% -6.15% -16%
firstFocus 129.83 ms +0% -0% 178.82 ms +0% -0% -27.4%
selectAll 334.4 ms +2.56% -0.43% 384.01 ms +7.53% -4.44% -12.92%
listViewOpen 45.51 ms +5.14% -5.91% 50.4 ms +9.07% -16.59% -9.7%
inserterOpen 25.39 ms +10.16% -5.08% 29.93 ms +3.68% -11.03% -15.17%
inserterHover 9.16 ms +4.69% -2.95% 9.68 ms +15.6% -5.37% -5.37%
inserterSearch 6.85 ms +14.16% -6.42% 7.02 ms +5.27% -4.42% -2.42%
loadPatterns 423.38 ms +4.82% -4.33% 425.14 ms +5.78% -3.75% -0.41%
wpTotal 254.13 ms +4.16% -11.02% 236.24 ms +7.69% -6.86% 7.57%
wpMemoryUsage 13.22 MB +0% -0% 13.18 MB +0% -0% 0.25%
wpDbQueries 54 +0% -0% 54 +0% -0% 0%

site-editor

Metric 391b31b trunk % Change
serverResponse 500.7 ms +1.6% -5.41% 493.8 ms +1.86% -9.93% 1.4%
firstPaint 306.17 ms +51.58% -17.63% 258.97 ms +22.37% -7.07% 18.23%
domContentLoaded 1175.35 ms +1.4% -1.26% 1180.61 ms +0.35% -1.45% -0.45%
loaded 1176.57 ms +1.41% -1.24% 1181.95 ms +0.35% -1.45% -0.46%
firstContentfulPaint 468 ms +2.36% -1.57% 481.34 ms +0.76% -3.33% -2.77%
firstBlock 4392.17 ms +0.53% -0.77% 4398.55 ms +0.81% -1.02% -0.15%
type 19.13 ms +3.66% -3.71% 19.24 ms +6.13% -6.13% -0.57%
navigate 119.79 ms +3.88% -6.81% 117.87 ms +8.16% -5.65% 1.63%
loadPatterns 1361.87 ms +3.7% -6.72% 1256.15 ms +0.59% -2.43% 8.42%
loadPages 1013.06 ms +0.42% -2.06% 1004.63 ms +4.34% -1.4% 0.84%
wpTotal 490.97 ms +1.57% -5.53% 484.27 ms +1.93% -10.21% 1.38%
wpMemoryUsage 12.26 MB +0% -0% 12.22 MB +0% -0% 0.3%
wpDbQueries 43 +2.33% -0% 43 +2.33% -0% 0%

aa03575 Run

Comment thread package.json Resolved

@tyxla tyxla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff. Glad to see this finally moving and supported in the build server!

BTW the description says the minimum version is >=12.0.2, but the code uses >=12.2.0. Perhaps just the description needs an update, but wanted to confirm.

Comment thread package.json Resolved
Comment thread .npmrc
# fail the install on any dependency script not covered by allowScripts in package.json
strict-allow-scripts = true
# npm v12 already refuses git and remote URL dependencies; extend that to local tarballs
allow-file = none

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because npm 12 refuses remote URL dependencies, release builds of older branches will break. The release script runs npm ci in the publish checkout with npm 12 from trunk. The lockfiles on wp/7.0, wp/6.9 and wp/6.8 still have tarballs from raw.githubusercontent.com (react-native-video and @react-native-community/slider). So a wp release for 7.0.x will fail with EALLOWREMOTE, and nothing will be published.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and .npmrc here cannot solve it: the lockfiles on wp/7.0, wp/6.9 and wp/6.8 carry raw.githubusercontent.com tarballs, and performance.js would install npm 12 onto refs pinned to Node 20, which npm 12 does not support.

Those branches need their own migration, the same way the Node 24 upgrade is being handled per branch, and that one is not finished on every branch yet either. So this is sequencing rather than a blocker: npm 12 on trunk first, then each branch as it is migrated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is sequencing rather than a blocker: npm 12 on trunk first, then each branch as it is migrated.

Won't this leave releases broken in the transition period?

Should we migrate them first or keep those installs on a compatible npm version until then?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, the current changes would leave releases from wp/7.0, wp/6.9, and wp/6.8 broken during the transition: the workflow uses npm from trunk, and npm 12 rejects their remote tarball dependencies with EALLOWREMOTE. Could we migrate those branches first, or keep their installs on a compatible npm version before merging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a safer approach is to prepare those branches before merging this. Should we move this PR back to draft?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the safest approach, IMO.

cc @desrosj @aduth @jsnajdr @tyxla @youknowriad just for visibility / coordination.

Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
Comment thread package.json Resolved
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
npm v12 wraps `view --json` in an array and keys `pack --json` by package
name. The publish preflight read the former as an object, so every retry saw
an undefined version and failed before pushing tags; the vitest consumer test
read the latter as an array and threw. Both now accept either shape, and the
preflight test covers both.

Reported in #82732 (comment).
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
allowScripts lives in package.json and changes what an install produces, but
the cache key only covered package-lock.json and .npmrc. A PR that approved or
denied a package would restore node_modules from a stale cache, so CI and a
fresh local install no longer matched.

Reported in #82732 (comment).
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
The workspace prepare script needed an allowScripts approval, and that entry
was fragile: strict-allow-scripts never checks workspace lifecycle scripts, so
losing it fails silently. Root lifecycle scripts are not subject to the policy,
so running the build from postinstall drops the approval entirely.

Reported in #82732 (comment).
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
* Release Tooling: Read the npm v12 JSON output shapes

npm v12 wraps `view --json` in an array and keys `pack --json` by package
name. The publish preflight read the former as an object, so every retry saw
an undefined version and failed before pushing tags; the vitest consumer test
read the latter as an array and threw. Both now accept either shape, and the
preflight test covers both.

Reported in #82732 (comment).

* Release Tooling: Validate the npm view and pack result count

Unwrap the npm view array in the preflight, where the call is made,
instead of in the shared JSON parser, and fail when it does not hold
exactly one version. Share one npm pack reader between the two
validation scripts, parsing stdout only and requiring one result.

* Release Tooling: Validate the npm view and pack result shape

Reject an npm view entry that is not an object and an npm pack result
without filename or files, naming the package. Run the preflight failure
tests against both npm view shapes and cover the object shapes, null and
malformed entries in the pack reader tests.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
allowScripts lives in package.json and changes what an install produces, but
the cache key only covered package-lock.json and .npmrc. A PR that approved or
denied a package would restore node_modules from a stale cache, so CI and a
fresh local install no longer matched.

Reported in #82732 (comment).
manzoorwanijk added a commit that referenced this pull request Oct 5, 2026
The workspace prepare script needed an allowScripts approval, and that entry
was fragile: strict-allow-scripts never checks workspace lifecycle scripts, so
losing it fails silently. Root lifecycle scripts are not subject to the policy,
so running the build from postinstall drops the approval entirely.

Reported in #82732 (comment).
Comment thread package.json Resolved
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Oct 5, 2026
* Release Tooling: Read the npm v12 JSON output shapes

npm v12 wraps `view --json` in an array and keys `pack --json` by package
name. The publish preflight read the former as an object, so every retry saw
an undefined version and failed before pushing tags; the vitest consumer test
read the latter as an array and threw. Both now accept either shape, and the
preflight test covers both.

Reported in WordPress/gutenberg#82732 (comment).

* Release Tooling: Validate the npm view and pack result count

Unwrap the npm view array in the preflight, where the call is made,
instead of in the shared JSON parser, and fail when it does not hold
exactly one version. Share one npm pack reader between the two
validation scripts, parsing stdout only and requiring one result.

* Release Tooling: Validate the npm view and pack result shape

Reject an npm view entry that is not an object and an npm pack result
without filename or files, naming the package. Run the preflight failure
tests against both npm view shapes and cover the object shapes, null and
malformed entries in the pack reader tests.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

Source: WordPress/gutenberg@a79e3fd
manzoorwanijk added a commit that referenced this pull request Oct 6, 2026
allowScripts lives in package.json and changes what an install produces, but
the cache key only covered package-lock.json and .npmrc. A PR that approved or
denied a package would restore node_modules from a stale cache, so CI and a
fresh local install no longer matched.

Reported in #82732 (comment).
manzoorwanijk added a commit that referenced this pull request Oct 6, 2026
The workspace prepare script needed an allowScripts approval, and that entry
was fragile: strict-allow-scripts never checks workspace lifecycle scripts, so
losing it fails silently. Root lifecycle scripts are not subject to the policy,
so running the build from postinstall drops the approval entirely.

Reported in #82732 (comment).

@ciampo ciampo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nit: the PR description is out of date. Icons now build from root postinstall with no approval entry, and .npmrc still contains lockfile-version = 3.

Comment thread .npmrc Resolved
Comment thread .npmrc
# fail the install on any dependency script not covered by allowScripts in package.json
strict-allow-scripts = true
# npm v12 already refuses git and remote URL dependencies; extend that to local tarballs
allow-file = none

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, the current changes would leave releases from wp/7.0, wp/6.9, and wp/6.8 broken during the transition: the workflow uses npm from trunk, and npm 12 rejects their remote tarball dependencies with EALLOWREMOTE. Could we migrate those branches first, or keep their installs on a compatible npm version before merging?

@manzoorwanijk

Copy link
Copy Markdown
Member Author

Moving this to draft. See #82732 (comment)

@manzoorwanijk
manzoorwanijk marked this pull request as draft October 6, 2026 12:18
Bump engines.npm and devEngines.packageManager to npm v12 and opt in to
the supply chain policy the new major requires. Install scripts are now
opt-in, so record every dependency that ships one in allowScripts, all
denied: nothing compiles on install.

npm 12 does not exempt workspace lifecycle scripts from allowScripts
under install-strategy=linked, so @wordpress/icons needs an entry of its
own to keep generating src/library on install. See
npm/cli#9982.

Closes #82328. Supersedes #82689.
The workspace prepare script needed an allowScripts approval, and that entry
was fragile: strict-allow-scripts never checks workspace lifecycle scripts, so
losing it fails silently. Root lifecycle scripts are not subject to the policy,
so running the build from postinstall drops the approval entirely.

Reported in #82732 (comment).
An earlier rebase read its deliberate removal as an accidental drop and put it
back. The lockfile records its own version, so the setting is redundant and
would pin v3 when npm v12 features need v4.
allow-git and allow-remote both default to none in npm v12, so opting in
explicitly says nothing. Verified that EALLOWGIT and EALLOWREMOTE still fire
without them, alongside EALLOWFILE and ESTRICTALLOWSCRIPTS, which do differ
from the defaults and stay.
The setup block relies on the npm that Node bundles, which no longer satisfies
the version this repository requires.
peterwilsoncc pushed a commit to peterwilsoncc/gutenberg-build that referenced this pull request Oct 14, 2026
* Release Tooling: Read the npm v12 JSON output shapes

npm v12 wraps `view --json` in an array and keys `pack --json` by package
name. The publish preflight read the former as an object, so every retry saw
an undefined version and failed before pushing tags; the vitest consumer test
read the latter as an array and threw. Both now accept either shape, and the
preflight test covers both.

Reported in WordPress/gutenberg#82732 (comment).

* Release Tooling: Validate the npm view and pack result count

Unwrap the npm view array in the preflight, where the call is made,
instead of in the shared JSON parser, and fail when it does not hold
exactly one version. Share one npm pack reader between the two
validation scripts, parsing stdout only and requiring one result.

* Release Tooling: Validate the npm view and pack result shape

Reject an npm view entry that is not an object and an npm pack result
without filename or files, naming the package. Run the preflight failure
tests against both npm view shapes and cover the object shapes, null and
malformed entries in the pack reader tests.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

Source: WordPress/gutenberg@a79e3fd

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Framework: Update npm to v12

4 participants