mirror of
https://github.com/actions/setup-node.git
synced 2026-07-01 02:41:38 +00:00
Compare commits
1 Commits
7a65b23cf1
...
2d43d2d85d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d43d2d85d |
@ -107,7 +107,6 @@ describe('main tests', () => {
|
|||||||
${' 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": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
|
||||||
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
|
||||||
${'{}'} | ${null}
|
|
||||||
`.it('parses "$contents"', ({contents, expected}) => {
|
`.it('parses "$contents"', ({contents, expected}) => {
|
||||||
expect(util.parseNodeVersionFile(contents)).toBe(expected);
|
expect(util.parseNodeVersionFile(contents)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|||||||
22
dist/cache-save/index.js
vendored
22
dist/cache-save/index.js
vendored
@ -83338,25 +83338,9 @@ function parseNodeVersionFile(contents) {
|
|||||||
let nodeVersion;
|
let nodeVersion;
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
const manifest = JSON.parse(contents);
|
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
||||||
// JSON can parse numbers, but that's handled later
|
if (!nodeVersion)
|
||||||
if (typeof manifest === 'object') {
|
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
||||||
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
|
|
||||||
if (!nodeVersion)
|
|
||||||
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
|
|
||||||
// if contents are an object, we parsed JSON
|
|
||||||
// this can happen if node-version-file is a package.json
|
|
||||||
// yet contains no volta.node or engines.node
|
|
||||||
//
|
|
||||||
// if node-version file is _not_ json, control flow
|
|
||||||
// will not have reached these lines.
|
|
||||||
//
|
|
||||||
// And because we've reached here, we know the contents
|
|
||||||
// *are* JSON, so no further string parsing makes sense.
|
|
||||||
if (!nodeVersion) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (_d) {
|
catch (_d) {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
|
|||||||
30
dist/setup/index.js
vendored
30
dist/setup/index.js
vendored
@ -93731,13 +93731,7 @@ function resolveVersionInput() {
|
|||||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
||||||
}
|
}
|
||||||
const parsedVersion = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
version = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
||||||
if (parsedVersion) {
|
|
||||||
version = parsedVersion;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.warning(`Could not determine node version from ${versionFilePath}. Falling back`);
|
|
||||||
}
|
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
@ -93792,25 +93786,9 @@ function parseNodeVersionFile(contents) {
|
|||||||
let nodeVersion;
|
let nodeVersion;
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
const manifest = JSON.parse(contents);
|
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
|
||||||
// JSON can parse numbers, but that's handled later
|
if (!nodeVersion)
|
||||||
if (typeof manifest === 'object') {
|
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
|
||||||
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
|
|
||||||
if (!nodeVersion)
|
|
||||||
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
|
|
||||||
// if contents are an object, we parsed JSON
|
|
||||||
// this can happen if node-version-file is a package.json
|
|
||||||
// yet contains no volta.node or engines.node
|
|
||||||
//
|
|
||||||
// if node-version file is _not_ json, control flow
|
|
||||||
// will not have reached these lines.
|
|
||||||
//
|
|
||||||
// And because we've reached here, we know the contents
|
|
||||||
// *are* JSON, so no further string parsing makes sense.
|
|
||||||
if (!nodeVersion) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (_d) {
|
catch (_d) {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
|
|||||||
12
src/main.ts
12
src/main.ts
@ -109,17 +109,7 @@ function resolveVersionInput(): string {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedVersion = parseNodeVersionFile(
|
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
|
||||||
fs.readFileSync(versionFilePath, 'utf8')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (parsedVersion) {
|
|
||||||
version = parsedVersion;
|
|
||||||
} else {
|
|
||||||
core.warning(
|
|
||||||
`Could not determine node version from ${versionFilePath}. Falling back`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/util.ts
24
src/util.ts
@ -1,31 +1,13 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export function parseNodeVersionFile(contents: string): string | null {
|
export function parseNodeVersionFile(contents: string): string {
|
||||||
let nodeVersion: string | undefined;
|
let nodeVersion: string | undefined;
|
||||||
|
|
||||||
// Try parsing the file as an NPM `package.json` file.
|
// Try parsing the file as an NPM `package.json` file.
|
||||||
try {
|
try {
|
||||||
const manifest = JSON.parse(contents);
|
nodeVersion = JSON.parse(contents).volta?.node;
|
||||||
|
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
|
||||||
// JSON can parse numbers, but that's handled later
|
|
||||||
if (typeof manifest === 'object') {
|
|
||||||
nodeVersion = manifest.volta?.node;
|
|
||||||
if (!nodeVersion) nodeVersion = manifest.engines?.node;
|
|
||||||
|
|
||||||
// if contents are an object, we parsed JSON
|
|
||||||
// this can happen if node-version-file is a package.json
|
|
||||||
// yet contains no volta.node or engines.node
|
|
||||||
//
|
|
||||||
// if node-version file is _not_ json, control flow
|
|
||||||
// will not have reached these lines.
|
|
||||||
//
|
|
||||||
// And because we've reached here, we know the contents
|
|
||||||
// *are* JSON, so no further string parsing makes sense.
|
|
||||||
if (!nodeVersion) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
core.info('Node version file is not JSON file');
|
core.info('Node version file is not JSON file');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user