Skip to content

Commit 94f88d7

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents d79e93a + 348e008 commit 94f88d7

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

.github/workflows/versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
fail-fast: false
9393
matrix:
9494
os: [ubuntu-latest, windows-latest, macos-latest]
95-
node-version-file: [.nvmrc, .tool-versions]
95+
node-version-file: [.nvmrc, .tool-versions, package.json]
9696
steps:
9797
- uses: actions/checkout@v3
9898
- name: Setup node from node version file

__tests__/data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"engines": {
3-
"node": ">=14.0.0"
3+
"node": "^14.0.0"
44
},
55
"volta": {
66
"node": "14.0.0"

dist/setup/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71770,14 +71770,19 @@ function translateArchToDistUrl(arch) {
7177071770
function parseNodeVersionFile(contents) {
7177171771
var _a, _b, _c;
7177271772
let nodeVersion;
71773-
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
71774-
nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
71773+
// Try parsing the file as an NPM `package.json` file.
71774+
try {
71775+
nodeVersion = (_a = JSON.parse(contents).volta) === null || _a === void 0 ? void 0 : _a.node;
71776+
if (!nodeVersion)
71777+
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
71778+
}
71779+
catch (_d) {
71780+
core.warning('Node version file is not JSON file');
71781+
}
7177571782
if (!nodeVersion) {
7177671783
try {
71777-
// Try parsing the file as an NPM `package.json` file.
71778-
nodeVersion = (_b = JSON.parse(contents).volta) === null || _b === void 0 ? void 0 : _b.node;
71779-
if (!nodeVersion)
71780-
nodeVersion = (_c = JSON.parse(contents).engines) === null || _c === void 0 ? void 0 : _c.node;
71784+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
71785+
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
7178171786
if (!nodeVersion)
7178271787
throw new Error();
7178371788
}

src/installer.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,19 @@ function translateArchToDistUrl(arch: string): string {
497497
export function parseNodeVersionFile(contents: string): string {
498498
let nodeVersion: string | undefined;
499499

500-
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
501-
nodeVersion = found?.groups?.version;
500+
// Try parsing the file as an NPM `package.json` file.
501+
try {
502+
nodeVersion = JSON.parse(contents).volta?.node;
503+
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
504+
} catch {
505+
core.warning('Node version file is not JSON file');
506+
}
502507

503508
if (!nodeVersion) {
504509
try {
505-
// Try parsing the file as an NPM `package.json` file.
506-
nodeVersion = JSON.parse(contents).volta?.node;
507-
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
510+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
511+
nodeVersion = found?.groups?.version;
512+
508513
if (!nodeVersion) throw new Error();
509514
} catch (err) {
510515
// In the case of an unknown format,

0 commit comments

Comments
 (0)