openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.23 kB
JavaScript
import{t as e}from"./git-operation.worker-map-size-CypexNQj.mjs";import{d as t,t as n}from"./git-operation.worker-home-dir-DUQkhCrS.mjs";import{r}from"./git-operation.worker-process-env-DgVwfN3Y.mjs";import i from"node:fs";import"node:fs/promises";import a from"node:path";import{safeStatSync as o}from"@openclaw/fs-safe/path";function resolveExecutablePathCandidate(e,t){let r=e.startsWith(`~`)?n(e,{env:t?.env}):e;if(process.platform===`win32`&&/^:[\\/]/.test(r))return;let i=r.includes(`/`)||r.includes(`\\`);if(t?.requirePathSeparator&&!i)return;if(!i)return r;if(a.isAbsolute(r))return a.resolve(r);let o=t?.cwd&&t.cwd.trim()?t.cwd:process.cwd();return a.resolve(o,r)}function resolveWindowsExecutableExtensions(e,t,n=!0){if(process.platform!==`win32`||a.extname(e).length>0)return[``];let r=[...resolveWindowsExecutableExtSet(t)];return n?[``,...r]:r}function resolveWindowsExecutableExtSet(e){return new Set((r(e,`PATHEXT`)??r(process.env,`PATHEXT`)??`.EXE;.CMD;.BAT;.COM`).split(`;`).map(e=>t(e)).filter(Boolean))}function isRegularFile(e){return o(e)?.isFile()??!1}const s=/* @__PURE__ */ new Set([`.com`,`.exe`,`.bat`,`.cmd`]);function isWindowsExecutable(e,n){let r=t(a.extname(e));return!r||s.has(r)||resolveWindowsExecutableExtSet(n).has(r)}function isExecutableFile(e,t){if(!isRegularFile(e))return!1;try{return process.platform===`win32`?isWindowsExecutable(e,t?.env):(i.accessSync(e,i.constants.X_OK),!0)}catch{return!1}}const c=6e4;let l=/* @__PURE__ */ new Map;function cacheExecutablePath(t,n,r){t.set(n,{expiresAt:Date.now()+c,resolved:r??null}),e(t,128)}function*executablePathProbes(e,t,n,i){let o=l,s=i?.cwd?.trim()?a.resolve(i.cwd):void 0,u=i?.useCache!==!1,d=r(n,`PATHEXT`)??r(process.env,`PATHEXT`)??``,f=``;try{f=s??process.cwd()}catch{}let p=`${process.platform}\0${e}\0${JSON.stringify(t)}\0${d}\0${i?.includeExtensionless!==!1}\0${f}\0${s!==void 0}`,m=u?o.get(p):void 0,h=Date.now();if(m&&m.expiresAt>h)return m.expiresAt=h+c,o.delete(p),o.set(p,m),m.resolved??void 0;m&&o.delete(p);let g=process.platform===`win32`?`;`:a.delimiter,_=(typeof t==`string`?t.split(g):t).filter(e=>!!e||s!==void 0&&process.platform!==`win32`),v=resolveWindowsExecutableExtensions(e,n,i?.includeExtensionless);for(let t of _){let n=process.platform!==`win32`&&t.split(`/`).includes(`..`),r=s!==void 0&&!a.isAbsolute(t)?`${s}${a.sep}${t}`:t;for(let i of v){let c=n?`${r}${a.sep}${e}${i}`:a.join(s===void 0?t:a.resolve(s,t),e+i);if(yield c)return u&&cacheExecutablePath(o,p,c),c}}u&&cacheExecutablePath(o,p,void 0)}function resolveExecutableFromPathEnv(...e){let t=executablePathProbes(...e),n=t.next();for(;!n.done;)n=t.next(isExecutableFile(n.value,{env:e[2]}));return n.value}function*executableCandidateProbes(e,t){let n=resolveExecutablePathCandidate(e,t);if(n)return n.includes(`/`)||n.includes(`\\`)?(yield n)?n:void 0:yield*executablePathProbes(n,r(t?.env,`PATH`)??r(process.env,`PATH`)??``,t?.env,{cwd:t?.cwd,useCache:t?.useCache})}function resolveExecutablePath(...e){let t=executableCandidateProbes(...e),n=t.next();for(;!n.done;)n=t.next(isExecutableFile(n.value,e[1]));return n.value}export{resolveExecutablePathCandidate as i,resolveExecutableFromPathEnv as n,resolveExecutablePath as r,isRegularFile as t};