import{join}from"node:path";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{mkdir,readFile,rm,writeFile}from"node:fs/promises";const EVE_CACHE_METADATA_FILE=`eve-cache.json`;async function prepareEveVersionedCacheDirectory(e){let n=await readEveCacheVersion(e),r=resolveInstalledPackageInfo().version;n!==null&&n===r||await rm(e,{force:!0,recursive:!0})}async function writeEveVersionedCacheMetadata(r){await mkdir(r,{recursive:!0}),await writeFile(join(r,EVE_CACHE_METADATA_FILE),`${JSON.stringify({eveVersion:resolveInstalledPackageInfo().version},null,2)}\n`)}async function readEveCacheVersion(t){try{let n=JSON.parse(await readFile(join(t,EVE_CACHE_METADATA_FILE),`utf8`));return typeof n.eveVersion==`string`?n.eveVersion:null}catch(e){return e instanceof Error&&`code`in e&&e.code,null}}export{prepareEveVersionedCacheDirectory,writeEveVersionedCacheMetadata};