import{LRUCache as h}from"lru-cache";import t from"node:fs";import a from"node:path";import m from"node:os";import{shutdowner as l}from"../tools/shutdowner.js";import{PORTAL_VERSION as o}from"../version.js";const r=".cache/babel-plugin",s=t.existsSync("node_modules")?`node_modules/${r}`:a.join(m.tmpdir(),".redocly",r),i="styled-cache.json",C=5e3,p=15e3,n="_package-version";class _{#t;constructor(){this.#t=new h({max:C}),this.#s(),this.#i()}get(e){return this.#t.get(e)}set(e,c){this.#t.set(e,c)}#s(){if(!t.existsSync(`${s}/${i}`)){this.#t.load([]);return}const e=JSON.parse(t.readFileSync(`${s}/${i}`,"utf-8"));try{if(this.#t.load(e),this.#t.get(n)?.contents!==o)throw new Error("Cache version mismatch")}catch{this.#t.load([]),t.unlinkSync(`${s}/${i}`)}}#e(){t.existsSync(s)||t.mkdirSync(s,{recursive:!0}),this.#t.set(n,{contents:o||"",hash:""}),t.writeFileSync(`${s}/${i}`,JSON.stringify(this.#t.dump()),"utf-8")}#i(){process.on("SIGINT",()=>{this.#e(),l.exitWithCode(0)}),process.on("exit",()=>{this.#e()}),setInterval(()=>{this.#e()},p).unref()}}const y=new _;export{_ as BabelCache,y as babelCache};
