From 389036835e6197253dbe84cdac1af7c32e74582d Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 3 Aug 2022 11:17:53 +0200 Subject: [PATCH] Fix node version file parsing --- src/installer.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 193ff16a..a9afb2ff 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -497,14 +497,14 @@ function translateArchToDistUrl(arch: string): string { export function parseNodeVersionFile(contents: string): string { let nodeVersion: string | undefined; - const found = contents.match(/^(?:nodejs\s+)?v?(?[^\s]+)$/m); - nodeVersion = found?.groups?.version; + // Try parsing the file as an NPM `package.json` + // file. + nodeVersion = JSON.parse(contents).engines?.node; 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?(?[^\s]+)$/m); + nodeVersion = found?.groups?.version; if (!nodeVersion) throw new Error(); } catch (err) {