/* Socket Lib - Built with esbuild */
var k=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var $=(e,o)=>{for(var t in o)k(e,t,{get:o[t],enumerable:!0})},E=(e,o,t,f)=>{if(o&&typeof o=="object"||typeof o=="function")for(let p of q(o))!W.call(e,p)&&p!==t&&k(e,p,{get:()=>o[p],enumerable:!(f=R(o,p))||f.enumerable});return e};var D=e=>E(k({},"__esModule",{value:!0}),e);var F={};$(F,{isolatePackage:()=>C});module.exports=D(F);var a=require("node:fs"),S=require("#constants/platform"),u=require("../path"),w=require("./operations"),v=require("#lib/paths");let J;function N(){return J===void 0&&(J=require("node:path")),J}const j={dereference:!0,errorOnExist:!1,filter:e=>!e.includes("node_modules")&&!e.endsWith(".DS_Store"),force:!0,recursive:!0,...S.WIN32?{maxRetries:3,retryDelay:100}:{}};async function I(e){const o=N();return await a.promises.realpath(e).catch(()=>o.resolve(e))}async function z(e,o){const t=JSON.parse(await a.promises.readFile(e,"utf8"));return o?{...o,...t}:t}async function C(e,o){const t=N(),f={__proto__:null,...o},{imports:p,install:g,onPackageJson:P,sourcePath:O}=f;let r=O,i,m;if((0,u.isPath)(e)){const s=(0,u.trimLeadingDotSlash)(e),n=(0,u.isAbsolute)(s)?s:e;if(r=t.resolve(n),!(0,a.existsSync)(r))throw new Error(`Source path does not exist: ${r}`);const d=await(0,w.readPackageJson)(r,{normalize:!0});if(!d)throw new Error(`Could not read package.json from: ${r}`);i=d.name}else{const n=require("../external/npm-package-arg")(e);if(i=n.name,n.type==="directory"||n.type==="file"){if(r=n.fetchSpec,!r||!(0,a.existsSync)(r))throw new Error(`Source path does not exist: ${r}`);if(!i){const d=await(0,w.readPackageJson)(r,{normalize:!0});if(!d)throw new Error(`Could not read package.json from: ${r}`);i=d.name}}else m=n.fetchSpec||n.rawSpec}if(!i)throw new Error(`Could not determine package name from: ${e}`);const y=i.replace(/[@/]/g,"-"),x=await a.promises.mkdtemp(t.join((0,v.getOsTmpDir)(),`socket-test-${y}-`)),l=t.join(x,y);await a.promises.mkdir(l,{recursive:!0});let c,h;if(m){if(await a.promises.writeFile(t.join(l,"package.json"),JSON.stringify({name:"test-temp",private:!0,version:"1.0.0"},null,2)),g)await g(l);else{const{spawn:s}=require("../spawn"),n=require("../constants/platform").WIN32,d=m.startsWith("https://")?m:`${i}@${m}`;await s("pnpm",["add",d],{cwd:l,shell:n,stdio:"pipe"})}if(c=t.join(l,"node_modules",i),h=await(0,w.readPackageJson)(c,{normalize:!0}),r){const s=await I(c);await I(r)!==s&&await a.promises.cp(r,c,j)}}else{if(!r)throw new Error("sourcePath is required when no version spec provided");const s=i.startsWith("@")?t.join(l,"node_modules",i.split("/")[0]??""):t.join(l,"node_modules");await a.promises.mkdir(s,{recursive:!0}),c=t.join(l,"node_modules",i),await a.promises.cp(r,c,j)}if(P||h){const s=t.join(c,"package.json"),n=await z(s,h),d=P?await P(n):n;await a.promises.writeFile(s,JSON.stringify(d,null,2))}if(g)await g(c);else{const{spawn:s}=require("../spawn"),n=require("../constants/platform").WIN32;await s("pnpm",["install"],{cwd:c,shell:n,stdio:"pipe"})}const _=p?{__proto__:null}:void 0;if(p)for(const{0:s,1:n}of Object.entries(p)){const d=t.join(c,n);_[s]=require(d)}return{exports:_,tmpdir:c}}0&&(module.exports={isolatePackage});
//# sourceMappingURL=isolation.js.map
