mirror of
https://github.com/actions/setup-node.git
synced 2026-03-04 06:51:04 +08:00
Compare commits
5 Commits
b4cdfa017c
...
4af1e7da26
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4af1e7da26 | ||
|
|
774c1d6296 | ||
|
|
ead69d56d0 | ||
|
|
43959a440a | ||
|
|
fc2e41dd00 |
15
.github/workflows/versions.yml
vendored
15
.github/workflows/versions.yml
vendored
@ -168,6 +168,21 @@ jobs:
|
|||||||
- name: Verify node
|
- name: Verify node
|
||||||
run: __tests__/verify-node.sh 24
|
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]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- 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-volta:
|
version-file-volta:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
11
__tests__/data/package-dev-engines.json
Normal file
11
__tests__/data/package-dev-engines.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"engines": {
|
||||||
|
"node": "^19"
|
||||||
|
},
|
||||||
|
"devEngines": {
|
||||||
|
"runtime": {
|
||||||
|
"name": "node",
|
||||||
|
"version": "^20"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -106,10 +106,12 @@ describe('main tests', () => {
|
|||||||
${''} | ${''}
|
${''} | ${''}
|
||||||
${'unknown format'} | ${'unknown format'}
|
${'unknown format'} | ${'unknown format'}
|
||||||
${' 14.1.0 '} | ${'14.1.0'}
|
${' 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}
|
${'{}'} | ${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}) => {
|
`.it('parses "$contents"', ({contents, expected}) => {
|
||||||
const existsSpy = jest.spyOn(fs, 'existsSync');
|
const existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
existsSpy.mockImplementation(() => true);
|
existsSpy.mockImplementation(() => true);
|
||||||
@ -133,10 +135,11 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
describe('printEnvDetailsAndSetOutput', () => {
|
describe('printEnvDetailsAndSetOutput', () => {
|
||||||
it.each([
|
it.each([
|
||||||
[{node: '12.0.2', npm: '6.3.3', yarn: '1.22.11'}],
|
[{node: '12.0.2', npm: '6.3.3', yarn: '1.22.11', pnpm: ''}],
|
||||||
[{node: '16.0.2', npm: '7.3.3', yarn: '2.22.11'}],
|
[{node: '16.0.2', npm: '7.3.3', yarn: '2.22.11', pnpm: ''}],
|
||||||
[{node: '14.0.1', npm: '8.1.0', yarn: '3.2.1'}],
|
[{node: '14.0.1', npm: '8.1.0', yarn: '3.2.1', pnpm: ''}],
|
||||||
[{node: '17.0.2', npm: '6.3.3', yarn: ''}]
|
[{node: '17.0.2', npm: '6.3.3', yarn: '', pnpm: ''}],
|
||||||
|
[{node: '24.10.0', npm: '11.6.1', yarn: '', pnpm: '10.18.3'}]
|
||||||
])('Tools versions %p', async obj => {
|
])('Tools versions %p', async obj => {
|
||||||
getExecOutputSpy.mockImplementation(async command => {
|
getExecOutputSpy.mockImplementation(async command => {
|
||||||
if (Reflect.has(obj, command) && !obj[command]) {
|
if (Reflect.has(obj, command) && !obj[command]) {
|
||||||
|
|||||||
13
dist/cache-save/index.js
vendored
13
dist/cache-save/index.js
vendored
@ -71877,6 +71877,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
if (manifest.volta?.node) {
|
if (manifest.volta?.node) {
|
||||||
return manifest.volta.node;
|
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) {
|
if (manifest.engines?.node) {
|
||||||
return manifest.engines.node;
|
return manifest.engines.node;
|
||||||
}
|
}
|
||||||
@ -71907,7 +71918,7 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
}
|
}
|
||||||
async function printEnvDetailsAndSetOutput() {
|
async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
const promises = ['node', 'npm', 'yarn'].map(async (tool) => {
|
const promises = ['node', 'npm', 'yarn', 'pnpm'].map(async (tool) => {
|
||||||
const pathTool = await io.which(tool, false);
|
const pathTool = await io.which(tool, false);
|
||||||
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
||||||
return { tool, output };
|
return { tool, output };
|
||||||
|
|||||||
13
dist/setup/index.js
vendored
13
dist/setup/index.js
vendored
@ -82415,6 +82415,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
if (manifest.volta?.node) {
|
if (manifest.volta?.node) {
|
||||||
return manifest.volta.node;
|
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) {
|
if (manifest.engines?.node) {
|
||||||
return manifest.engines.node;
|
return manifest.engines.node;
|
||||||
}
|
}
|
||||||
@ -82445,7 +82456,7 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
}
|
}
|
||||||
async function printEnvDetailsAndSetOutput() {
|
async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
const promises = ['node', 'npm', 'yarn'].map(async (tool) => {
|
const promises = ['node', 'npm', 'yarn', 'pnpm'].map(async (tool) => {
|
||||||
const pathTool = await io.which(tool, false);
|
const pathTool = await io.which(tool, false);
|
||||||
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
||||||
return { tool, output };
|
return { tool, output };
|
||||||
|
|||||||
@ -90,21 +90,31 @@ steps:
|
|||||||
- run: npm test
|
- 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 the following fields for a specified Node version:
|
||||||
|
1. It checks `volta.node` first.
|
||||||
|
2. Then it checks `devEngines.runtime` for an entry with `"name": "node"`.
|
||||||
|
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`, `devEngines.runtime`, or `engines.node` recursively.
|
||||||
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0"
|
"node": "^22 || ^24"
|
||||||
|
},
|
||||||
|
"devEngines": {
|
||||||
|
"runtime": {
|
||||||
|
"name": "node",
|
||||||
|
"version": "^24.3"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "16.0.0"
|
"node": "24.11.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
## 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).
|
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).
|
||||||
|
|||||||
14
src/util.ts
14
src/util.ts
@ -26,6 +26,18 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
|||||||
return manifest.volta.node;
|
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) {
|
if (manifest.engines?.node) {
|
||||||
return manifest.engines.node;
|
return manifest.engines.node;
|
||||||
}
|
}
|
||||||
@ -62,7 +74,7 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
|||||||
|
|
||||||
export async function printEnvDetailsAndSetOutput() {
|
export async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
const promises = ['node', 'npm', 'yarn'].map(async tool => {
|
const promises = ['node', 'npm', 'yarn', 'pnpm'].map(async tool => {
|
||||||
const pathTool = await io.which(tool, false);
|
const pathTool = await io.which(tool, false);
|
||||||
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
const output = pathTool ? await getToolVersion(tool, ['--version']) : '';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user