Skip to content

Commit

Permalink
Don't use regex to parse the node version
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Oct 30, 2024
1 parent b1030da commit 5e5ab14
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions v-next/hardhat/src/internal/cli/node-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@

import chalk from "chalk";

const SEMVER_REV_REGEX = /^(\d+)\.(\d+)\.(\d)+$/;

const MIN_SUPPORTED_NODE_VERSION = [22, 10, 0];

function isNodeVersionSupported(): boolean {
const nodeVersion = process.versions.node;
const semverMatch = SEMVER_REV_REGEX.exec(nodeVersion);

if (semverMatch === null) {
return false;
}

const major = parseInt(semverMatch[1], 10);
const minor = parseInt(semverMatch[2], 10);
const patch = parseInt(semverMatch[3], 10);

if (major < MIN_SUPPORTED_NODE_VERSION[0]) {
return false;
}

if (minor < MIN_SUPPORTED_NODE_VERSION[1]) {
return false;
}

if (patch < MIN_SUPPORTED_NODE_VERSION[2]) {
return false;
try {
const [majorStr, minorStr, patchStr] = process.versions.node.split(".");

const major = parseInt(majorStr, 10);
const minor = parseInt(minorStr, 10);
const patch = parseInt(patchStr, 10);

if (major < MIN_SUPPORTED_NODE_VERSION[0]) {
return false;
}

if (minor < MIN_SUPPORTED_NODE_VERSION[1]) {
return false;
}

if (patch < MIN_SUPPORTED_NODE_VERSION[2]) {
return false;
}
} catch {
// If our parsing of the version fails we assume it's supported.
return true;
}

return true;
Expand Down

0 comments on commit 5e5ab14

Please sign in to comment.