"use strict";var j=require("node:worker_threads"),d=require("../node-features-CKvB621_.cjs"),J=require("../register-DUq1clC8.cjs"),g=require("node:url"),v=require("../index-CLWE53E9.cjs"),f=require("../is-relative-path-pattern-Cr3_Gkbv.cjs"),k=require("../client-DjommMgI.cjs"),m=require("node:path"),h=require("get-tsconfig"),R=require("node:fs");require("node:module"),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},M=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.port&&(p.port=e.port,e.port.on("message",t=>{t==="deactivate"&&(p.active=!1,e.port.postMessage({type:"deactivated"}))}))},A=()=>"process.setSourceMapsEnabled(true);",l=new Map,D=async e=>{if(l.has(e))return l.get(e);if(!await R.promises.access(e).then(()=>!0,()=>!1)){l.set(e,void 0);return}const a=await R.promises.readFile(e,"utf8");try{const r=JSON.parse(a);return l.set(e,r),r}catch{throw new Error(`Error parsing: ${e}`)}},b=async e=>{let t=new URL("package.json",e);for(;!t.pathname.endsWith("/node_modules/package.json");){const a=g.fileURLToPath(t),r=await D(a);if(r)return r;const c=t;if(t=new URL("../package.json",t),t.pathname===c.pathname)break}},I=async e=>(await b(e))?.type??"commonjs",u=process.env.TSX_TSCONFIG_PATH?{path:m.resolve(process.env.TSX_TSCONFIG_PATH),config:h.parseTsconfig(process.env.TSX_TSCONFIG_PATH)}:h.getTsconfig(),$=u&&h.createFilesMatcher(u),q=u&&h.createPathsMatcher(u),L=u?.config.compilerOptions?.allowJs??!1,O="file://",w=/\.([cm]?ts|[tj]sx)($|\?)/,C=/\.json(?:$|\?)/,W=e=>{const t=m.extname(e);if(t===".json")return"json";if(t===".mjs"||t===".mts")return"module";if(t===".cjs"||t===".cts")return"commonjs"},G=e=>{const t=W(e);if(t)return t;if(w.test(e))return I(e)},y="tsx-namespace=",P=e=>{const t=e.indexOf(y);if(t===-1)return;const a=e[t-1];if(a!=="?"&&a!=="&")return;const r=t+y.length,c=e.indexOf("&",r);return c===-1?e.slice(r):e.slice(r,c)},_=d.isFeatureSupported(d.importAttributes)?"importAttributes":"importAssertions",H=async(e,t,a)=>{if(!p.active||p.namespace&&p.namespace!==P(e))return a(e,t);if(p.port){const s=new URL(e);s.searchParams.delete("tsx-namespace"),p.port.postMessage({type:"load",url:s.toString()})}k.parent.send&&k.parent.send({type:"dependency",path:e}),C.test(e)&&(t[_]||(t[_]={}),t[_].type="json");const r=await a(e,t);if(!r.source)return r;const c=e.startsWith("file://")?g.fileURLToPath(e):e,n=r.source.toString();if(r.format==="json"||w.test(e)){const s=await v.transform(n,c,{tsconfigRaw:$?.(c)});return{format:"module",source:f.inlineSourceMap(s)}}if(r.format==="module"){const s=v.transformDynamicImport(c,n);s&&(r.source=f.inlineSourceMap(s))}return r},S=/\/(?:$|\?)/,T=async(e,t,a)=>{const r=await e(t,a);return!r.format&&r.url.startsWith(O)&&(r.format=await G(r.url)),r},X=[".js",".json",".ts",".tsx",".jsx"],E=async(e,t,a)=>{const[r,c]=e.split("?");let n;for(const s of X)try{return await T(a,r+s+(c?`?${c}`:""),t)}catch(o){if(n===void 0&&o instanceof Error){const{message:i}=o;o.message=o.message.replace(`${s}'`,"'"),o.stack=o.stack.replace(i,o.message),n=o}}throw n},U=async(e,t,a)=>{const r=S.test(e),c=r?"index":"/index",[n,s]=e.split("?");try{return await E(n+c+(s?`?${s}`:""),t,a)}catch(o){if(!r)try{return await E(e,t,a)}catch{}const i=o,{message:N}=i;throw i.message=i.message.replace(`${c.replace("/",m.sep)}'`,"'"),i.stack=i.stack.replace(N,i.message),i}},F=async(e,t,a,r)=>{if(!p.active)return a(e,t);if(e.startsWith(O)||m.isAbsolute(e)||f.isRelativePathPattern.test(e)){let n=P(e);if(t.parentURL){const s=P(t.parentURL);s&&!n&&(n=s,e+=`${e.includes("?")?"&":"?"}${y}${s}`)}if(p.namespace&&p.namespace!==n)return a(e,t);if(S.test(e))return await U(e,t,a)}else if(q&&!t.parentURL?.includes("/node_modules/")){const n=q(e);for(const s of n)try{return await F(g.pathToFileURL(s).toString(),t,a)}catch{}}if(w.test(t.parentURL)||L){const n=f.resolveTsPath(e);if(n)for(const s of n)try{return await T(a,s,t)}catch(o){const{code:i}=o;if(i!=="ERR_MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw o}}try{return await T(a,e,t)}catch(n){if(n instanceof Error&&!r){const{code:s}=n;if(s==="ERR_UNSUPPORTED_DIR_IMPORT")try{return await U(e,t,a)}catch(o){if(o.code!=="ERR_PACKAGE_IMPORT_NOT_DEFINED")throw o}if(s==="ERR_MODULE_NOT_FOUND")try{return await E(e,t,a)}catch{}}throw n}};d.isFeatureSupported(d.moduleRegister)&&j.isMainThread&&J.register(),exports.globalPreload=A,exports.initialize=M,exports.load=H,exports.resolve=F;
