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

feat: add volta as node-version-file #532

Merged
merged 21 commits into from
Sep 12, 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
Merge remote-tracking branch 'upstream/main'
  • Loading branch information
jef committed Aug 4, 2022
commit 94f88d78c4057b5883734ba04b3299da3c8955c7
2 changes: 1 addition & 1 deletion __tests__/data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"engines": {
"node": ">=14.0.0"
"node": "^14.0.0"
},
"volta": {
"node": "14.0.0"
Expand Down
15 changes: 7 additions & 8 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71770,20 +71770,19 @@ function translateArchToDistUrl(arch) {
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
// Try parsing the file as an NPM `package.json`
// file.
// Try parsing the file as an NPM `package.json` file.
try {
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
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;
}
catch (_c) {
catch (_d) {
core.warning('Node version file is not JSON file');
}
if (!nodeVersion) {
try {
// Try parsing the file as an NPM `package.json` file.
nodeVersion = (_b = JSON.parse(contents).volta) === null || _b === void 0 ? void 0 : _b.node;
if (!nodeVersion)
nodeVersion = (_c = JSON.parse(contents).engines) === null || _c === void 0 ? void 0 : _c.node;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
if (!nodeVersion)
throw new Error();
}
Expand Down
12 changes: 6 additions & 6 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,19 @@ function translateArchToDistUrl(arch: string): string {
export function parseNodeVersionFile(contents: string): string {
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 {
nodeVersion = JSON.parse(contents).engines?.node;
nodeVersion = JSON.parse(contents).volta?.node;
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
} catch {
core.warning('Node version file is not JSON file');
}

if (!nodeVersion) {
try {
// Try parsing the file as an NPM `package.json` file.
nodeVersion = JSON.parse(contents).volta?.node;
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = found?.groups?.version;

if (!nodeVersion) throw new Error();
} catch (err) {
// In the case of an unknown format,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.