site/node_modules/tsx/dist/register-B_eFQvfc.mjs
2024-10-14 08:09:33 +02:00

4 lines
6.5 KiB
JavaScript

var z=Object.defineProperty;var o=(s,e)=>z(s,"name",{value:e,configurable:!0});import{r as G}from"./get-pipe-path-BHW2eJdv.mjs";import u from"node:module";import h from"node:path";import{fileURLToPath as F}from"node:url";import{parseTsconfig as H,getTsconfig as X,createFilesMatcher as K,createPathsMatcher as V}from"get-tsconfig";import Y from"node:fs";import{b as Z,i as q,a as ee}from"./index-DeKCL_WS.mjs";import{p as U}from"./client-BQVF1NaW.mjs";const W=o(s=>{if(!s.startsWith("data:text/javascript,"))return;const e=s.indexOf("?");if(e===-1)return;const n=new URLSearchParams(s.slice(e+1)).get("filePath");if(n)return n},"getOriginalFilePath"),$=o(s=>{const e=W(s);return e&&(u._cache[e]=u._cache[s],delete u._cache[s],s=e),s},"interopCjsExports"),se=o(s=>{const e=s.indexOf(":");if(e!==-1)return s.slice(0,e)},"getScheme"),L=o(s=>s[0]==="."&&(s[1]==="/"||s[1]==="."||s[2]==="/"),"isRelativePath"),y=o(s=>L(s)||h.isAbsolute(s),"isFilePath"),te=o(s=>{if(y(s))return!0;const e=se(s);return e&&e!=="node"},"requestAcceptsQuery"),x="file://",R=/\.([cm]?ts|[tj]sx)($|\?)/,ne=/[/\\].+\.(?:cts|cjs)(?:$|\?)/,re=/\.json($|\?)/,_=/\/(?:$|\?)/,ae=/^(?:@[^/]+\/)?[^/\\]+$/,D=`${h.sep}node_modules${h.sep}`;let S,E,w=!1;const N=o(s=>{let e=null;if(s){const r=h.resolve(s);e={path:r,config:H(r)}}else{try{e=X()}catch{}if(!e)return}S=K(e),E=V(e),w=e?.config.compilerOptions?.allowJs??!1},"loadTsconfig"),M=o(s=>Array.from(s).length>0?`?${s.toString()}`:"","urlSearchParamsStringify"),oe=`
//# sourceMappingURL=data:application/json;base64,`,C=o(()=>process.sourceMapsEnabled??!0,"shouldApplySourceMap"),T=o(({code:s,map:e})=>s+oe+Buffer.from(JSON.stringify(e),"utf8").toString("base64"),"inlineSourceMap"),ce=[".cts",".mts",".ts",".tsx",".jsx"],ie=[".js",".cjs",".mjs"],A=[".ts",".tsx",".jsx"],v=o((s,e,r,n)=>{const t=Object.getOwnPropertyDescriptor(s,e);t?.set?s[e]=r:(!t||t.configurable)&&Object.defineProperty(s,e,{value:r,enumerable:t?.enumerable||n?.enumerable,writable:n?.writable??(t?t.writable:!0),configurable:n?.configurable??(t?t.configurable:!0)})},"safeSet"),le=o((s,e,r)=>{const n=e[".js"],t=o((a,c)=>{if(s.enabled===!1)return n(a,c);const[l,f]=c.split("?");if((new URLSearchParams(f).get("namespace")??void 0)!==r)return n(a,c);U?.send&&U.send({type:"dependency",path:l});const d=ce.some(m=>l.endsWith(m)),P=ie.some(m=>l.endsWith(m));if(!d&&!P)return n(a,l);let p=Y.readFileSync(l,"utf8");if(l.endsWith(".cjs")){const m=Z(c,p);m&&(p=C()?T(m):m.code)}else if(d||q(p)){const m=ee(p,c,{tsconfigRaw:S?.(l)});p=C()?T(m):m.code}a._compile(p,l)},"transformer");v(e,".js",t);for(const a of A)v(e,a,t,{enumerable:!r,writable:!0,configurable:!0});return v(e,".mjs",t,{writable:!0,configurable:!0}),()=>{e[".js"]===t&&(e[".js"]=n);for(const a of[...A,".mjs"])e[a]===t&&delete e[a]}},"createExtensions"),fe=o(s=>e=>{if((e==="."||e===".."||e.endsWith("/.."))&&(e+="/"),_.test(e)){let r=h.join(e,"index.js");e.startsWith("./")&&(r=`./${r}`);try{return s(r)}catch{}}try{return s(e)}catch(r){const n=r;if(n.code==="MODULE_NOT_FOUND")try{return s(`${e}${h.sep}index.js`)}catch{}throw n}},"createImplicitResolver"),Q=[".js",".json"],I=[".ts",".tsx",".jsx"],me=[...I,...Q],he=[...Q,...I],g=Object.create(null);g[".js"]=[".ts",".tsx",".js",".jsx"],g[".jsx"]=[".tsx",".ts",".jsx",".js"],g[".cjs"]=[".cts"],g[".mjs"]=[".mts"];const k=o(s=>{const e=s.split("?"),r=e[1]?`?${e[1]}`:"",[n]=e,t=h.extname(n),a=[],c=g[t];if(c){const f=n.slice(0,-t.length);a.push(...c.map(i=>f+i+r))}const l=!(s.startsWith(x)||y(n))||n.includes(D)||n.includes("/node_modules/")?he:me;return a.push(...l.map(f=>n+f+r)),a},"mapTsExtensions"),b=o((s,e,r)=>{if(_.test(e)||!r&&!w)return;const n=k(e);if(n)for(const t of n)try{return s(t)}catch(a){const{code:c}=a;if(c!=="MODULE_NOT_FOUND"&&c!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw a}},"resolveTsFilename"),pe=o((s,e)=>r=>{if(y(r)){const n=b(s,r,e);if(n)return n}try{return s(r)}catch(n){const t=n;if(t.code==="MODULE_NOT_FOUND"){if(typeof t.path=="string"&&t.path.endsWith(`${h.sep}package.json`)){const c=t.message.match(/^Cannot find module '([^']+)'$/);if(c){const f=c[1],i=b(s,f,e);if(i)return i}const l=t.message.match(/^Cannot find module '([^']+)'. Please verify that the package.json has a valid "main" entry$/);if(l){const f=l[1],i=b(s,f,e);if(i)return i}}const a=b(s,r,e);if(a)return a}throw t}},"createTsExtensionResolver"),J="at cjsPreparseModuleExports (node:internal",ue=o(s=>{const e=s.stack.split(`
`).slice(1);return e[1].includes(J)||e[2].includes(J)},"isFromCjsLexer"),de=o((s,e)=>{const r=s.split("?"),n=new URLSearchParams(r[1]);if(e?.filename){const t=W(e.filename);let a;if(t){const f=t.split("?"),i=f[0];a=f[1],e.filename=i,e.path=h.dirname(i),e.paths=u._nodeModulePaths(e.path),u._cache[i]=e}a||(a=e.filename.split("?")[1]);const l=new URLSearchParams(a).get("namespace");l&&n.append("namespace",l)}return[r[0],n,(t,a)=>(h.isAbsolute(t)&&!t.endsWith(".json")&&!t.endsWith(".node")&&!(a===0&&ue(new Error))&&(t+=M(n)),t)]},"preserveQuery"),Pe=o((s,e,r)=>{if(s.startsWith(x)&&(s=F(s)),E&&!y(s)&&!e?.filename?.includes(D)){const n=E(s);for(const t of n)try{return r(t)}catch{}}return r(s)},"resolveTsPaths"),ge=o((s,e,r)=>(n,t,...a)=>{if(s.enabled===!1)return e(n,t,...a);n=$(n);const[c,l,f]=de(n,t);if((l.get("namespace")??void 0)!==r)return e(n,t,...a);let i=o(P=>e(P,t,...a),"nextResolveSimple");i=pe(i,!!(t?.filename&&R.test(t.filename))),i=fe(i);const d=Pe(c,t,i);return f(d,a.length)},"createResolveFilename"),B=o((s,e)=>{if(!e)throw new Error("The current file path (__filename or import.meta.url) must be provided in the second argument of tsx.require()");return s.startsWith(".")?((typeof e=="string"&&e.startsWith(x)||e instanceof URL)&&(e=F(e)),h.resolve(h.dirname(e),s)):s},"resolveContext"),je=o(s=>{const{sourceMapsEnabled:e}=process,r={enabled:!0};N(process.env.TSX_TSCONFIG_PATH),process.setSourceMapsEnabled(!0);const n=u._resolveFilename,t=ge(r,n,s?.namespace);u._resolveFilename=t;const a=le(r,u._extensions,s?.namespace),c=o(()=>{e===!1&&process.setSourceMapsEnabled(!1),r.enabled=!1,u._resolveFilename===t&&(u._resolveFilename=n),a()},"unregister");if(s?.namespace){const l=o((i,d)=>{const P=B(i,d),[p,m]=P.split("?"),j=new URLSearchParams(m);return s.namespace&&!p.startsWith("node:")&&j.set("namespace",s.namespace),G(p+M(j))},"scopedRequire");c.require=l;const f=o((i,d,P)=>{const p=B(i,d),[m,j]=p.split("?"),O=new URLSearchParams(j);return s.namespace&&!m.startsWith("node:")&&O.set("namespace",s.namespace),t(m+M(O),module,!1,P)},"scopedResolve");c.resolve=f,c.unregister=c}return c},"register");export{$ as a,re as b,ne as c,S as d,T as e,x as f,te as g,E as h,ae as i,_ as j,L as k,N as l,k as m,w as n,je as r,R as t};