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