UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.42 kB
import path from"node:path";import fs from"node:fs/promises";import{assertCanonicalPathWithinBase,resolveSafeInstallDir,safeDirName,safePathSegmentHashed}from"@openclaw/fs-safe/advanced"; //!src/infra/install-safe-path.ts function unscopedPackageName(e){const t=e.trim();return t.slice(t.lastIndexOf(`/`)+1)}function packageNameMatchesId(e,t){const n=t.trim();if(!n)return false;const r=e.trim();if(!r)return false;return n===r||n===unscopedPackageName(r)}const INSTALL_BASE_CHANGED_ERROR_MESSAGE=`install base directory changed during install`;async function assertInstallBaseStable(e){if(!(await fs.stat(e.installBaseDir)).isDirectory())throw new Error(INSTALL_BASE_CHANGED_ERROR_MESSAGE);if(await fs.realpath(e.installBaseDir)!==e.expectedRealPath)throw new Error(INSTALL_BASE_CHANGED_ERROR_MESSAGE)}async function resolveInstallPublishTarget(e){const t=path.resolve(e.installBaseDir);const n=path.resolve(e.targetDir);const r=path.relative(t,n);if(!r||r===`..`||r.startsWith(`..${path.sep}`))throw new Error(`invalid install target path`);const i=await fs.realpath(e.installBaseDir);return{installBaseRealPath:i,canonicalTargetDir:path.join(i,r)}}export{resolveInstallPublishTarget as a,safePathSegmentHashed as c,packageNameMatchesId as i,unscopedPackageName as l,assertCanonicalPathWithinBase as n,resolveSafeInstallDir as o,assertInstallBaseStable as r,safeDirName as s,INSTALL_BASE_CHANGED_ERROR_MESSAGE as t};