eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.53 kB
JavaScript
import{cp,mkdir,symlink,writeFile}from"node:fs/promises";import{dirname,join}from"node:path";import{constants,existsSync}from"node:fs";import{DevelopmentRuntimeSourceSnapshotError,toDevelopmentSourceSnapshotPath}from"#internal/nitro/dev-runtime-source-snapshot.js";const SNAPSHOT_COPY_MODE=constants.COPYFILE_FICLONE;async function copyDevelopmentSourceSnapshot(e){await mkdir(e.snapshotSourceRoot,{recursive:!0});for(let t of e.copyFiles){if(!existsSync(t))continue;let n=toSnapshotPathForPlan(e,t);try{await mkdir(dirname(n),{recursive:!0}),await cp(t,n,{mode:SNAPSHOT_COPY_MODE,recursive:!0})}catch(e){throw new DevelopmentRuntimeSourceSnapshotError(`Failed to copy development runtime source snapshot path "${t}" to "${n}": ${formatErrorMessage(e)}`)}}await createSnapshotDependencyMounts(e),await ensureRuntimePackageJson(e)}async function createSnapshotDependencyMounts(e){for(let t of e.dependencyMounts){let n=toSnapshotPathForPlan(e,t.mountPath);await mkdir(dirname(n),{recursive:!0}),await symlink(t.sourcePath,n,`junction`)}}async function ensureRuntimePackageJson(e){let t=join(e.runtimeAppRoot,`package.json`);existsSync(t)||(await mkdir(e.runtimeAppRoot,{recursive:!0}),await writeFile(t,`${JSON.stringify({private:!0,type:`module`},null,2)}\n`))}function toSnapshotPathForPlan(e,t){return toDevelopmentSourceSnapshotPath({snapshotSourceRoot:e.snapshotSourceRoot,sourcePath:t,sourceRoot:e.sourceRoot})}function formatErrorMessage(e){return e instanceof Error?e.message:String(e)}export{copyDevelopmentSourceSnapshot};