"use strict";const{readFileSync}=require("fs"),{extname}=require("path"),tsm=require("./utils"),loadJS=require.extensions[".js"];let esbuild,env=tsm.$defaults("cjs"),uconf=env.file&&require(env.file),config=tsm.$finalize(env,uconf);const tsrequire='var $$req=require("module").createRequire(__filename);require=('+function(){let{existsSync:t}=$$req("fs"),r=$$req("url");return new Proxy(require,{apply(l,n,o){let[e]=o;if(!e)return l.apply(n||$$req,o);if(/^\w+\:?/.test(e))return $$req(e);let u=/\.([mc])?[tj]sx?(?=\?|$)/.exec(e);if(u==null)return $$req(e);let f=r.pathToFileURL(__filename),s=r.fileURLToPath(new r.URL(e,f));if(t(s))return $$req(e);let p=u[0],a=new RegExp(p+"$"),i=s.replace(a,p.replace("js","ts"));return t(i)||p===".js"&&(i=s.replace(a,".tsx"),t(i)||(i=s.replace(a,".jsx"),t(i)))?$$req(i):$$req(e)}})}+")();";function transform(t,r){return esbuild=esbuild||require("esbuild"),esbuild.transformSync(t,r).code}function loader(t,r){let l=extname(r),n=config[l]||{},o=t._compile.bind(t);n.sourcefile=r,/\.[mc]?[tj]sx?$/.test(l)&&(n.banner=tsrequire+(n.banner||""),n.supported=n.supported||{},n.supported["dynamic-import"]=!1),config[l]!=null&&(t._compile=e=>{let u=transform(e,n);return o(u,r)});try{return loadJS(t,r)}catch(e){if((e&&e.code)!=="ERR_REQUIRE_ESM")throw e;let f=readFileSync(r,"utf8"),s=transform(f,{...n,format:"cjs"});return o(s,r)}}for(let t in config)require.extensions[t]=loader;config[".js"]==null&&(require.extensions[".js"]=loader);
