From e93b952c781c7c2da9e717adab2bda2ef213e730 Mon Sep 17 00:00:00 2001 From: Jack Hamer Date: Mon, 16 Oct 2023 18:35:08 +0300 Subject: [PATCH] fix: check node version --- src/program.ts | 12 ++++++++---- src/utils/node.ts | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/program.ts b/src/program.ts index a71d97f0..7b6fc600 100644 --- a/src/program.ts +++ b/src/program.ts @@ -18,10 +18,14 @@ program.name(Package.name).description(Package.description).version(Package.vers program.hook("preAction", async () => { const nodeVersion = await getNodeVersion(); const minimumNodeVersion = "18.0.0"; - if (compare(nodeVersion, minimumNodeVersion, "<")) { - Logger.error("Minimum Node.js version required: v18.x"); - Logger.error(`Current version: v${nodeVersion}`); - process.exit(1); + try { + if (compare(nodeVersion, minimumNodeVersion, "<")) { + Logger.error("Minimum Node.js version required: v18.x"); + Logger.error(`Current version: v${nodeVersion}`); + process.exit(1); + } + } catch (error) { + Logger.warn(`Failed to check Node.js version. Make sure you are using version ${minimumNodeVersion} or higher`); } }); diff --git a/src/utils/node.ts b/src/utils/node.ts index 0fbc0228..fc2690eb 100644 --- a/src/utils/node.ts +++ b/src/utils/node.ts @@ -5,9 +5,12 @@ let nodeVersion: string | undefined; export const getNodeVersion = async () => { if (nodeVersion) return nodeVersion; try { - const version = await executeCommand("node --version", { silent: true }); - nodeVersion = version.trim().slice(1); - return nodeVersion; + const version = (await executeCommand("node --version", { silent: true })).trim(); + const vIndex = version.indexOf("v"); + if (vIndex === -1) { + return version; + } + return version.slice(vIndex + 1); } catch { throw new Error("Node.js is not installed. Download: http://nodejs.org"); }