UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.71 kB
import{a as e}from"./git-operation.worker-src-D09IpTfC.mjs";import"./git-operation.worker-cli-invocation-D4VTUfsB.mjs";import t from"node:path";import{fileURLToPath as n,pathToFileURL as r}from"node:url";import{readRootJsonObjectSync as i}from"@openclaw/fs-safe/json";const a=e(import.meta.url),o={npm:`npm-cli.js`,npx:`npx-cli.js`};resolveRuntimeProcessDistRoot(n(import.meta.url));function resolveRuntimeProcessDistRoot(e){let n=e.replaceAll(t.sep,`/`).lastIndexOf(`/dist/`);return n>=0?e.slice(0,n+6):void 0}function resolveRuntimeDependencyEntrypointUrlFromDirectory(e,n){return r(t.join(n,o[e]))}const s=/^node(?:-\d+|\d+)(?:\.\d+)*(?:\.exe)?$/;function normalizeRuntimeBasename(e){let t=e.trim().replace(/^["']|["']$/g,``),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return(n===-1?t:t.slice(n+1)).trim().toLowerCase()}function isNodeRuntime(e){let t=normalizeRuntimeBasename(e);return/^node(?:js)?(?:\.exe)?$/.test(t)||s.test(t)}function isBunRuntime(e){let t=normalizeRuntimeBasename(e);return t===`bun`||t===`bun.exe`}const c=/* @__PURE__ */ new Set([`-r`,`--preload`,`--require`,`--import`,`--loader`,`--experimental-loader`,`--test-reporter`,`--test-global-setup`]),l=/* @__PURE__ */ new Set([...c,`-C`,`--env-file`,`--env-file-if-exists`,`--tsconfig`,`--cwd`,`--conditions`,`--icu-data-dir`,`--openssl-config`,`--title`,`--disable-warning`,`--disable-proto`,`--cpu-prof-name`,`--max-old-space-size`,`--max-semi-space-size`]),u=/* @__PURE__ */ new Set([`--inspect`,`--inspect-brk`,`--inspect-wait`,`--expose-gc`,`--jitless`,`--no-opt`,`--experimental-strip-types`,`--watch`,`--no-warnings`,`--trace-uncaught`,`--bun`]);function resolveRuntimeScriptPosition(e){let t=[],n=e[0]??``,r=n.replaceAll(`\\`,`/`).trim().toLowerCase().split(`/`).at(-1),i=isBunRuntime(n),a=r===`tsx`||r===`tsx.cmd`,o=i?`run`:a?`watch`:void 0,s,d=[];if(!isNodeRuntime(n)&&!i&&!a)return{position:{kind:`not-runtime`},operands:t,sourceIndices:d};for(let n=1;n<e.length;n++){let r=e[n];if(r===`--`){if(!s)return{position:d.length===0&&e[n+1]?n+1:{kind:`other`},operands:t,sourceIndices:d};t.push(...e.slice(n+1).map(e=>({value:e,module:!1})));break}if(r===`-e`||r===`-p`||/^--(?:eval|print|run)(?:=|$)/.test(r)){r.includes(`=`)||n++,d.push(n);continue}let a=r.indexOf(`=`),f=a<0?r:r.slice(0,a);if(r.startsWith(`-r`)&&!r.startsWith(`--`)&&r.length>2)t.push({value:r.slice(2),module:!0});else if(l.has(f)){let o=a<0?e[++n]??``:r.slice(a+1),s=!i&&f===`--test-reporter`&&/^(?:dot|spec|tap)$/.test(o);c.has(f)&&!s&&(!i||f!==`--loader`)&&t.push({value:o,module:!0})}else if(r.startsWith(`-`)){let e=`--no-${f.replace(/^--(?:no-)?/,``)}`,n=!i&&process.allowedNodeEnvironmentFlags.has(f),o=u.has(f)||i&&(f===`--hot`||f===`--no-install`)||n&&process.allowedNodeEnvironmentFlags.has(e);d.length===0&&!o&&!/^--[^=]+=/.test(r)&&(s??={kind:`unclassified`,reason:`unsupported runtime option ${r}`}),a>=0&&!o&&!n&&t.push({value:r.slice(a+1),module:!0})}else if(d.length===0&&r===o)o=void 0;else if(d.length===0){if(!s)return{position:n,operands:t,sourceIndices:d};o=void 0,t.push({value:r,module:!1})}else break}return{position:s??{kind:`other`},operands:t,sourceIndices:s?[]:d}}function resolveRuntimeWorkerUrl(e){if(e.root!==void 0)return r(t.join(e.root,`dist`,e.distWorkerPath));let a=n(e.currentModuleUrl),o=resolveRuntimeProcessDistRoot(a);if(o!==void 0){let n=e.distWorkerPath;if(e.package){let r=t.resolve(o,`..`),a=i({rootDir:r,relativePath:`package.json`,boundaryLabel:`runtime worker package`,rejectHardlinks:!1});if(!a.ok)throw Error(`Cannot resolve runtime worker package: ${r}/package.json`);a.value.name===e.package.name&&(n=e.package.distWorkerPath)}return r(t.join(o,n))}let s=e.sourceExtension??(t.extname(a)||`.js`);return new URL(`./${e.sourceWorkerName}${s}`,e.currentModuleUrl)}function isBunTargetRuntime(e){return e===process.execPath?!!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){let r=n(e);return runtimeNeedsTypeScriptLoader(r,t)?[`--import`,import.meta.resolve(`tsx`),r]:[...resolveRuntimeArgs(t),r]}function resolveRuntimeWorkerThreadExecArgv(e,t=process.execPath){return e.protocol===`file:`&&runtimeNeedsTypeScriptLoader(n(e),t)?[`--import`,import.meta.resolve(`tsx/esm`)]:[]}export{isBunRuntime as a,resolveRuntimeDependencyEntrypointUrlFromDirectory as c,runtimeNeedsTypeScriptLoader as i,a as l,resolveRuntimeWorkerThreadExecArgv as n,isNodeRuntime as o,resolveRuntimeWorkerUrl as r,resolveRuntimeScriptPosition as s,resolveRuntimeWorkerArgv as t};