mirror of
https://github.com/actions/setup-node.git
synced 2026-07-28 00:55:46 +00:00
Merge 914052aadc into 32f57ac043
This commit is contained in:
commit
a474c1b4ce
@ -216,6 +216,35 @@ describe('main tests', () => {
|
|||||||
|
|
||||||
expect(util.getNodeVersionFromFile('file')).toBe(expected);
|
expect(util.getNodeVersionFromFile('file')).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
each`
|
||||||
|
name | contents | expected
|
||||||
|
${'ignores blank lines and comments'} | ${'# use the version below\n\n 20.16.0 # maintenance release\n'} | ${'20.16.0'}
|
||||||
|
${'strips an inline comment'} | ${'v20.16.0 # maintenance release'} | ${'20.16.0'}
|
||||||
|
${'preserves an alias before a comment'} | ${'lts/* # use the latest LTS'} | ${'lts/*'}
|
||||||
|
${'rejects a comment-only file'} | ${'# comment only'} | ${null}
|
||||||
|
${'rejects comments and whitespace only'} | ${'#\r\n # another comment\r\n'} | ${null}
|
||||||
|
`.it('$name', ({contents, expected}: any) => {
|
||||||
|
const existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
|
existsSpy.mockImplementation(() => true);
|
||||||
|
|
||||||
|
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
|
readFileSpy.mockImplementation(() => contents);
|
||||||
|
|
||||||
|
expect(util.getNodeVersionFromFile('.nvmrc')).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves .tool-versions parsing', () => {
|
||||||
|
const existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
|
existsSpy.mockImplementation(() => true);
|
||||||
|
|
||||||
|
const readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
|
readFileSpy.mockImplementation(
|
||||||
|
() => 'ruby 3.3.0\nnodejs 20.16.0\npython 3.12.0'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(util.getNodeVersionFromFile('.tool-versions')).toBe('20.16.0');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('printEnvDetailsAndSetOutput', () => {
|
describe('printEnvDetailsAndSetOutput', () => {
|
||||||
|
|||||||
15
dist/cache-save/index.js
vendored
15
dist/cache-save/index.js
vendored
@ -92709,8 +92709,19 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
catch {
|
catch {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
let versionFileContents = contents;
|
||||||
return found?.groups?.version ?? contents.trim();
|
if (path.basename(versionFilePath) === '.nvmrc') {
|
||||||
|
versionFileContents = contents
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map(line => line.replace(/#.*/, '').trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
if (!versionFileContents) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const found = versionFileContents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
|
return found?.groups?.version ?? versionFileContents.trim();
|
||||||
}
|
}
|
||||||
async function printEnvDetailsAndSetOutput() {
|
async function printEnvDetailsAndSetOutput() {
|
||||||
core.startGroup('Environment details');
|
core.startGroup('Environment details');
|
||||||
|
|||||||
15
dist/setup/index.js
vendored
15
dist/setup/index.js
vendored
@ -98103,8 +98103,19 @@ function getNodeVersionFromFile(versionFilePath) {
|
|||||||
catch {
|
catch {
|
||||||
core_info('Node version file is not JSON file');
|
core_info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
let versionFileContents = contents;
|
||||||
return found?.groups?.version ?? contents.trim();
|
if (external_path_default().basename(versionFilePath) === '.nvmrc') {
|
||||||
|
versionFileContents = contents
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map(line => line.replace(/#.*/, '').trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
if (!versionFileContents) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const found = versionFileContents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||||
|
return found?.groups?.version ?? versionFileContents.trim();
|
||||||
}
|
}
|
||||||
async function printEnvDetailsAndSetOutput() {
|
async function printEnvDetailsAndSetOutput() {
|
||||||
startGroup('Environment details');
|
startGroup('Environment details');
|
||||||
|
|||||||
20
src/util.ts
20
src/util.ts
@ -68,8 +68,24 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
let versionFileContents = contents;
|
||||||
return found?.groups?.version ?? contents.trim();
|
|
||||||
|
if (path.basename(versionFilePath) === '.nvmrc') {
|
||||||
|
versionFileContents = contents
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map(line => line.replace(/#.*/, '').trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.join('\n');
|
||||||
|
|
||||||
|
if (!versionFileContents) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const found = versionFileContents.match(
|
||||||
|
/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m
|
||||||
|
);
|
||||||
|
return found?.groups?.version ?? versionFileContents.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function printEnvDetailsAndSetOutput() {
|
export async function printEnvDetailsAndSetOutput() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user