UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.19 kB
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{n as resolveEffectiveHomeDir,r as resolveOsHomeDir,t as normalizeHomeDirValue}from"./home-dir-DrOv-SYd.mjs";import{n as tryProcessCwd}from"./safe-cwd-BRF56DNK.mjs";import path from"node:path";import os from"node:os"; //!src/infra/home-dir.ts function getUserPathBaseDirectory(){return resolveGlobalSingleton(Symbol.for(`openclaw.userPathBaseDirectory`),()=>{const{AsyncLocalStorage:e}=process.getBuiltinModule(`async_hooks`);return new e})}function withUserPathBaseDirectory(e,t){return e===void 0?t():getUserPathBaseDirectory().run(path.resolve(e),t)}function resolveRequiredHomeDir(e=process.env,t=os.homedir){const n=resolveEffectiveHomeDir(e,t)??tryProcessCwd();if(n)return path.resolve(n);throw new Error(`Unable to resolve an OpenClaw home: set OPENCLAW_HOME, HOME, or USERPROFILE, or run from an existing directory.`)}function resolveRequiredOsHomeDir(e=process.env,t=os.homedir){const n=resolveOsHomeDir(e,t)??tryProcessCwd();if(n)return path.resolve(n);throw new Error(`Unable to resolve an OS home: set HOME or USERPROFILE, or run from an existing directory.`)}function expandHomePrefix(e,t){if(!e.startsWith(`~`))return e;const n=normalizeHomeDirValue(t?.home)??resolveEffectiveHomeDir(t?.env??process.env,t?.homedir??os.homedir);if(!n)return e;return e.replace(/^~(?=$|[\\/])/,()=>n)}function resolveAgainstUserBase(e){const t=getUserPathBaseDirectory().getStore();return t?path.resolve(t,e):path.resolve(e)}function resolvePathWithHome(e,t,n,r=resolveAgainstUserBase){const i=e.trim();if(!i)return i;return r(i.startsWith(`~`)?expandHomePrefix(i,{home:n(t?.env??process.env,t?.homedir??os.homedir),env:t?.env,homedir:t?.homedir}):i)}function notADirectory(e){return Object.assign(/* @__PURE__ */ new Error(`ENOTDIR: not a directory, '${e}'`),{code:`ENOTDIR`,path:e})}function resolveFilesystemPath(e){if(process.platform===`win32`||!e.split(`/`).includes(`..`))return resolveAgainstUserBase(e);const t=path.isAbsolute(e)?e:`${getUserPathBaseDirectory().getStore()??process.cwd()}/${e}`;const n=process.getBuiltinModule(`fs`);const r=t.split(`/`);let i=`/`;for(const e of r)if(e===`..`){const e=n.lstatSync(i).isSymbolicLink()?n.realpathSync(i):i;if(!n.statSync(e).isDirectory())throw notADirectory(e);i=path.dirname(e)}else if(e!==``&&e!==`.`)i=path.join(i,e);const a=r.at(-1);if(a===``||a===`.`){const e=n.statSync(i,{throwIfNoEntry:false});if(e&&!e.isDirectory())throw notADirectory(i)}return i}function resolveHomeRelativePath(e,t){return resolvePathWithHome(e,t,resolveRequiredHomeDir)}function resolveUserPath(e,t=process.env,n=os.homedir){if(!e)return``;return resolveHomeRelativePath(e,{env:t,homedir:n})}function resolveUserFilesystemPath(e){if(!e)return``;return resolvePathWithHome(e,void 0,resolveRequiredHomeDir,resolveFilesystemPath)}function resolveOsHomeRelativePath(e,t){return resolvePathWithHome(e,t,resolveRequiredOsHomeDir)}export{resolveRequiredHomeDir as a,resolveUserPath as c,resolveOsHomeRelativePath as i,withUserPathBaseDirectory as l,resolveFilesystemPath as n,resolveRequiredOsHomeDir as o,resolveHomeRelativePath as r,resolveUserFilesystemPath as s,expandHomePrefix as t};