openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.63 kB
JavaScript
const e=/^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(t){let n=normalizeRuntimeBasename(t);return/^node(?:js)?(?:\.exe)?$/.test(n)||e.test(n)}function isBunRuntime(e){let t=normalizeRuntimeBasename(e);return t===`bun`||t===`bun.exe`}const t=/* @__PURE__ */ new Set([`-r`,`--preload`,`--require`,`--import`,`--loader`,`--experimental-loader`,`--test-reporter`,`--test-global-setup`]),n=/* @__PURE__ */ new Set([...t,`-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`]),r=/* @__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 i=[],a=e[0]??``,o=a.replaceAll(`\\`,`/`).trim().toLowerCase().split(`/`).at(-1),s=isBunRuntime(a),c=o===`tsx`||o===`tsx.cmd`,l=s?`run`:c?`watch`:void 0,u,d=[];if(!isNodeRuntime(a)&&!s&&!c)return{position:{kind:`not-runtime`},operands:i,sourceIndices:d};for(let a=1;a<e.length;a++){let o=e[a];if(o===`--`){if(!u)return{position:d.length===0&&e[a+1]?a+1:{kind:`other`},operands:i,sourceIndices:d};i.push(...e.slice(a+1).map(e=>({value:e,module:!1})));break}if(o===`-e`||o===`-p`||/^--(?:eval|print|run)(?:=|$)/.test(o)){o.includes(`=`)||a++,d.push(a);continue}let c=o.indexOf(`=`),f=c<0?o:o.slice(0,c);if(o.startsWith(`-r`)&&!o.startsWith(`--`)&&o.length>2)i.push({value:o.slice(2),module:!0});else if(n.has(f)){let n=c<0?e[++a]??``:o.slice(c+1),r=!s&&f===`--test-reporter`&&/^(?:dot|spec|tap)$/.test(n);!t.has(f)||r||s&&f===`--loader`||i.push({value:n,module:!0})}else if(o.startsWith(`-`)){let e=`--no-${f.replace(/^--(?:no-)?/,``)}`,t=!s&&process.allowedNodeEnvironmentFlags.has(f),n=r.has(f)||s&&(f===`--hot`||f===`--no-install`)||t&&process.allowedNodeEnvironmentFlags.has(e);d.length===0&&!n&&!/^--[^=]+=/.test(o)&&(u??={kind:`unclassified`,reason:`unsupported runtime option ${o}`}),c>=0&&!n&&!t&&i.push({value:o.slice(c+1),module:!0})}else if(d.length===0&&o===l)l=void 0;else if(d.length===0){if(!u)return{position:a,operands:i,sourceIndices:d};l=void 0,i.push({value:o,module:!1})}else break}return{position:u??{kind:`other`},operands:i,sourceIndices:u?[]:d}}export{isNodeRuntime as n,resolveRuntimeScriptPosition as r,isBunRuntime as t};