/* Socket Lib - Built with esbuild */
var p=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var S=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0})},b=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of w(r))!E.call(e,n)&&n!==t&&p(e,n,{get:()=>r[n],enumerable:!(s=v(r,n))||s.enumerable});return e};var $=e=>b(p({},"__esModule",{value:!0}),e);var J={};S(J,{clearDlx:()=>j,clearDlxSync:()=>F,dlxDirExists:()=>M,dlxDirExistsAsync:()=>A,ensureDlxDir:()=>I,ensureDlxDirSync:()=>L,generateCacheKey:()=>C,getDlxInstalledPackageDir:()=>f,getDlxPackageDir:()=>l,getDlxPackageJsonPath:()=>T,getDlxPackageNodeModulesDir:()=>m,isDlxPackageInstalled:()=>_,isDlxPackageInstalledAsync:()=>q,isInSocketDlx:()=>X,listDlxPackages:()=>h,listDlxPackagesAsync:()=>D,removeDlxPackage:()=>P,removeDlxPackageSync:()=>k});module.exports=$(J);var x=require("node:crypto"),i=require("./fs"),c=require("./path"),o=require("./paths"),y=require("./promises");let g;function a(){return g===void 0&&(g=require("node:fs")),g}function C(e){return(0,x.createHash)("sha512").update(e).digest("hex").substring(0,16)}let d;function u(){return d===void 0&&(d=require("node:path")),d}async function j(){const e=await D();await(0,y.pEach)(e,r=>P(r))}function F(){const e=h();for(const r of e)k(r)}function M(){return a().existsSync((0,o.getSocketDlxDir)())}async function A(){const e=a();try{return await e.promises.access((0,o.getSocketDlxDir)()),!0}catch{return!1}}async function I(){await(0,i.safeMkdir)((0,o.getSocketDlxDir)(),{recursive:!0})}function L(){(0,i.safeMkdirSync)((0,o.getSocketDlxDir)(),{recursive:!0})}function f(e){return(0,c.normalizePath)(u().join(m(e),e))}function l(e){return(0,c.normalizePath)(u().join((0,o.getSocketDlxDir)(),e))}function T(e){return(0,c.normalizePath)(u().join(f(e),"package.json"))}function m(e){return(0,c.normalizePath)(u().join(l(e),"node_modules"))}function X(e){if(!e)return!1;const r=u(),t=(0,o.getSocketDlxDir)();return r.resolve(e).startsWith(t+r.sep)}function _(e){return a().existsSync(f(e))}async function q(e){const r=a();try{return await r.promises.access(f(e)),!0}catch{return!1}}function h(){try{return(0,i.readDirNamesSync)((0,o.getSocketDlxDir)(),{sort:!0})}catch{return[]}}async function D(){const e=a();try{return(await e.promises.readdir((0,o.getSocketDlxDir)(),{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort()}catch{return[]}}async function P(e){const r=l(e);try{await(0,i.safeDelete)(r,{recursive:!0,force:!0})}catch(t){throw new Error(`Failed to remove DLX package "${e}"`,{cause:t})}}function k(e){const r=a(),t=l(e);try{r.rmSync(t,{recursive:!0,force:!0})}catch(s){const n=s.code;throw n==="EACCES"||n==="EPERM"?new Error(`Permission denied removing DLX package "${e}"
Directory: ${t}
To resolve:
  1. Check file/directory permissions
  2. Close any programs using files in this directory
  3. Try running with elevated privileges if necessary
  4. Manually remove: rm -rf "${t}"`,{cause:s}):n==="EROFS"?new Error(`Cannot remove DLX package "${e}" from read-only filesystem
Directory: ${t}
The filesystem is mounted read-only.`,{cause:s}):new Error(`Failed to remove DLX package "${e}"
Directory: ${t}
Check permissions and ensure no programs are using this directory.`,{cause:s})}}0&&(module.exports={clearDlx,clearDlxSync,dlxDirExists,dlxDirExistsAsync,ensureDlxDir,ensureDlxDirSync,generateCacheKey,getDlxInstalledPackageDir,getDlxPackageDir,getDlxPackageJsonPath,getDlxPackageNodeModulesDir,isDlxPackageInstalled,isDlxPackageInstalledAsync,isInSocketDlx,listDlxPackages,listDlxPackagesAsync,removeDlxPackage,removeDlxPackageSync});
//# sourceMappingURL=dlx.js.map
