/* Socket Lib - Built with esbuild */
var F=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var B=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},q=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!$.call(n,o)&&o!==t&&F(n,o,{get:()=>e[o],enumerable:!(i=W(e,o))||i.enumerable});return n};var M=n=>q(F({},"__esModule",{value:!0}),n);var ue={};B(ue,{findUp:()=>V,findUpSync:()=>G,invalidatePathCache:()=>U,isDir:()=>z,isDirEmptySync:()=>j,isDirSync:()=>K,isSymLinkSync:()=>H,readDirNames:()=>X,readDirNamesSync:()=>Y,readFileBinary:()=>Z,readFileBinarySync:()=>ne,readFileUtf8:()=>ee,readFileUtf8Sync:()=>te,readJson:()=>ie,readJsonSync:()=>re,safeDelete:()=>oe,safeDeleteSync:()=>se,safeReadFile:()=>ae,safeReadFileSync:()=>ce,safeStats:()=>C,safeStatsSync:()=>I,uniqueSync:()=>de,validateFiles:()=>Q,writeJson:()=>fe,writeJsonSync:()=>le});module.exports=M(ue);var v=require("#constants/process"),m=require("./arrays"),S=require("./globs"),b=require("./json"),D=require("./objects"),p=require("./path"),E=require("./paths/rewire"),k=require("./sorts");const w=(0,v.getAbortSignal)(),L=(0,D.objectFreeze)({__proto__:null,force:!0,maxRetries:3,recursive:!0,retryDelay:200});let P;function l(){return P===void 0&&(P=require("node:fs")),P}let R;function _(){return R===void 0&&(R=require("node:path")),R}function J(n,e,t){const{ignore:i,includeEmpty:o=!0,sort:s=!0}={__proto__:null,...t},c=_(),a=n.filter(r=>r.isDirectory()&&(o||!j(c.join(e||r.parentPath,r.name),{ignore:i}))).map(r=>r.name);return s?a.sort(k.naturalCompare):a}function A(n,e,t,i,o=2){const s=t?e:"";return`${JSON.stringify(n,i,o).replace(/\n/g,e)}${s}`}async function V(n,e){const{cwd:t=process.cwd(),signal:i=w}={__proto__:null,...e};let{onlyDirectories:o=!1,onlyFiles:s=!0}={__proto__:null,...e};o&&(s=!1),s&&(o=!1);const c=l(),a=_();let r=a.resolve(t);const{root:d}=a.parse(r),f=(0,m.isArray)(n)?n:[n];for(;r&&r!==d;){for(const y of f){if(i?.aborted)return;const u=a.join(r,y);try{const g=await c.promises.stat(u);if(!o&&g.isFile())return(0,p.normalizePath)(u);if(!s&&g.isDirectory())return(0,p.normalizePath)(u)}catch{}}r=a.dirname(r)}}function G(n,e){const{cwd:t=process.cwd(),stopAt:i}={__proto__:null,...e};let{onlyDirectories:o=!1,onlyFiles:s=!0}={__proto__:null,...e};o&&(s=!1),s&&(o=!1);const c=l(),a=_();let r=a.resolve(t);const{root:d}=a.parse(r),f=i?a.resolve(i):void 0,y=(0,m.isArray)(n)?n:[n];for(;r&&r!==d;){if(f&&r===f){for(const u of y){const g=a.join(r,u);try{const h=c.statSync(g);if(!o&&h.isFile())return(0,p.normalizePath)(g);if(!s&&h.isDirectory())return(0,p.normalizePath)(g)}catch{}}return}for(const u of y){const g=a.join(r,u);try{const h=c.statSync(g);if(!o&&h.isFile())return(0,p.normalizePath)(g);if(!s&&h.isDirectory())return(0,p.normalizePath)(g)}catch{}}r=a.dirname(r)}}async function z(n){return!!(await C(n))?.isDirectory()}function K(n){return!!I(n)?.isDirectory()}function j(n,e){const{ignore:t=S.defaultIgnore}={__proto__:null,...e},i=l();try{const o=i.readdirSync(n),{length:s}=o;if(s===0)return!0;const c=(0,S.getGlobMatcher)(t,{cwd:(0,p.pathLikeToString)(n)});let a=0;for(let r=0;r<s;r+=1){const d=o[r];d&&c(d)&&(a+=1)}return a===s}catch{return!1}}function H(n){const e=l();try{return e.lstatSync(n).isSymbolicLink()}catch{}return!1}function Q(n){const e=l(),t=[],i=[],{R_OK:o}=e.constants;for(const s of n)try{e.accessSync(s,o),t.push(s)}catch{i.push(s)}return{__proto__:null,validPaths:t,invalidPaths:i}}async function X(n,e){const t=l();try{return J(await t.promises.readdir(n,{__proto__:null,encoding:"utf8",withFileTypes:!0}),String(n),e)}catch{}return[]}function Y(n,e){const t=l();try{return J(t.readdirSync(n,{__proto__:null,encoding:"utf8",withFileTypes:!0}),String(n),e)}catch{}return[]}async function Z(n,e){const t=typeof e=="string"?{encoding:e}:e;return await l().promises.readFile(n,{signal:w,...t,encoding:null})}async function ee(n,e){const t=typeof e=="string"?{encoding:e}:e;return await l().promises.readFile(n,{signal:w,...t,encoding:"utf8"})}function ne(n,e){const t=typeof e=="string"?{encoding:e}:e;return l().readFileSync(n,{...t,encoding:null})}function te(n,e){const t=typeof e=="string"?{encoding:e}:e;return l().readFileSync(n,{...t,encoding:"utf8"})}async function ie(n,e){const t=typeof e=="string"?{encoding:e}:e,{reviver:i,throws:o,...s}={__proto__:null,...t},c=o===void 0||!!o,a=l();let r="";try{r=await a.promises.readFile(n,{__proto__:null,encoding:"utf8",...s})}catch(d){if(c){const f=d.code;throw f==="ENOENT"?new Error(`JSON file not found: ${n}
Ensure the file exists or create it with the expected structure.`,{cause:d}):f==="EACCES"||f==="EPERM"?new Error(`Permission denied reading JSON file: ${n}
Check file permissions or run with appropriate access.`,{cause:d}):d}return}return(0,b.jsonParse)(r,{filepath:String(n),reviver:i,throws:c})}function re(n,e){const t=typeof e=="string"?{encoding:e}:e,{reviver:i,throws:o,...s}={__proto__:null,...t},c=o===void 0||!!o,a=l();let r="";try{r=a.readFileSync(n,{__proto__:null,encoding:"utf8",...s})}catch(d){if(c){const f=d.code;throw f==="ENOENT"?new Error(`JSON file not found: ${n}
Ensure the file exists or create it with the expected structure.`,{cause:d}):f==="EACCES"||f==="EPERM"?new Error(`Permission denied reading JSON file: ${n}
Check file permissions or run with appropriate access.`,{cause:d}):d}return}return(0,b.jsonParse)(r,{filepath:String(n),reviver:i,throws:c})}let O;function N(){if(O===void 0){const n=_(),{getOsTmpDir:e,getSocketCacacheDir:t,getSocketUserDir:i}=require("#lib/paths");O=[n.resolve(e()),n.resolve(t()),n.resolve(i())]}return O}function U(){O=void 0}(0,E.registerCacheInvalidation)(U);async function oe(n,e){const t=require("./external/del"),{deleteAsync:i}=t,o={__proto__:null,...e},s=(0,m.isArray)(n)?n.map(p.pathLikeToString):[(0,p.pathLikeToString)(n)];let c=o.force!==!1;if(!c&&s.length>0){const a=_(),r=N();s.every(f=>{const y=a.resolve(f);for(const u of r){const g=y.startsWith(u+a.sep)||y===u,x=a.relative(u,y).startsWith("..");if(g&&!x)return!0}return!1})&&(c=!0)}await i(s,{concurrency:o.maxRetries||L.maxRetries,dryRun:!1,force:c,onlyFiles:!1})}function se(n,e){const t=require("./external/del"),{deleteSync:i}=t,o={__proto__:null,...e},s=(0,m.isArray)(n)?n.map(p.pathLikeToString):[(0,p.pathLikeToString)(n)];let c=o.force!==!1;if(!c&&s.length>0){const a=_(),r=N();s.every(f=>{const y=a.resolve(f);for(const u of r){const g=y.startsWith(u+a.sep)||y===u,x=a.relative(u,y).startsWith("..");if(g&&!x)return!0}return!1})&&(c=!0)}i(s,{concurrency:o.maxRetries||L.maxRetries,dryRun:!1,force:c,onlyFiles:!1})}async function ae(n,e){const t=typeof e=="string"?{encoding:e}:e,i=l();try{return await i.promises.readFile(n,{signal:w,...t})}catch{}}async function C(n){const e=l();try{return await e.promises.stat(n)}catch{}}function I(n,e){const t=typeof e=="string"?{encoding:e}:e,i=l();try{return i.statSync(n,{__proto__:null,throwIfNoEntry:!1,...t})}catch{}}function ce(n,e){const t=typeof e=="string"?{encoding:e}:e,i=l();try{return i.readFileSync(n,{__proto__:null,...t})}catch{}}function de(n){const e=l(),t=_(),i=String(n);if(!e.existsSync(i))return(0,p.normalizePath)(i);const o=t.dirname(i),s=t.extname(i),c=t.basename(i,s);let a=1,r;do r=t.join(o,`${c}-${a}${s}`),a++;while(e.existsSync(r));return(0,p.normalizePath)(r)}async function fe(n,e,t){const i=typeof t=="string"?{encoding:t}:t,{EOL:o,finalEOL:s,replacer:c,spaces:a,...r}={__proto__:null,...i},d=l(),f=A(e,o||`
`,s!==void 0?s:!0,c,a);await d.promises.writeFile(n,f,{encoding:"utf8",...r,__proto__:null})}function le(n,e,t){const i=typeof t=="string"?{encoding:t}:t,{EOL:o,finalEOL:s,replacer:c,spaces:a,...r}={__proto__:null,...i},d=l(),f=A(e,o||`
`,s!==void 0?s:!0,c,a);d.writeFileSync(n,f,{encoding:"utf8",...r,__proto__:null})}0&&(module.exports={findUp,findUpSync,invalidatePathCache,isDir,isDirEmptySync,isDirSync,isSymLinkSync,readDirNames,readDirNamesSync,readFileBinary,readFileBinarySync,readFileUtf8,readFileUtf8Sync,readJson,readJsonSync,safeDelete,safeDeleteSync,safeReadFile,safeReadFileSync,safeStats,safeStatsSync,uniqueSync,validateFiles,writeJson,writeJsonSync});
//# sourceMappingURL=fs.js.map
