mirror of
https://code.forgejo.org/actions/setup-node.git
synced 2025-05-19 21:04:45 +00:00
Fix node version file parsing (#553)
* Fix node version file parsing * Build index.js * Non-json file error handling * Format code * Add package.json to e2e tests * Minor fix
This commit is contained in:
parent
2a814b57e1
commit
348e008008
4 changed files with 21 additions and 12 deletions
|
@ -497,14 +497,18 @@ function translateArchToDistUrl(arch: string): string {
|
|||
export function parseNodeVersionFile(contents: string): string {
|
||||
let nodeVersion: string | undefined;
|
||||
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = found?.groups?.version;
|
||||
// Try parsing the file as an NPM `package.json`
|
||||
// file.
|
||||
try {
|
||||
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).engines?.node;
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = found?.groups?.version;
|
||||
|
||||
if (!nodeVersion) throw new Error();
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue