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