UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.24 kB
import path from"node:path";import os from"node:os"; //!packages/normalization-core/src/home-dir.ts function normalizeHomeDirValue(e){const t=e?.trim();return t&&t!==`undefined`&&t!==`null`?t:void 0}function normalizeSafe(e){try{return normalizeHomeDirValue(e())}catch{return}}function resolveTermuxHome(e){const t=normalizeHomeDirValue(e.PREFIX);if(!t||!normalizeHomeDirValue(e.ANDROID_DATA))return;if(!/(?:^|\/)com\.termux\/files\/usr\/?$/u.test(t.replace(/\\/gu,`/`)))return;return path.resolve(t,`..`,`home`)}function resolveRawOsHomeDir(e,t){return normalizeHomeDirValue(e.HOME)??normalizeHomeDirValue(e.USERPROFILE)??resolveTermuxHome(e)??normalizeSafe(t)}function resolveOsHomeDir(e=process.env,t=os.homedir){const n=resolveRawOsHomeDir(e,t);return n?path.resolve(n):void 0}function resolveEffectiveHomeDir(e=process.env,t=os.homedir,n){const r=normalizeHomeDirValue(e.OPENCLAW_HOME);if(!r)return resolveOsHomeDir(e,t);if(r===`~`||r.startsWith(`~/`)||r.startsWith(`~\\`)){const i=resolveRawOsHomeDir(e,t);if(!i)return n?.preserveUnresolvedTilde?path.resolve(r):void 0;return path.resolve(r.replace(/^~(?=$|[\\/])/,()=>i))}return path.resolve(r)}export{resolveEffectiveHomeDir as n,resolveOsHomeDir as r,normalizeHomeDirValue as t};