"use strict";var R=require("node:worker_threads"),d=require("../node-features-CKvB621_.cjs"),N=require("../register-BIOvi1NN.cjs"),c=require("../resolve-ts-path-VlOGJlUT.cjs"),h=require("node:url"),P=require("../index-CL50QkGo.cjs"),_=require("../client-DjommMgI.cjs"),E=require("node:path"),T=require("node:fs");require("node:module"),require("get-tsconfig"),require("esbuild"),require("node:crypto"),require("node:os"),require("../temporary-directory-B83uKxJF.cjs"),require("node:net"),require("../get-pipe-path-b8D5AZgV.cjs");const p={active:!0},v=async e=>{if(!e)throw new Error(`tsx must be loaded with --import instead of --loader The --loader flag was deprecated in Node v20.6.0 and v18.19.0`);p.namespace=e.namespace,e.tsconfig!==!1&&c.loadTsconfig(e.tsconfig??process.env.TSX_TSCONFIG_PATH),e.port&&(p.port=e.port,e.port.on("message",t=>{t==="deactivate"&&(p.active=!1,e.port.postMessage({type:"deactivated"}))}))},F=()=>(c.loadTsconfig(process.env.TSX_TSCONFIG_PATH),"process.setSourceMapsEnabled(true);"),f=new Map,S=async e=>{if(f.has(e))return f.get(e);if(!await T.promises.access(e).then(()=>!0,()=>!1)){f.set(e,void 0);return}const r=await T.promises.readFile(e,"utf8");try{const s=JSON.parse(r);return f.set(e,s),s}catch{throw new Error(`Error parsing: ${e}`)}},M=async e=>{let t=new URL("package.json",e);for(;!t.pathname.endsWith("/node_modules/package.json");){const r=h.fileURLToPath(t),s=await S(r);if(s)return s;const o=t;if(t=new URL("../package.json",t),t.pathname===o.pathname)break}},U=async e=>(await M(e))?.type??"commonjs",j=e=>{const t=e.indexOf("?");e=t===-1?e:e.slice(0,t);const r=E.extname(e);if(r===".json")return"json";if(r===".mjs"||r===".mts")return"module";if(r===".cjs"||r===".cts")return"commonjs"},D=e=>{const t=j(e);if(t)return t;if(c.tsExtensionsPattern.test(e))return U(e)},m="tsx-namespace=",g=e=>{const t=e.indexOf(m);if(t===-1)return;const r=e[t-1];if(r!=="?"&&r!=="&")return;const s=t+m.length,o=e.indexOf("&",s);return o===-1?e.slice(s):e.slice(s,o)},l=d.isFeatureSupported(d.importAttributes)?"importAttributes":"importAssertions",J=async(e,t,r)=>{if(!p.active||p.namespace&&p.namespace!==g(e))return r(e,t);if(p.port){const n=new URL(e);n.searchParams.delete("tsx-namespace"),p.port.postMessage({type:"load",url:n.toString()})}_.parent.send&&_.parent.send({type:"dependency",path:e}),c.isJsonPattern.test(e)&&(t[l]||(t[l]={}),t[l].type="json");const s=await r(e,t);if(!s.source)return s;const o=e.startsWith("file://")?h.fileURLToPath(e):e,a=s.source.toString();if(s.format==="json"||c.tsExtensionsPattern.test(e)){const n=await P.transform(a,o,{tsconfigRaw:c.fileMatcher?.(o)});return{format:"module",source:c.inlineSourceMap(n)}}if(s.format==="module"){const n=P.transformDynamicImport(o,a);n&&(s.source=c.inlineSourceMap(n))}return s},y=async e=>(!e.format&&e.url.startsWith(c.fileUrlPrefix)&&(e.format=await D(e.url)),e),A=[".js",".json",".ts",".tsx",".jsx"],w=async(e,t,r)=>{const[s,o]=e.split("?");let a;for(const n of A)try{return await y(await r(s+n+(o?`?${o}`:""),t))}catch(i){if(a===void 0&&i instanceof Error){const{message:u}=i;i.message=i.message.replace(`${n}'`,"'"),i.stack=i.stack.replace(u,i.message),a=i}}throw a},q=async(e,t,r)=>{const s=c.isDirectoryPattern.test(e),o=s?"index":"/index",[a,n]=e.split("?");try{return await w(a+o+(n?`?${n}`:""),t,r)}catch(i){if(!s)try{return await w(e,t,r)}catch{}const u=i,{message:O}=u;throw u.message=u.message.replace(`${o.replace("/",E.sep)}'`,"'"),u.stack=u.stack.replace(O,u.message),u}},k=async(e,t,r,s)=>{if(!p.active)return r(e,t);const o=t.parentURL&&g(t.parentURL);if(c.requestAcceptsQuery(e)){let a=g(e);if(o&&!a&&(a=o,e+=`${e.includes("?")?"&":"?"}${m}${o}`),p.namespace&&p.namespace!==a)return r(e,t);if(c.isDirectoryPattern.test(e))return await q(e,t,r)}else if(c.tsconfigPathsMatcher&&!t.parentURL?.includes("/node_modules/")){const a=c.tsconfigPathsMatcher(e);for(const n of a)try{return await k(h.pathToFileURL(n).toString(),t,r)}catch{}}if(c.tsExtensionsPattern.test(t.parentURL)||c.allowJs){const a=c.resolveTsPath(e);if(a)for(const n of a)try{return await y(await r(n,t))}catch(i){const{code:u}=i;if(u!=="ERR_MODULE_NOT_FOUND"&&u!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw i}}try{const a=await y(await r(e,t));if(c.requestAcceptsQuery(a.url)){const n=g(a.url);o&&!n&&(a.url+=`${a.url.includes("?")?"&":"?"}${m}${o}`)}return a}catch(a){if(a instanceof Error&&!s){const{code:n}=a;if(n==="ERR_UNSUPPORTED_DIR_IMPORT")try{return await q(e,t,r)}catch(i){if(i.code!=="ERR_PACKAGE_IMPORT_NOT_DEFINED")throw i}if(n==="ERR_MODULE_NOT_FOUND")try{return await w(e,t,r)}catch{}}throw a}};d.isFeatureSupported(d.moduleRegister)&&R.isMainThread&&N.register(),exports.globalPreload=F,exports.initialize=v,exports.load=J,exports.resolve=k;