@@ -93728,7 +93728,13 @@ function resolveVersionInput() {
93728
93728
if (!fs_1.default.existsSync(versionFilePath)) {
93729
93729
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
93730
93730
}
93731
- version = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
93731
+ const parsedVersion = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
93732
+ if (parsedVersion) {
93733
+ version = parsedVersion;
93734
+ }
93735
+ else {
93736
+ core.warning(`Could not determine node version from ${versionFilePath}. Falling back`);
93737
+ }
93732
93738
core.info(`Resolved ${versionFileInput} as ${version}`);
93733
93739
}
93734
93740
return version;
@@ -93783,9 +93789,25 @@ function parseNodeVersionFile(contents) {
93783
93789
let nodeVersion;
93784
93790
// Try parsing the file as an NPM `package.json` file.
93785
93791
try {
93786
- nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
93787
- if (!nodeVersion)
93788
- nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
93792
+ const manifest = JSON.parse(contents);
93793
+ // JSON can parse numbers, but that's handled later
93794
+ if (typeof manifest === 'object') {
93795
+ nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
93796
+ if (!nodeVersion)
93797
+ nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
93798
+ // if contents are an object, we parsed JSON
93799
+ // this can happen if node-version-file is a package.json
93800
+ // yet contains no volta.node or engines.node
93801
+ //
93802
+ // if node-version file is _not_ json, control flow
93803
+ // will not have reached these lines.
93804
+ //
93805
+ // And because we've reached here, we know the contents
93806
+ // *are* JSON, so no further string parsing makes sense.
93807
+ if (!nodeVersion) {
93808
+ return null;
93809
+ }
93810
+ }
93789
93811
}
93790
93812
catch (_d) {
93791
93813
core.info('Node version file is not JSON file');
0 commit comments