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