Repository navigation
Framework: Update npm to v12 - #82732
manzoorwanijk wants to merge 5 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. 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 📦 Bundle sizeSize Change: 0 B Total Size: 8.29 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
48ff320 to
19c2e92
Compare
ad5c010 to
0c93e6d
Compare
ea5cbf6 to
3815ba1
Compare
b8bc152 to
d109772
Compare
8734714 to
c7cf7a3
Compare
122cee6 to
08de4c8
Compare
c880581 to
5fdb2d7
Compare
5fdb2d7 to
50f9da9
Compare
95919b1 to
d10dd69
Compare
2d23770 to
de6139f
Compare
tyxla
left a comment
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I think a safer approach is to prepare those branches before merging this. Should we move this PR back to draft?
There was a problem hiding this comment.
That's the safest approach, IMO.
cc @desrosj @aduth @jsnajdr @tyxla @youknowriad just for visibility / coordination.
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).
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).
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).
* 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>
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).
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).
e887331 to
7ea9d64
Compare
* 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
85cedd4 to
777967d
Compare
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).
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).
| # 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 |
There was a problem hiding this comment.
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?
|
Moving this to draft. See #82732 (comment) |
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.
f71e273 to
aa03575
Compare
* 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
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?
allowScriptsdenies every dependency that ships an install script, so nothing compiles on install..npmrcaddsstrict-allow-scriptsso an unlisted one fails the install, and refuses local tarballs.test/ai-developmentinstalls with--prefix, so it carries its own copy of both.@wordpress/iconsbuilds from the rootpostinstall, which the policy does not gate, because npm 12 skips workspace lifecycle scripts underinstall-strategy=linked(npm/cli#9982).lockfile-versionis removed from.npmrc: the lockfile records its own version, and npm v12 moves to v4 for its patch and extension features.Testing Instructions
npm install --global npm@12.node_modules, thennpm ci. The lockfile should be unchanged andpackages/icons/src/librarypopulated.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.jsonTesting Instructions for Keyboard
N/A, no user interface change.
Use of AI Tools
Claude Code drafted and verified the changes. I reviewed them.