Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('main tests', () => {
${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => {
expect(util.parseNodeVersionFile(contents)).toBe(expected);
});
Expand Down
25 changes: 22 additions & 3 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83324,14 +83324,33 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
//export function parseNodeVersionFile(contents: string): string {
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
//nodeVersion = JSON.parse(contents).volta?.node;
//if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
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) {
core.info('Node version file is not JSON file');
Expand Down
35 changes: 30 additions & 5 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93669,7 +93669,6 @@ function run() {
const version = resolveVersionInput();
let arch = core.getInput('architecture');
const cache = core.getInput('cache');
core.info("from Haritha's setup node repo");
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
Expand Down Expand Up @@ -93729,7 +93728,14 @@ function resolveVersionInput() {
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
version = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
//version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
const parsedVersion = (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}`);
}
return version;
Expand Down Expand Up @@ -93779,14 +93785,33 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
//export function parseNodeVersionFile(contents: string): string {
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
//nodeVersion = JSON.parse(contents).volta?.node;
//if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
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) {
core.info('Node version file is not JSON file');
Expand Down
15 changes: 13 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function run() {
let arch = core.getInput('architecture');
const cache = core.getInput('cache');

core.info("from Haritha's setup node repo");
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
if (arch && !version) {
Expand Down Expand Up @@ -106,7 +105,19 @@ function resolveVersionInput(): string {
);
}

version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));

//version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
const parsedVersion = parseNodeVersionFile(
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}`);
}
Expand Down
28 changes: 25 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';

export function parseNodeVersionFile(contents: string): string {
//export function parseNodeVersionFile(contents: string): string {
export function parseNodeVersionFile(contents: string): string | null {
let nodeVersion: string | undefined;

// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = JSON.parse(contents).volta?.node;
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
//nodeVersion = JSON.parse(contents).volta?.node;
//if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;

const manifest = JSON.parse(contents);

// 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 {
core.info('Node version file is not JSON file');
}
Expand Down
Loading