Skip to content

Commit 16a1674

Browse files
committed
chore: upgrade to NPM v12
Require npm >=12.0.2 <13, enforced via check-node-version on npm install and npm ci. CI installs the version from engines.npm via the new .github/actions/install-npm composite action. The motivation is that npm v12 turns three code-execution paths off by default, most notably the unauthorized execution of install scripts: - allowScripts now defaults to off, so npm install no longer executes preinstall, install or postinstall scripts from dependencies unless they are explicitly allowed in package.json. This also covers prepare scripts from git, file and link dependencies. - --allow-git now defaults to none, which closes a code-execution path where a git dependency's .npmrc could override the git executable, even with --ignore-scripts. - --allow-remote now defaults to none, blocking dependencies from remote URLs such as HTTPS tarballs. See https://github.blog/changelog/2026-06-09-upcoming-breaking-changes-for-npm-v12/ The check is skipped during npm publish and npm pack, because semantic-release bundles its own npm (@semantic-release/npm depends on npm@^11.6.2) and runs the publish with that version rather than the one installed in CI. The Node.js requirement is left unchanged.
1 parent 6f19f57 commit 16a1674

5 files changed

Lines changed: 210 additions & 1 deletion

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Install NPM
2+
description: >
3+
Installs the NPM version required by the `engines.npm` directive in
4+
package.json, which is required for the project to build correctly.
5+
6+
runs:
7+
using: composite
8+
steps:
9+
- name: Install NPM
10+
shell: bash
11+
run: |
12+
npmVersion="$(node -p 'require(`${process.env.GITHUB_WORKSPACE}/package.json`).engines.npm')"
13+
echo "Installing npm@${npmVersion}"
14+
npm install -g "npm@${npmVersion}"

.github/workflows/test-and-release.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
node-version: ">=24.18.1 <25"
2323
cache: "npm"
2424

25+
- name: Install NPM version specified in package.json
26+
uses: ./.github/actions/install-npm
27+
2528
- name: Install dependencies
2629
run: npm ci --no-audit
2730

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ const fetch = fetchWithDebug(
2323

2424
const res = await fetch(new URL("https://example.com"));
2525
```
26+
27+
## Node & NPM
28+
29+
This project requires npm `>=12.0.2 <13` (enforced via `check-node-version` on
30+
`npm install` and `npm ci`).
31+
32+
The check is skipped during `npm publish` and `npm pack`, because
33+
`semantic-release` bundles its own npm (`@semantic-release/npm` depends on
34+
`npm@^11.6.2`) and runs the publish with that version rather than the one
35+
installed in CI.

package-lock.json

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
},
1313
"author": "Nordic Semiconductor ASA | nordicsemi.no",
1414
"scripts": {
15-
"test": "node --no-warnings --experimental-transform-types --test \"./*.spec.ts\""
15+
"test": "node --no-warnings --experimental-transform-types --test \"./*.spec.ts\"",
16+
"prepare": "case \"$npm_command\" in install|ci) check-node-version --package ;; esac"
1617
},
1718
"license": "BSD-3-Clause",
1819
"type": "module",
1920
"main": "export.ts",
2021
"devDependencies": {
2122
"@bifravst/prettier-config": "1.1.17",
23+
"check-node-version": "4.2.1",
2224
"nock": "14.0.17",
2325
"prettier": "3.9.6"
2426
},
@@ -33,5 +35,8 @@
3335
"@semantic-release/release-notes-generator",
3436
"@sebbo2002/semantic-release-jsr"
3537
]
38+
},
39+
"engines": {
40+
"npm": ">=12.0.2 <13"
3641
}
3742
}

0 commit comments

Comments
 (0)