Compare commits

..

3 Commits

Author SHA1 Message Date
Ferdinand Thiessen
a1a024961c Merge 25df5cda4f into 2951748f4c 2026-01-14 10:46:39 +05:00
Ferdinand Thiessen
25df5cda4f test: adjust for array like devEngines
Co-authored-by: Grigory <grigory.orlov.set@gmail.com>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-06-21 15:06:11 +02:00
Ferdinand Thiessen
88483fd687 feat(node-version-file): support parsing devEngines field
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-04-20 13:23:46 +02:00
8 changed files with 173 additions and 1545 deletions

View File

@@ -168,6 +168,36 @@ jobs:
- name: Verify node
run: __tests__/verify-node.sh 24
version-file-dev-engines:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v4
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/package-dev-engines.json'
- name: Verify node
run: __tests__/verify-node.sh 20
version-file-dev-engines-array:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
steps:
- uses: actions/checkout@v4
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/package-dev-engines-array.json'
- name: Verify node
run: __tests__/verify-node.sh 20
version-file-volta:
runs-on: ${{ matrix.os }}
strategy:

View File

@@ -0,0 +1,17 @@
{
"engines": {
"node": "^19"
},
"devEngines": {
"runtime": [
{
"name": "bun",
"version": "^1"
},
{
"name": "node",
"version": "^20"
}
]
}
}

View File

@@ -0,0 +1,11 @@
{
"engines": {
"node": "^19"
},
"devEngines": {
"runtime": {
"name": "node",
"version": "^20"
}
}
}

View File

@@ -94,22 +94,24 @@ describe('main tests', () => {
describe('getNodeVersionFromFile', () => {
each`
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'lts/*'} | ${'lts/*'}
${'nodejs 12.3.4'} | ${'12.3.4'}
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
${''} | ${''}
${'unknown format'} | ${'unknown format'}
${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'lts/*'} | ${'lts/*'}
${'nodejs 12.3.4'} | ${'12.3.4'}
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
${''} | ${''}
${'unknown format'} | ${'unknown format'}
${' 14.1.0 '} | ${'14.1.0'}
${'{}'} | ${null}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'} | ${'>=14.0.0 <=17.0.0'}
${'{"volta": {"extends": "./package.json"}}'} | ${'18.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{"devEngines": {"runtime": {"name": "node", "version": "22.0.0"}}}'} | ${'22.0.0'}
${'{"devEngines": {"runtime": [{"name": "bun"}, {"name": "node", "version": "22.0.0"}]}}'} | ${'22.0.0'}
`.it('parses "$contents"', ({contents, expected}) => {
const existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true);

View File

@@ -64,7 +64,7 @@ If `check-latest` is set to `true`, the action first checks if the cached versio
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24'
@@ -82,7 +82,7 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
@@ -90,7 +90,35 @@ steps:
- run: npm test
```
When using the `package.json` input, the action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`.
When using the `package.json` input, the action will look in following field for a specified Node version:
1. It checks `volta.node` first.
2. Then it checks `devEngines.runtime`.
3. Then it will look for `engines.node`.
4. Otherwise it tries to resolve the file defined by [`volta.extends`](https://docs.volta.sh/advanced/workspaces)
and look for `volta.node` or `engines.node` recursively.
### Example with `devEngines`
When a runtime engine (`engines.node`) is defined but also a development engine (`devEngines.runtime`) then the `devEngine` runtime version is used.
This example will install a Node version based on the `^20.10` pattern.
```json
{
"engines": {
"node": "^19"
},
"devEngines": {
"runtime": {
"name": "node",
"version": "^20.10"
}
}
}
```
### Example with volta pinned Node version
When both `engines.node` and `volta.node` is defined the value in `volta.node` is used.
```json
{
@@ -103,8 +131,6 @@ When using the `package.json` input, the action will look for `volta.node` first
}
```
Otherwise, when [`volta.extends`](https://docs.volta.sh/advanced/workspaces) is defined, then it will resolve the corresponding file and look for `volta.node` or `engines.node` recursively.
## Architecture
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
@@ -116,7 +142,7 @@ jobs:
runs-on: windows-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24'
@@ -137,7 +163,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0
@@ -152,7 +178,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24
@@ -168,7 +194,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: 'v24.0.0-v8-canary2025030537242e55ac'
@@ -188,7 +214,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24-nightly' # it will install the latest nightly release for node 24
@@ -204,7 +230,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0
@@ -220,7 +246,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.0.0-nightly202505066102159fa1'
@@ -238,7 +264,7 @@ jobs:
runs-on: ubuntu-latest
name: Node sample
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.0.0-rc.4'
@@ -256,7 +282,7 @@ Yarn caching handles both Yarn Classic (v1) and Yarn Berry (v2, v3, v4+).
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24'
@@ -275,7 +301,7 @@ steps:
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: pnpm/action-setup@v4
with:
version: 10
@@ -294,7 +320,7 @@ steps:
**Using wildcard patterns to cache dependencies**
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24'
@@ -307,7 +333,7 @@ steps:
**Using a list of file paths to cache dependencies**
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24'
@@ -327,7 +353,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
# Restore Node.js modules cache (restore-only)
- name: Restore Node modules cache
uses: actions/cache@v5
@@ -373,7 +399,7 @@ jobs:
architecture: x86
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- name: Setup node
uses: actions/setup-node@v6
with:
@@ -386,7 +412,7 @@ jobs:
## Publish to npmjs and GPR with npm
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.x'
@@ -406,7 +432,7 @@ steps:
## Publish to npmjs and GPR with yarn
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.x'
@@ -426,7 +452,7 @@ steps:
## Use private packages
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.x'
@@ -446,7 +472,7 @@ Below you can find a sample "Setup .yarnrc.yml" step, that is going to allow you
```yaml
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '24.x'

1538
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "setup-node",
"version": "6.2.0",
"version": "6.1.1",
"private": true,
"description": "setup node action",
"main": "lib/setup-node.js",
@@ -51,7 +51,7 @@
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-node": "^11.1.0",
"jest": "^29.7.0",
"jest-circus": "^30.2.0",
"jest-circus": "^29.7.0",
"jest-each": "^29.7.0",
"prettier": "^3.6.2",
"ts-jest": "^29.4.1",

View File

@@ -26,6 +26,18 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
return manifest.volta.node;
}
// support devEngines from npm 11
if (manifest.devEngines?.runtime) {
// find an entry with name set to node and having set a version.
// the devEngines.runtime can either be an object or an array of objects
const nodeEntry = [manifest.devEngines.runtime]
.flat()
.find(({name, version}) => name.toLowerCase() === 'node' && version);
if (nodeEntry) {
return nodeEntry.version;
}
}
if (manifest.engines?.node) {
return manifest.engines.node;
}