import{readFileSync as e,rmSync as t}from"node:fs";import i from"node:process";import{resolve as h}from"node:path";import s from"../../../../_virtual/index7.mjs";import o from"../../../file-entry-cache/dist/index.mjs";import{DEFAULT_CACHE_LOCATION as r,DEFAULT_CACHE_STRATEGY as a,CACHE_STRATEGY_METADATA as c,CACHE_STRATEGY_CONTENT as f}from"../constants.mjs";import n from"./hash.mjs";import l from"./resolveFilePath.mjs";const m=s("stylelint:file-cache"),C=JSON.parse(e(new URL("../../package.json",import.meta.url),"utf8"));class d{constructor(e=r,s=a,C=i.cwd()){if(![c,f].includes(s))throw new Error(`"${s}" cache strategy is unsupported. Specify either "${c}" or "${f}"`);const d=h(l(e,C,`.stylelintcache_${n(C)}`)),g=s===f;m(`Cache file is created at ${d}`);try{this._fileCache=o.createFromFile(d,{useCheckSum:g,cwd:void 0})}catch{m("Cache file might be corrupt, attempting to remove and recreate the cache file"),t(d,{force:!0}),this._fileCache=o.createFromFile(d,{useCheckSum:g,cwd:void 0})}this._hashOfConfig="",this._useCheckSum=g}calcHashOfConfig(e){if(this._hashOfConfig)return;const t=C.version,i=JSON.stringify(e||{});this._hashOfConfig=n(`${t}_${i}`)}hasFileChanged(e){const t=this._fileCache.cache.getKey(this._fileCache.createFileKey(e)),i=this._fileCache.getFileDescriptor(e),h=i.meta.data??={},s=h.hashOfConfig!==this._hashOfConfig;let o;return o=this._useCheckSum?s||!t?.hash||t.hash!==i.meta.hash:s||Boolean(i.changed),o||m(`Skip linting ${e}. File hasn't changed.`),h.hashOfConfig!==this._hashOfConfig&&(h.hashOfConfig=this._hashOfConfig),o}reconcile(){this._fileCache.reconcile()}destroy(){this._fileCache.destroy()}removeEntry(e){this._fileCache.removeEntry(e)}}export{d as default};