Skip to content

Commit

Permalink
fix: check node version
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Oct 16, 2023
1 parent f336dd9 commit e93b952
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
});

Expand Down
9 changes: 6 additions & 3 deletions src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit e93b952

Please sign in to comment.