Skip to content

Commit 5bbf722

Browse files
Merge branch 'actions:main' into update-contributors-guide
2 parents dbb54d0 + 348e008 commit 5bbf722

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

.github/workflows/versions.yml

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"engines": {
3-
"node": ">=14.0.0"
3+
"node": "^14.0.0"
44
}
55
}

dist/setup/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -71770,13 +71770,18 @@ function translateArchToDistUrl(arch) {
7177071770
function parseNodeVersionFile(contents) {
7177171771
var _a, _b;
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`
71774+
// file.
71775+
try {
71776+
nodeVersion = (_a = JSON.parse(contents).engines) === null || _a === void 0 ? void 0 : _a.node;
71777+
}
71778+
catch (_c) {
71779+
core.warning('Node version file is not JSON file');
71780+
}
7177571781
if (!nodeVersion) {
7177671782
try {
71777-
// Try parsing the file as an NPM `package.json`
71778-
// file.
71779-
nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
71783+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
71784+
nodeVersion = (_b = found === null || found === void 0 ? void 0 : found.groups) === null || _b === void 0 ? void 0 : _b.version;
7178071785
if (!nodeVersion)
7178171786
throw new Error();
7178271787
}

src/installer.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,18 @@ 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`
501+
// file.
502+
try {
503+
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`
506-
// file.
507-
nodeVersion = JSON.parse(contents).engines?.node;
510+
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
511+
nodeVersion = found?.groups?.version;
508512

509513
if (!nodeVersion) throw new Error();
510514
} catch (err) {

0 commit comments

Comments
 (0)