import{isMainThread as J}from"worker_threads";import{i as y,a as M,m as N}from"../node-features-fb266590.mjs";import U from"module";import{installSourceMapSupport as _}from"../source-map.mjs";import f from"path";import{fileURLToPath as P,pathToFileURL as D}from"url";import{b as A,t as b}from"../index-29948669.mjs";import{r as x}from"../resolve-ts-path-eb3847f5.mjs";import{c as I}from"../client-e665d820.mjs";import{parseTsconfig as L,getTsconfig as $,createFilesMatcher as C,createPathsMatcher as W}from"get-tsconfig";import T from"fs";import"esbuild";import"crypto";import"os";import"../temporary-directory-04b36185.mjs";import"net";import"../get-pipe-path-b74d9893.mjs";const q=()=>{_(),U.register("./index.mjs",{parentURL:import.meta.url,data:!0})},u=new Map,G=async t=>{if(u.has(t))return u.get(t);if(!await T.promises.access(t).then(()=>!0,()=>!1)){u.set(t,void 0);return}const o=await T.promises.readFile(t,"utf8");try{const e=JSON.parse(o);return u.set(t,e),e}catch{throw new Error(`Error parsing: ${t}`)}},H=async t=>{let r=new URL("package.json",t);for(;!r.pathname.endsWith("/node_modules/package.json");){const o=P(r),e=await G(o);if(e)return e;const a=r;if(r=new URL("../package.json",r),r.pathname===a.pathname)break}},X=async t=>{var r;const o=await H(t);return(r=o==null?void 0:o.type)!=null?r:"commonjs"};var E,k;const m=process.env.TSX_TSCONFIG_PATH?{path:f.resolve(process.env.TSX_TSCONFIG_PATH),config:L(process.env.TSX_TSCONFIG_PATH)}:$(),K=m&&C(m),R=m&&W(m),Q=(k=(E=m==null?void 0:m.config.compilerOptions)==null?void 0:E.allowJs)!=null?k:!1,S="file://",l=/\.([cm]?ts|[tj]sx)($|\?)/,z=/\.json(?:$|\?)/,B=t=>{const r=f.extname(t);if(r===".json")return"json";if(r===".mjs"||r===".mts")return"module";if(r===".cjs"||r===".cts")return"commonjs"},V=t=>{const r=B(t);if(r)return r;if(l.test(t))return X(t)},j=_(),O=/\/(?:$|\?)/,Y=async t=>{if(!t)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`)},Z=()=>`
const require = getBuiltin('module').createRequire("${import.meta.url}");
require('../source-map.cjs').installSourceMapSupport();
`,d=async(t,r,o)=>{const e=await t(r,o);return!e.format&&e.url.startsWith(S)&&(e.format=await V(e.url)),e},tt=[".js",".json",".ts",".tsx",".jsx"],h=async(t,r,o)=>{const[e,a]=t.split("?");let c;for(const n of tt)try{return await d(o,e+n+(a?`?${a}`:""),r)}catch(s){if(c===void 0&&s instanceof Error){const{message:i}=s;s.message=s.message.replace(`${n}'`,"'"),s.stack=s.stack.replace(i,s.message),c=s}}throw c},v=async(t,r,o)=>{const e=O.test(t),a=e?"index":"/index",[c,n]=t.split("?");try{return await h(c+a+(n?`?${n}`:""),r,o)}catch(s){if(!e)try{return await h(t,r,o)}catch{}const i=s,{message:p}=i;throw i.message=i.message.replace(`${a.replace("/",f.sep)}'`,"'"),i.stack=i.stack.replace(p,i.message),i}},rt=/^\.{1,2}\//,F=async(t,r,o,e)=>{var a;if(O.test(t))return await v(t,r,o);const c=t.startsWith(S)||rt.test(t);if(R&&!c&&!((a=r.parentURL)!=null&&a.includes("/node_modules/"))){const n=R(t);for(const s of n)try{return await F(D(s).toString(),r,o)}catch{}}if(l.test(r.parentURL)||Q){const n=x(t);if(n)for(const s of n)try{return await d(o,s,r)}catch(i){const{code:p}=i;if(p!=="ERR_MODULE_NOT_FOUND"&&p!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw i}}try{return await d(o,t,r)}catch(n){if(n instanceof Error&&!e){const{code:s}=n;if(s==="ERR_UNSUPPORTED_DIR_IMPORT")try{return await v(t,r,o)}catch(i){if(i.code!=="ERR_PACKAGE_IMPORT_NOT_DEFINED")throw i}if(s==="ERR_MODULE_NOT_FOUND")try{return await h(t,r,o)}catch{}}throw n}};let g;I.then(t=>{g=t},()=>{});const w=y(M)?"importAttributes":"importAssertions",ot=async(t,r,o)=>{var e;g&&g({type:"dependency",path:t}),z.test(t)&&(r[w]||(r[w]={}),r[w].type="json");const a=await o(t,r);if(!a.source)return a;const c=t.startsWith("file://")?P(t):t,n=a.source.toString();if(a.format==="json"||l.test(t)){const s=await A(n,c,{tsconfigRaw:(e=K)==null?void 0:e(c)});return{format:"module",source:j(s)}}if(a.format==="module"){const s=b(c,n);s&&(a.source=j(s))}return a};y(N)&&J&&q();export{Z as globalPreload,Y as initialize,ot as load,F as resolve};
