import n from"path";import{simpleGit as r}from"simple-git";import{statSync as h}from"node:fs";import{envConfig as o}from"../config/env-config.js";import{fastMtime as a}from"./fast-mtime.js";class p{fs;#e;#i=void 0;#t=null;#s=new Map;#n=".";constructor(t){this.fs=t,t.watch(i=>{for(const e of i)e.event!=="code-updated"&&(e.event==="unlink"?this.#s.delete(e.path):this.#s.set(e.path,new Date().toISOString()))})}#o(){return this.#e?this.#e:(this.#e=new Promise(t=>{const i=r(this.fs.cwd,{binary:"git"});i.version().then(e=>{e.installed||t(void 0),i.revparse(["--show-toplevel"]).then(s=>{this.#n=s,t(i)}).catch(()=>{t(void 0)})})}),this.#e)}async#h(){return this.#i||(this.#i=this.#o().then(t=>{if(t)return a(this.fs.cwd,t)})),this.#i}async#a(){return this.#t||(this.#t=this.#o().then(async t=>{if(!t)return new Set;try{const i=!o.isDevelopMode,e=await t?.status(i?["--untracked-files=no"]:void 0);return new Set(e?.files.map(s=>n.posix.normalize(n.relative(this.fs.cwd,n.resolve(this.#n,s.path))))??[])}catch{return new Set}}),this.#t.then(()=>{o.isDevelopMode&&setTimeout(()=>{this.#t=null},5e3)})),this.#t}#r(t){return this.#s.get(t)||h(n.resolve(this.fs.cwd,t)).mtime.toISOString()}async getLastModified(t){const i=await this.#h(),e=await this.#a();try{if(e?.has(t))return this.#r(t);const s=i?.get(t);return s||this.#r(t)}catch{return null}}}export{p as LastModifiedTracker};
