mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor(runtime): unify node version guard parsing
This commit is contained in:
21
openclaw.mjs
21
openclaw.mjs
@@ -4,18 +4,27 @@ import module from "node:module";
|
||||
|
||||
const MIN_NODE_MAJOR = 22;
|
||||
const MIN_NODE_MINOR = 12;
|
||||
const MIN_NODE_VERSION = `${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}`;
|
||||
|
||||
const parseNodeVersion = (rawVersion) => {
|
||||
const [majorRaw = "0", minorRaw = "0"] = rawVersion.split(".");
|
||||
return {
|
||||
major: Number(majorRaw),
|
||||
minor: Number(minorRaw),
|
||||
};
|
||||
};
|
||||
|
||||
const isSupportedNodeVersion = (version) =>
|
||||
version.major > MIN_NODE_MAJOR ||
|
||||
(version.major === MIN_NODE_MAJOR && version.minor >= MIN_NODE_MINOR);
|
||||
|
||||
const ensureSupportedNodeVersion = () => {
|
||||
const [majorRaw = "0", minorRaw = "0"] = process.versions.node.split(".");
|
||||
const major = Number(majorRaw);
|
||||
const minor = Number(minorRaw);
|
||||
const supported = major > MIN_NODE_MAJOR || (major === MIN_NODE_MAJOR && minor >= MIN_NODE_MINOR);
|
||||
if (supported) {
|
||||
if (isSupportedNodeVersion(parseNodeVersion(process.versions.node))) {
|
||||
return;
|
||||
}
|
||||
|
||||
process.stderr.write(
|
||||
`openclaw: Node.js v${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}+ is required (current: v${process.versions.node}).\n` +
|
||||
`openclaw: Node.js v${MIN_NODE_VERSION}+ is required (current: v${process.versions.node}).\n` +
|
||||
"If you use nvm, run:\n" +
|
||||
" nvm install 22\n" +
|
||||
" nvm use 22\n" +
|
||||
|
||||
Reference in New Issue
Block a user