import f from"path";import x from"fs";import l from"module";import{parseTsconfig as F,getTsconfig as O,createFilesMatcher as j,createPathsMatcher as E}from"get-tsconfig";import{installSourceMapSupport as P}from"../source-map.mjs";import{p as g,t as M,a as A}from"../index-29948669.mjs";import{r as N}from"../resolve-ts-path-eb3847f5.mjs";import{c as R}from"../client-e665d820.mjs";import"url";import"esbuild";import"crypto";import"os";import"../temporary-directory-04b36185.mjs";import"net";import"../get-pipe-path-b74d9893.mjs";const b=t=>{if(t.includes("import")||t.includes("export"))try{return g(t)[3]}catch{return!0}return!1},I=/^\.{1,2}\//,C=/\.[cm]?tsx?$/,D=`${f.sep}node_modules${f.sep}`,c=process.env.TSX_TSCONFIG_PATH?{path:f.resolve(process.env.TSX_TSCONFIG_PATH),config:F(process.env.TSX_TSCONFIG_PATH)}:O(),v=c&&j(c),_=c&&E(c),h=P(),p=l._extensions,G=p[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"];let d;R.then(t=>{d=t},()=>{});const y=(t,s)=>{d&&d({type:"dependency",path:s});const n=H.some(o=>s.endsWith(o)),r=X.some(o=>s.endsWith(o));if(!n&&!r)return G(t,s);let e=x.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const o=M(s,e);o&&(e=h(o))}else if(n||b(e)){const o=A(e,s,{tsconfigRaw:v==null?void 0:v(s)});e=h(o)}t._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(t=>{p[t]=y}),Object.defineProperty(p,".mjs",{value:y,enumerable:!1});const u=l._resolveFilename.bind(l);l._resolveFilename=(t,s,n,r)=>{var e;const o=t.indexOf("?");if(o!==-1&&(t=t.slice(0,o)),_&&!I.test(t)&&!((e=s==null?void 0:s.filename)!=null&&e.includes(D))){const m=_(t);for(const i of m){const T=S(i,s,n,r);if(T)return T;try{return u(i,s,n,r)}catch{}}}const a=S(t,s,n,r);return a||u(t,s,n,r)};const S=(t,s,n,r)=>{var e;const o=N(t);if(s!=null&&s.filename&&(C.test(s.filename)||(e=c==null?void 0:c.config.compilerOptions)!=null&&e.allowJs)&&o)for(const a of o)try{return u(a,s,n,r)}catch(m){const{code:i}=m;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw m}};
