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

Fix node version file parsing #553

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Non-json file error handling
  • Loading branch information
Vladimir Safonkin committed Aug 3, 2022
commit e22d92112e4396ad95d74ff483273903d6159100
7 changes: 6 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71772,7 +71772,12 @@ function parseNodeVersionFile(contents) {
let nodeVersion;
// Try parsing the file as an NPM `package.json`
// file.
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
try {
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
}
catch (_c) {
core.warning("Node version file is not JSON file");
}
if (!nodeVersion) {
try {
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
Expand Down
6 changes: 5 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,11 @@ export function parseNodeVersionFile(contents: string): string {

// Try parsing the file as an NPM `package.json`
// file.
nodeVersion = JSON.parse(contents).engines?.node;
try {
nodeVersion = JSON.parse(contents).engines?.node;
} catch {
core.warning("Node version file is not JSON file")
}

if (!nodeVersion) {
try {
Expand Down