UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

94 lines (93 loc) • 3.41 kB
import { i as isUsableNode, o as resolveRecoveryPath } from "./node-runtime-recovery-BDQPyLO8.mjs"; import { fileURLToPath } from "node:url"; import path from "node:path"; import { spawnSync } from "node:child_process"; import { createInterface } from "node:readline"; //#region node-runtime-update.mjs function canInstallPrivateNode() { if (!["x64", "arm64"].includes(process.arch)) return false; if (process.platform === "linux") return Boolean(process.report?.getReport().header.glibcVersionRuntime); return process.platform === "darwin" || process.platform === "win32"; } function confirmNodeUpdate() { return new Promise((e) => { const t = createInterface({ input: process.stdin, output: process.stderr }); let n = false; const finish = (r) => { if (n) return; n = true; t.close(); e(/^(y|yes)$/i.test(r.trim())); }; t.once("close", () => finish("")); t.once("SIGINT", () => finish("")); t.question("Update NodeJS: Y/N [N]: ", finish); }); } /** Returns a verified private runtime, or null when recovery was declined/unavailable. */ async function resolveUpdatedNodeRuntime(e, { allowInstall: t = true, env: n = process.env, acceptVersion: r, nodeVersion: i, installCommand: a } = {}) { if (n.OPENCLAW_NODE_UPDATE_RESPAWNED === "1" && !a) return null; const o = { allowMissing: true, trustedRoot: e }; const s = resolveRecoveryPath(path.join(e, "tools", "cli-node"), void 0, o); const c = s && resolveRecoveryPath(path.join(s, "tools", "node"), void 0, o); if (!s || !c) return null; const l = process.platform === "win32" ? path.join(c, "node.exe") : path.join(c, "bin", "node"); if (isUsableNode(l, { env: n, trustedRoot: e, acceptVersion: r })) return l; if (!t || !a && (!process.stdin.isTTY || !process.stderr.isTTY || n.CI || process.argv.some((e) => [ "--non-interactive", "--json", "--yes" ].includes(e))) || a && !/^\d+\.\d+\.\d+$/.test(i ?? "") || !canInstallPrivateNode()) return null; if (!a) { process.stderr.write("Install a compatible Node.js for OpenClaw only and retry this command.\nThe Node.js installation will not change system Node.js, shell settings, or Gateway services.\n"); if (!await confirmNodeUpdate()) return null; } const u = process.platform === "win32"; const d = fileURLToPath(new URL(u ? "./scripts/install.ps1" : "./scripts/install-cli.sh", import.meta.url)); const f = u ? (await import("./windows-cmd-helpers-UvLV0i4g.mjs")).resolveWindowsPowerShellPath(n) : process.platform === "darwin" ? "/bin/bash" : "bash"; const p = u ? [ "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", d, "-NodeOnly", "-NodePrefix", c, ...i ? ["-NodeVersion", i] : [] ] : [ d, "--node-only", "--prefix", s, ...i ? ["--node-version", i] : [] ]; const m = (a ? await a(f, p, n) : spawnSync(f, p, { stdio: "inherit", env: n }).status) === 0 ? resolveRecoveryPath(path.join(s, "tools", "node"), void 0, { trustedRoot: e }) : null; const h = m && path.join(m, ...u ? ["node.exe"] : ["bin", "node"]); if (!h || !isUsableNode(h, { env: n, trustedRoot: e, acceptVersion: r })) { if (!a) process.stderr.write("openclaw: Node.js update failed; install a compatible Node.js manually.\n"); return null; } if (!a) process.stderr.write("openclaw: Node.js updated. Retrying your command.\n"); return h; } //#endregion export { resolveUpdatedNodeRuntime };