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