1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-11-14 09:32:41 +00:00

Merge remote-tracking branch 'upstream/main'

This commit is contained in:
Jef LeCompte 2022-08-04 09:28:48 -07:00
commit 94f88d78c4
No known key found for this signature in database
GPG key ID: 7F5BA322B5DC170C
4 changed files with 23 additions and 13 deletions

View file

@ -92,7 +92,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
node-version-file: [.nvmrc, .tool-versions] node-version-file: [.nvmrc, .tool-versions, package.json]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup node from node version file - name: Setup node from node version file

View file

@ -1,6 +1,6 @@
{ {
"engines": { "engines": {
"node": ">=14.0.0" "node": "^14.0.0"
}, },
"volta": { "volta": {
"node": "14.0.0" "node": "14.0.0"

17
dist/setup/index.js vendored
View file

@ -71770,14 +71770,19 @@ function translateArchToDistUrl(arch) {
function parseNodeVersionFile(contents) { function parseNodeVersionFile(contents) {
var _a, _b, _c; var _a, _b, _c;
let nodeVersion; let nodeVersion;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m); // Try parsing the file as an NPM `package.json` file.
nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version; try {
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 (_d) {
core.warning('Node version file is not JSON file');
}
if (!nodeVersion) { if (!nodeVersion) {
try { try {
// Try parsing the file as an NPM `package.json` file. const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = (_b = JSON.parse(contents).volta) === null || _b === void 0 ? void 0 : _b.node; nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
if (!nodeVersion)
nodeVersion = (_c = JSON.parse(contents).engines) === null || _c === void 0 ? void 0 : _c.node;
if (!nodeVersion) if (!nodeVersion)
throw new Error(); throw new Error();
} }

View file

@ -497,14 +497,19 @@ function translateArchToDistUrl(arch: string): string {
export function parseNodeVersionFile(contents: string): string { export function parseNodeVersionFile(contents: string): string {
let nodeVersion: string | undefined; let nodeVersion: string | undefined;
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m); // Try parsing the file as an NPM `package.json` file.
nodeVersion = found?.groups?.version; try {
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) { if (!nodeVersion) {
try { try {
// Try parsing the file as an NPM `package.json` file. const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = JSON.parse(contents).volta?.node; nodeVersion = found?.groups?.version;
if (!nodeVersion) nodeVersion = JSON.parse(contents).engines?.node;
if (!nodeVersion) throw new Error(); if (!nodeVersion) throw new Error();
} catch (err) { } catch (err) {
// In the case of an unknown format, // In the case of an unknown format,