openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.11 kB
JavaScript
import"./cli-invocation-BQt-q4O8.js";import{t as isBunRuntime}from"./runtime-binary-CSMtzJzW.js";import path from"node:path";import{fileURLToPath,pathToFileURL}from"node:url";import{readRootJsonObjectSync}from"@openclaw/fs-safe/json";const distRoot=resolveRuntimeProcessDistRoot(fileURLToPath(import.meta.url));function resolveRuntimeProcessDistRoot(e){const t=e.replaceAll(path.sep,`/`).lastIndexOf(`/dist/`);return t>=0?e.slice(0,t+6):void 0}
//!src/infra/runtime-worker-url.ts
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)}function resolveRuntimeArgs(e=process.execPath){return isBunTargetRuntime(e)?[`--no-install`]:[]}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]}function resolveRuntimeWorkerThreadExecArgv(e,t=process.execPath){if(typeof SEALED_RUNTIME_BUILD===`boolean`&&SEALED_RUNTIME_BUILD)return[];return e.protocol===`file:`&&runtimeNeedsTypeScriptLoader(fileURLToPath(e),t)?[`--import`,import.meta.resolve(`tsx/esm`)]:[]}export{runtimeNeedsTypeScriptLoader as i,resolveRuntimeWorkerThreadExecArgv as n,resolveRuntimeWorkerUrl as r,resolveRuntimeWorkerArgv as t};