import p from"node:path";import{I18N_DIR_NAME as f,L10N_DIR_NAME as d}from"../constants/common.js";import{logger as u}from"../tools/notifiers/logger.js";import{Fs as m}from"./fs.js";import{isL10nPath as n}from"./utils/is-l10n-path.js";import{getLocaleFromRelativePath as c}from"./utils/get-locale-from-relative-path.js";import{removeL10nPrefix as l}from"./utils/remove-l10n-prefix.js";import{LastModifiedTracker as F}from"./last-modified-tracker.js";class R extends m{cwd;ignored;#e=new Map;#s;#t;constructor(e,t=[]){super(e,t),this.cwd=e,this.ignored=t,this.#s=new F(this),this.#r()}get localeFolders(){return Array.from(this.#e.keys())}get localizationFolder(){if(this.#t)return this.#t;let e=!1,t=!1;const s=this.localeFolders;if(!s.length)return;for(const i of s)for(const o of this.#e.get(i)?.values()||[]){const a=o.startsWith(d),h=o.startsWith(f);a&&!e&&(e=!0),h&&!t&&(t=!0)}e&&t?u.warn("Detected both `@l10n` and `@i18n` folders. Using `@l10n` folder for localization because `@i18n` folder is deprecated."):t&&u.warn("`@i18n` folder is deprecated. Please use `@l10n` folder instead.");const r=e?d:f;return this.#t=r,r}getFileInfo(e){if(e=e.replace(/^\.\//g,""),n(e)){if(super.exists(e))return super.getFileInfo(e);const t=l(e),s=super.getFileInfo(t);return s&&{...s,relativePath:e,realRelativePath:t,dirname:p.posix.dirname(e),isVirtual:!0}}return super.getFileInfo(e)}exists(e){return e=e.replace(/^\.\//g,""),n(e)?super.exists(e)||super.exists(l(e)):super.exists(e)}async read(e,t="utf-8"){return n(e)?await super.exists(e)?super.read(e,t):super.read(l(e),t):super.read(e,t)}scan(e){const t=super.scan(e),s={},r=new Set;for(const i of t)if(n(i.relativePath)){const o=c(i.relativePath),a=s[o]||new Set;a.add(l(i.relativePath)),s[o]=a}else r.add(i.relativePath);for(const i of r.values())for(const o of this.#e.keys())if(!s[o]?.has(i)){const a=`${this.localizationFolder}/${o}/${i}`;t.push({realRelativePath:i,relativePath:a,isVirtual:!0,hash:void 0})}return t}getLastModified(e){const t=this.getFileInfo(e);return this.#s.getLastModified(t?.realRelativePath||e)}async#r(){await this.watcher,this.#e=new Map;for(const e of this.filesList.values())if(n(e.relativePath)){const t=c(e.relativePath),s=this.#e.get(t)||new Set;s.add(e.relativePath),this.#e.set(t,s)}super.watch(async e=>{for(const t of e){if(t.event==="code-updated"||!n(t.path))continue;const s=c(t.path),r=this.#e.get(s)||new Set;switch(t.event){case"add":r.add(t.path),this.#e.set(s,r);break;case"unlink":r&&(r.delete(t.path),r.size===0&&this.#e.delete(s));break}}})}}export{R as ContentFs};
