mirror of
https://code.forgejo.org/actions/setup-node
synced 2025-03-15 14:54:38 +01:00
Merge b0f1a15a39
into 802632921f
This commit is contained in:
commit
5177c1a4cf
9 changed files with 4154 additions and 4421 deletions
2
.github/workflows/versions.yml
vendored
2
.github/workflows/versions.yml
vendored
|
@ -159,7 +159,7 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
os: [ubuntu-latest, windows-latest, macos-latest, macos-13]
|
||||||
node-version-file:
|
node-version-file:
|
||||||
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
[.nvmrc, .tool-versions, .tool-versions-node, package.json, .npmrc]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup node from node version file
|
- name: Setup node from node version file
|
||||||
|
|
1
__tests__/data/.npmrc
Normal file
1
__tests__/data/.npmrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
use-node-version=20.0.0
|
|
@ -103,10 +103,13 @@ describe('main tests', () => {
|
||||||
${''} | ${''}
|
${''} | ${''}
|
||||||
${'unknown format'} | ${'unknown format'}
|
${'unknown format'} | ${'unknown format'}
|
||||||
${' 14.1.0 '} | ${'14.1.0'}
|
${' 14.1.0 '} | ${'14.1.0'}
|
||||||
|
${'use-node-version=lts/iron'} | ${'lts/iron'}
|
||||||
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
||||||
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
|
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
|
||||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
||||||
${'{}'} | ${null}
|
${'{}'} | ${null}
|
||||||
|
${'[section]use-node-version=16'} | ${null}
|
||||||
|
${'[section]\nuse-node-version=20'} | ${null}
|
||||||
`.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);
|
||||||
|
|
3379
dist/cache-save/index.js
vendored
3379
dist/cache-save/index.js
vendored
File diff suppressed because it is too large
Load diff
3424
dist/setup/index.js
vendored
3424
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
1736
package-lock.json
generated
1736
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -33,6 +33,7 @@
|
||||||
"@actions/http-client": "^2.2.1",
|
"@actions/http-client": "^2.2.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
|
"ini": "^5.0.0",
|
||||||
"semver": "^7.6.3",
|
"semver": "^7.6.3",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
|
3
src/ini.d.ts
vendored
Normal file
3
src/ini.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
declare module 'ini' {
|
||||||
|
function parse(ini: string): Record<string, string | object>;
|
||||||
|
}
|
20
src/util.ts
20
src/util.ts
|
@ -3,6 +3,7 @@ import * as exec from '@actions/exec';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import * as INI from 'ini';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||||
|
@ -56,6 +57,25 @@ export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try parsing the file as an NPM `.npmrc` file.
|
||||||
|
//
|
||||||
|
// If the file contents contain the use-node-version key, we conclude it's an
|
||||||
|
// `.npmrc` file.
|
||||||
|
if (contents.match(/use-node-version *=/)) {
|
||||||
|
const manifest = INI.parse(contents);
|
||||||
|
const key = 'use-node-version';
|
||||||
|
|
||||||
|
if (key in manifest && typeof manifest[key] === 'string') {
|
||||||
|
const version = manifest[key];
|
||||||
|
core.info(`Using node version ${version} from global INI ${key}`);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We didn't find the key `use-node-version` in the global scope of the
|
||||||
|
// `.npmrc` file, so we return.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
return found?.groups?.version ?? contents.trim();
|
return found?.groups?.version ?? contents.trim();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue