Files
openclaw/openclaw.mjs
yunxiafei 89a243be70
Some checks failed
CI / docs-scope (push) Has been cancelled
CI / secrets (push) Has been cancelled
CI / ios (push) Has been cancelled
Docker Release / validate_manual_backfill (push) Has been cancelled
Install Smoke / docs-scope (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / config-docs-drift (push) Has been cancelled
CI / changed-scope (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / release-check (push) Has been cancelled
CI / checks (pnpm canvas:a2ui:bundle && bunx vitest run --config vitest.unit.config.ts, bun, test) (push) Has been cancelled
CI / checks (pnpm canvas:a2ui:bundle && pnpm test, node, 2, 1, test) (push) Has been cancelled
CI / checks (pnpm canvas:a2ui:bundle && pnpm test, node, 2, 2, test) (push) Has been cancelled
CI / checks (pnpm protocol:check, node, protocol) (push) Has been cancelled
CI / checks (pnpm test:channels, node, channels) (push) Has been cancelled
CI / checks (pnpm test:extensions, node, extensions) (push) Has been cancelled
CI / check (push) Has been cancelled
CI / startup-memory (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / compat-node22 (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 1, test) (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 2, test) (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 3, test) (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 4, test) (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 5, test) (push) Has been cancelled
CI / checks-windows (pnpm test, node, 6, 6, test) (push) Has been cancelled
CI / macos (push) Has been cancelled
CI / android (./gradlew --no-daemon :app:assembleDebug, build) (push) Has been cancelled
CI / android (./gradlew --no-daemon :app:testDebugUnitTest, test) (push) Has been cancelled
Docker Release / approve_manual_backfill (push) Has been cancelled
Docker Release / build-amd64 (push) Has been cancelled
Docker Release / build-arm64 (push) Has been cancelled
Docker Release / create-manifest (push) Has been cancelled
Install Smoke / install-smoke (push) Has been cancelled
初版
2026-03-16 17:22:13 +08:00

90 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
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 = () => {
if (isSupportedNodeVersion(parseNodeVersion(process.versions.node))) {
return;
}
process.stderr.write(
`openclaw: Node.js v${MIN_NODE_VERSION}+ is required (current: v${process.versions.node}).\n` +
"If you use nvm, run:\n" +
` nvm install ${MIN_NODE_MAJOR}\n` +
` nvm use ${MIN_NODE_MAJOR}\n` +
` nvm alias default ${MIN_NODE_MAJOR}\n`,
);
process.exit(1);
};
ensureSupportedNodeVersion();
// https://nodejs.org/api/module.html#module-compile-cache
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
try {
module.enableCompileCache();
} catch {
// Ignore errors
}
}
const isModuleNotFoundError = (err) =>
err && typeof err === "object" && "code" in err && err.code === "ERR_MODULE_NOT_FOUND";
const installProcessWarningFilter = async () => {
// Keep bootstrap warnings consistent with the TypeScript runtime.
for (const specifier of ["./dist/warning-filter.js", "./dist/warning-filter.mjs"]) {
try {
const mod = await import(specifier);
if (typeof mod.installProcessWarningFilter === "function") {
mod.installProcessWarningFilter();
return;
}
} catch (err) {
if (isModuleNotFoundError(err)) {
continue;
}
throw err;
}
}
};
await installProcessWarningFilter();
const tryImport = async (specifier) => {
try {
await import(specifier);
return true;
} catch (err) {
// Only swallow missing-module errors; rethrow real runtime errors.
if (isModuleNotFoundError(err)) {
return false;
}
throw err;
}
};
if (await tryImport("./dist/entry.js")) {
// OK
} else if (await tryImport("./dist/entry.mjs")) {
// OK
} else {
throw new Error("openclaw: missing dist/entry.(m)js (build output).");
}