mirror of
https://github.com/actions/setup-node.git
synced 2026-03-04 06:51:04 +08:00
Compare commits
3 Commits
8664edb6aa
...
eeae088020
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeae088020 | ||
|
|
774c1d6296 | ||
|
|
ecb118ff9d |
15
.github/workflows/versions.yml
vendored
15
.github/workflows/versions.yml
vendored
@ -168,6 +168,21 @@ 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]
|
||||
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:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
||||
@ -118,6 +118,24 @@ describe('authutil tests', () => {
|
||||
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
|
||||
});
|
||||
|
||||
it('should not export NODE_AUTH_TOKEN if not set (OIDC support)', async () => {
|
||||
// Clean NODE_AUTH_TOKEN from environment
|
||||
delete process.env.NODE_AUTH_TOKEN;
|
||||
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
// NODE_AUTH_TOKEN should not be exported to environment if not initially set
|
||||
// This allows OIDC authentication to work properly
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||
});
|
||||
|
||||
it('should export empty string NODE_AUTH_TOKEN if explicitly set to empty (OIDC support)', async () => {
|
||||
process.env.NODE_AUTH_TOKEN = '';
|
||||
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
expect(process.env.NODE_AUTH_TOKEN).toEqual('');
|
||||
});
|
||||
|
||||
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
|
||||
fs.writeFileSync(rcFile, 'registry=NNN');
|
||||
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
11
dist/cache-save/index.js
vendored
11
dist/cache-save/index.js
vendored
@ -71877,6 +71877,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
||||
if (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) {
|
||||
return manifest.engines.node;
|
||||
}
|
||||
|
||||
19
dist/setup/index.js
vendored
19
dist/setup/index.js
vendored
@ -81047,8 +81047,12 @@ function writeRegistryToFile(registryUrl, fileLocation) {
|
||||
newContents += `${authString}${os.EOL}${registryString}`;
|
||||
fs.writeFileSync(fileLocation, newContents);
|
||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
|
||||
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
|
||||
// Only export NODE_AUTH_TOKEN if explicitly provided by user
|
||||
// This is required to support NPM OIDC tokens which need NODE_AUTH_TOKEN to be unset
|
||||
// See: https://github.com/actions/setup-node/issues/1440
|
||||
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
|
||||
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -82415,6 +82419,17 @@ function getNodeVersionFromFile(versionFilePath) {
|
||||
if (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) {
|
||||
return manifest.engines.node;
|
||||
}
|
||||
|
||||
@ -90,21 +90,31 @@ 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 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
|
||||
{
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
"node": "^22 || ^24"
|
||||
},
|
||||
"devEngines": {
|
||||
"runtime": {
|
||||
"name": "node",
|
||||
"version": "^24.3"
|
||||
}
|
||||
},
|
||||
"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
|
||||
|
||||
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).
|
||||
|
||||
1
package-lock.json
generated
1
package-lock.json
generated
@ -522,6 +522,7 @@
|
||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
|
||||
@ -46,9 +46,10 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||
newContents += `${authString}${os.EOL}${registryString}`;
|
||||
fs.writeFileSync(fileLocation, newContents);
|
||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
|
||||
core.exportVariable(
|
||||
'NODE_AUTH_TOKEN',
|
||||
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
|
||||
);
|
||||
// Only export NODE_AUTH_TOKEN if explicitly provided by user
|
||||
// This is required to support NPM OIDC tokens which need NODE_AUTH_TOKEN to be unset
|
||||
// See: https://github.com/actions/setup-node/issues/1440
|
||||
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
|
||||
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
12
src/util.ts
12
src/util.ts
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user