UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

63 lines (62 loc) • 2.76 kB
import { t as isBunRuntime } from "./runtime-binary-Cc9EAiQv.js"; import "./cli-invocation-Df8-W3Wc.js"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { readRootJsonObjectSync } from "@openclaw/fs-safe/json"; //#region runtime-process-bootstrap.generated.mjs const distRoot = resolveRuntimeProcessDistRoot(fileURLToPath(import.meta.url)); /** @param {string} currentPath */ function resolveRuntimeProcessDistRoot(e) { const t = e.replaceAll(path.sep, "/").lastIndexOf("/dist/"); return t >= 0 ? e.slice(0, t + 6) : void 0; } //#endregion //#region src/infra/runtime-worker-url.ts /** Resolve an explicit installed root, source sibling, or stable packaged worker path. */ function resolveRuntimeWorkerUrl(e) { if (e.root !== void 0) return pathToFileURL(path.join(e.root, "dist", e.distWorkerPath)); const t = fileURLToPath(e.currentModuleUrl); const n = resolveRuntimeProcessDistRoot(t); if (n !== void 0) { let t = e.distWorkerPath; if (e.package) { const r = path.resolve(n, ".."); const i = readRootJsonObjectSync({ rootDir: r, relativePath: "package.json", boundaryLabel: "runtime worker package", rejectHardlinks: false }); if (!i.ok) throw new Error(`Cannot resolve runtime worker package: ${r}/package.json`); if (i.value.name === e.package.name) t = e.package.distWorkerPath; } return pathToFileURL(path.join(n, t)); } const r = e.sourceExtension ?? (path.extname(t) || ".js"); return new URL(`./${e.sourceWorkerName}${r}`, e.currentModuleUrl); } function isBunTargetRuntime(e) { return e === process.execPath ? Boolean(process.versions.bun) : isBunRuntime(e); } /** Disable implicit package installation in OpenClaw-owned Bun processes. */ function resolveRuntimeArgs(e = process.execPath) { return isBunTargetRuntime(e) ? ["--no-install"] : []; } /** Whether a source TypeScript module needs Node's tsx loader; Bun runs TypeScript natively. */ function runtimeNeedsTypeScriptLoader(e, t = process.execPath) { return /\.[cm]?ts$/.test(e) && !isBunTargetRuntime(t); } function resolveRuntimeWorkerArgv(e, t = process.execPath) { const n = fileURLToPath(e); return runtimeNeedsTypeScriptLoader(n, t) ? [ "--import", import.meta.resolve("tsx"), n ] : [...resolveRuntimeArgs(t), n]; } /** Select the source Worker preload without feeding Node's TypeScript loader to Bun. */ function resolveRuntimeWorkerThreadExecArgv(e, t = process.execPath) { return e.protocol === "file:" && runtimeNeedsTypeScriptLoader(fileURLToPath(e), t) ? ["--import", import.meta.resolve("tsx/esm")] : []; } //#endregion export { runtimeNeedsTypeScriptLoader as i, resolveRuntimeWorkerThreadExecArgv as n, resolveRuntimeWorkerUrl as r, resolveRuntimeWorkerArgv as t };