import{join,resolve}from"node:path";import{existsSync,readFileSync,readdirSync,rmSync}from"node:fs";import{resolveInstalledPackageInfo,resolvePackageRoot,resolvePackageSourceDirectoryPath}from"#internal/application/package.js";import{createHash}from"node:crypto";import{workflowEntryReference}from"#execution/workflow-runtime.js";function resolveApplicationRoot(e=process.cwd()){return resolve(e)}function getWorkflowBuildCacheKey(e){return createHash(`sha256`).update(e).digest(`hex`).slice(0,12)}function isVercelBuildEnvironment(){return!!process.env.VERCEL}function resolveNitroBuildDirectory(t,n=`all`){let r=join(t,`.eve`,`nitro`);return n===`all`?r:join(r,n)}function resolveNitroSurfaceOutputDirectory(t,n){return join(t,`.eve`,`nitro-output`,n)}function resolveWorkflowBuildDirectory(t){let n=join(resolvePackageRoot(),`.eve`,`workflow-cache`);return pruneStaleWorkflowCacheSiblings(n),join(n,getWorkflowBuildCacheKey(t))}function pruneStaleWorkflowCacheSiblings(t){if(!existsSync(t))return;let o=resolveInstalledPackageInfo().version,s;try{s=readdirSync(t)}catch{return}for(let i of s){let a=join(t,i),s=join(a,`eve-cache.json`);if(existsSync(s))try{let e=JSON.parse(readFileSync(s,`utf8`));typeof e.eveVersion==`string`&&e.eveVersion!==o&&rmSync(a,{force:!0,recursive:!0})}catch{}}}function resolveSandboxCacheDirectory(t){return join(t,`.eve`,`sandbox-cache`)}function resolveOutputDirectory(t){return isVercelBuildEnvironment()?join(t,`.vercel`,`output`):join(t,`.output`)}function getApplicationInfo(e){return{appRoot:e,outputDir:resolveOutputDirectory(e),workflowId:workflowEntryReference.workflowId,workflowBuildDir:resolveWorkflowBuildDirectory(e),workflowSourceDir:resolvePackageSourceDirectoryPath(`src/execution`)}}export{getApplicationInfo,resolveApplicationRoot,resolveNitroBuildDirectory,resolveNitroSurfaceOutputDirectory,resolveOutputDirectory,resolveSandboxCacheDirectory,resolveWorkflowBuildDirectory};