tsx 4.7.0 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,22 +1,21 @@
1
1
  # tsx <a href="https://npm.im/tsx"><img src="https://badgen.net/npm/v/tsx"></a> <a href="https://npm.im/tsx"><img src="https://badgen.net/npm/dm/tsx"></a> <a href="https://packagephobia.now.sh/result?p=tsx"><img src="https://packagephobia.now.sh/badge?p=tsx"></a>
2
2
 
3
- > _TypeScript Execute (`tsx`)_: Node.js enhanced to run TypeScript & ESM files
3
+ _TypeScript Execute (tsx)_: The easiest way to run TypeScript in Node.js
4
4
 
5
5
  ### Features
6
- - Blazing fast on-demand TypeScript & ESM compilation
7
- - Works in both [CommonJS and ESM packages](https://nodejs.org/api/packages.html#type)
8
- - Supports next-gen TypeScript extensions (`.cts` & `.mts`)
9
- - Hides experimental feature warnings
6
+ - Super fast!
10
7
  - TypeScript REPL
11
- - Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
12
-
8
+ - Supports `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
9
+ - Works in both [CommonJS and ESM packages](https://nodejs.org/api/packages.html#type)
13
10
 
14
11
  > [!TIP]
15
- > **Do you need to compile your TypeScript projects?** Try [pkgroll](https://github.com/privatenumber/pkgroll)—the zero-config bundler _tsx_ uses!
12
+ > **Build your TypeScript projects?**
13
+ >
14
+ > Try [<img width="20" valign="middle" src="https://github.com/privatenumber/pkgroll/raw/develop/.github/logo.webp"> pkgroll](https://github.com/privatenumber/pkgroll)—the zero-config package bundler used by _tsx_!
16
15
  >
17
- > _pkgroll_ is a thin layer over Rollup that auto-configures it based on your `package.json` entry points.
18
- >
19
- > It supports next-gen TS formats, export maps, `.d.ts` generation, and more!
16
+ > _pkgroll_ is a thin Rollup wrapper that makes it so simple for your package to support CommonJS, ESM, & TypeScript.
17
+ >
18
+ > If you love tsx, you'll love pkgroll too!
20
19
 
21
20
  <br>
22
21
 
@@ -31,50 +30,64 @@
31
30
  </p>
32
31
 
33
32
  ## About
34
- `tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM in both `commonjs` & `module` package types.
33
+ `tsx` is a CLI command you can use just like you would use `node`:
35
34
 
36
- This is for you if you ever wanted:
37
- - A command that can _just run_ TypeScript code without dealing with configuration
38
- - Better interoperability in codebases that use ESM and CJS dependencies
39
- - Something really fast it's unnoticeable!
35
+ <table>
36
+ <tr>
37
+ <th>Before</th>
38
+ <th>After</th>
39
+ </tr>
40
+ <tr>
41
+ <td>
40
42
 
41
- > [!TIP]
42
- > **tsx is not just for TypeScript!** It also helps Node load `module` type packages.
43
- >
44
- > If you're getting the following error, give _tsx_ a try!
45
- > ```
46
- > require('ESM package');
47
- > ^
48
- >
49
- > Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported.
50
- > Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules.
51
- > ```
52
-
53
- ### Quick start
54
- Try tsx now without setup! Just pass in a TypeScript file:
43
+ ```sh
44
+ node file.js
45
+ ```
46
+
47
+ </td>
48
+ <td>
55
49
 
56
50
  ```sh
57
- npx tsx ./script.ts
51
+ tsx file.js
58
52
  ```
59
53
 
60
- ### Mission
61
- 1. Enhance Node.js with TypeScript support
62
- 2. Improve ESM <-> CJS interoperability as the ecosystem migrates to ESM
63
- 3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs)
54
+ </td>
55
+ </tr>
56
+ </table>
57
+
58
+
59
+ Use it to enhance your Node.js experience:
60
+ - _Just run_ TypeScript code without configuration
61
+ - Seamless integration between CommonJS and ES Modules
64
62
 
65
- ## Install
63
+ You'll never get the following error again:
64
+
65
+ ```
66
+ Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported.
67
+ Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules.
68
+ ```
69
+
70
+ ### ⚡️ Quick start
71
+ Try it out without setup using [npx](https://docs.npmjs.com/cli/v8/commands/npx)! Just pass in a TypeScript file:
72
+
73
+ ```sh
74
+ npx tsx ./script.ts
75
+ ```
76
+
77
+ ## Installation
66
78
 
67
79
  ### Local installation
68
- If you're using it in an npm project, install it as a development dependency:
80
+
81
+ To add tsx to an npm project as a development dependency:
69
82
  ```sh
70
83
  npm install --save-dev tsx
71
84
  ```
72
85
 
73
- Then you can reference it directly in the `package.json#scripts` object (you don't need npx here):
86
+ You can reference it directly in the `package.json#scripts` object (you don't need `npx` here):
74
87
  ```json5
75
88
  {
76
89
  "scripts": {
77
- "dev": "tsx ..."
90
+ "dev": "tsx ./file.ts"
78
91
  }
79
92
  }
80
93
  ```
@@ -87,7 +100,7 @@ npx tsx ...
87
100
 
88
101
  ### Global installation
89
102
 
90
- If you want to use it in any arbitrary project without [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
103
+ If you want to use tsx anywhere on your computer without [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
91
104
 
92
105
  ```sh
93
106
  npm install --global tsx
@@ -96,26 +109,25 @@ npm install --global tsx
96
109
  Then, you can call `tsx` directly:
97
110
 
98
111
  ```sh
99
- tsx ...
112
+ tsx file.ts
100
113
  ```
101
114
 
102
- ## Usage
103
-
104
- ### tsx is a Node.js wrapper
115
+ Now you can replace `node ...` with `tsx ...` in all your commands!
105
116
 
106
- _tsx_ wraps around Node.js to enhance it with TypeScript support. Because it's a drop-in replacement for `node`, it supports all [Node.js command-line flags](https://nodejs.org/docs/latest-v20.x/api/cli.html).
117
+ ## Usage
107
118
 
108
- ```sh
109
- # --no-warnings is a Node.js flag
110
- tsx --no-warnings ./file.ts
111
- ```
119
+ ### Swap `node` out for `tsx`
112
120
 
113
- ### Run TypeScript / ESM / CJS module
121
+ _tsx_ is an enhanced version of Node.js. If you have a `node ...` command, you can replace the `node` with `tsx` and it will just work.
114
122
 
115
- Pass in a file to run:
123
+ Because it's a drop-in replacement for `node`, it supports all [Node.js command-line flags](https://nodejs.org/docs/latest-v20.x/api/cli.html).
116
124
 
117
125
  ```sh
118
- tsx ./file.ts
126
+ # Old command
127
+ node --no-warnings --env-file=.env ./file.js
128
+
129
+ # New command
130
+ tsx --no-warnings --env-file=.env ./file.js
119
131
  ```
120
132
 
121
133
  #### Custom `tsconfig.json` path
@@ -275,7 +287,7 @@ Create the following configuration file in your project to setup debugging in VS
275
287
  Path to tsx binary
276
288
  Assuming locally installed
277
289
  */
278
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/tsx",
290
+ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
279
291
 
280
292
  /*
281
293
  Open terminal when debugging starts (Optional)
@@ -329,21 +341,11 @@ Create the following configuration file in your project to setup debugging in VS
329
341
 
330
342
  See the [VSCode documentation on _Launch Configuration_](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration) for more information.
331
343
 
332
- <br>
344
+ ## Contributing & Support
333
345
 
334
- <p align="center">
335
- <a href="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold">
336
- <picture>
337
- <source width="830" media="(prefers-color-scheme: dark)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image=dark">
338
- <source width="830" media="(prefers-color-scheme: light)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image">
339
- <img width="830" src="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=gold&image" alt="Premium sponsor banner">
340
- </picture>
341
- </a>
342
- </p>
346
+ If you're interested in contributing, please check out the [Contribution Guide](/CONTRIBUTING.md). Your collaboration will be greatly appreciated!
343
347
 
344
- ## Support
345
-
346
- If there's a problem you're encountering or something you need help with, don't hesitate to take advantage of my [_Priority Support_ service](https://github.com/sponsors/privatenumber) where you can ask me questions in an exclusive forum. I'm well equppied to assist you with this project and would be happy to help you out! 🙂
348
+ If you're encountering a problem, take advantage of my [_Priority Support_ service](https://github.com/sponsors/privatenumber) for as little as $25. I'd be happy to help you out! 🙂
347
349
 
348
350
  ## FAQ
349
351
 
@@ -361,30 +363,25 @@ No. tsx is designed to be a simple TypeScript runner.
361
363
 
362
364
  If you need type-checking, you can use an IDE like [VS Code](https://code.visualstudio.com) and it will type-check as you code via [IntelliSense](https://code.visualstudio.com/docs/languages/typescript). Alternatively, you can run the TypeScript Compiler only for type-checking (e.g. `tsc --noEmit`) as a linting step.
363
365
 
364
-
365
366
  ### How is `tsx` different from [`ts-node`](https://github.com/TypeStrong/ts-node)?
366
367
 
367
- They're both tools to run TypeScript files. But tsx does a lot more to improve the experience of using Node.js.
368
+ `tsx` and `ts-node` are both designed for executing TypeScript files in Node.js, but offer different approaches to suit user preferences.
368
369
 
369
- tsx _just works_. It's zero-config and doesn't require `tsconfig.json` to get started, making it easy for users that just want to run TypeScript code and not get caught up in the configuration.
370
+ - **Simple installation** tsx is offered as a single binary without peer dependencies, and can be used without installation: `npx tsx ./script.ts`. In comparison, `ts-node` requires installing TypeScript or SWC as peer dependencies.
370
371
 
371
- It's a single binary with no peer-dependencies (e.g. TypeScript or esbuild), so there is no setup necessary, enabling usage that is elegant and frictionless for first-time users:
372
+ - **Zero configuration** tsx _just works_. It doesn't require initial setup or a `tsconfig.json` file, and doesn't get in the way of running your code.
372
373
 
373
- ```
374
- npx tsx ./script.ts
375
- ```
376
-
377
- tsx is zero-config because it has smart detections built in. As a runtime, it detects what's imported to make many options in `tsconfig.json` redundant—which was designed for compiling matching files regardless of whether they're imported.
374
+ - **Sensible defaults** tsx employs sensible defaults based on file imports and Node.js version, removing the need for certain `tsconfig.json` settings (that are designed for compilation rather than runtime). In comparison, ts-node relies on TypeScript's defaults (e.g. [`ES3` target](https://www.typescriptlang.org/tsconfig#target)), which may be outdated.
378
375
 
379
- It seamlessly adapts between CommonJS and ESM package types by detecting how modules are loaded (`require()` or `import`) to determine how to compile them. It even adds support for `require()`ing ESM modules from CommonJS so you don't have to worry about your dependencies as the ecosystem migrates to ESM.
376
+ - **Module adaptability** tsx automatically adapts between CommonJS and ESM modules, even supporting `require()` of ESM modules, facilitating a smoother transition as the Node.js ecosystem evolves.
380
377
 
381
- [Newer and unsupported syntax](https://esbuild.github.io/content-types/) & features like [importing `node:` prefixes](https://2ality.com/2021/12/node-protocol-imports.html) are downgraded by detecting the Node.js version. For large TypeScript codebases, it has [`tsconfig.json paths`](https://www.typescriptlang.org/tsconfig#paths) aliasing support out of the box.
378
+ - **Enhancements** tsx gracefully handles [new JS & TS syntax](https://esbuild.github.io/content-types/) and features based on the Node.js version. It also supports [`tsconfig.json` paths](https://www.typescriptlang.org/tsconfig#paths) out of the box.
382
379
 
383
- At the core, tsx is powered by esbuild for [blazing fast TypeScript compilation](https://esbuild.github.io/faq/#:~:text=typescript%20benchmark), whereas `ts-node` (by default) uses the TypeScript compiler. Because esbuild doesn't type check, `tsx` is similar to `ts-node --esm --swc` (which uses the [SWC compiler](https://github.com/TypeStrong/ts-node#swc-1)).
380
+ - **Speed** tsx utilizes [esbuild](https://esbuild.github.io/faq/#:~:text=typescript%20benchmark) to achieve rapid TypeScript compilation. In comparison, ts-node uses the TypeScript compiler by default. Because tsx doesn't type check, it's similar to `ts-node --esm --swc` (which uses the [SWC compiler](https://github.com/TypeStrong/ts-node#swc-1)).
384
381
 
385
- As a bonus, tsx also comes with a watcher to speed up your development.
382
+ - **Watcher** As a DX bonus, tsx also comes with watch mode to help you iterate faster!
386
383
 
387
- [Here's an exhaustive technical comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx`, `ts-node`, and other runtimes.
384
+ For a detailed technical comparison, you can refer to this [exhaustive comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx`, `ts-node`, and other runtimes.
388
385
 
389
386
  ### Does it have a configuration file?
390
387
 
@@ -402,23 +399,6 @@ For details, refer to esbuild's [JavaScript caveats](https://esbuild.github.io/c
402
399
 
403
400
  ## Sponsors
404
401
 
405
- <p align="center">
406
- <a href="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1">
407
- <picture>
408
- <source width="410" media="(prefers-color-scheme: dark)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image=dark">
409
- <source width="410" media="(prefers-color-scheme: light)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image">
410
- <img width="410" src="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1&image" alt="Premium sponsor banner">
411
- </picture>
412
- </a>
413
- <a href="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2">
414
- <picture>
415
- <source width="410" media="(prefers-color-scheme: dark)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image=dark">
416
- <source width="410" media="(prefers-color-scheme: light)" srcset="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image">
417
- <img width="410" src="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver2&image" alt="Premium sponsor banner">
418
- </picture>
419
- </a>
420
- </p>
421
-
422
402
  <p align="center">
423
403
  <a href="https://github.com/sponsors/privatenumber">
424
404
  <img src="https://cdn.jsdelivr.net/gh/privatenumber/sponsors/sponsorkit/sponsors.svg">
@@ -1 +1 @@
1
- "use strict";var f=require("path"),P=require("fs"),a=require("module"),l=require("get-tsconfig"),g=require("../source-map.cjs"),d=require("../index-5d1f01e6.cjs"),j=require("../resolve-ts-path-3fca13b7.cjs"),q=require("../client-2f0df4a6.cjs");require("url"),require("esbuild"),require("crypto"),require("os"),require("../temporary-directory-2a027842.cjs"),require("net"),require("../get-pipe-path-86e97fc9.cjs");const E=s=>{if(s.includes("import")||s.includes("export"))try{return d.parseEsm(s)[3]}catch{return!0}return!1},M=/^\.{1,2}\//,O=/\.[cm]?tsx?$/,A=`${f.sep}node_modules${f.sep}`,u=process.env.TSX_TSCONFIG_PATH?{path:f.resolve(process.env.TSX_TSCONFIG_PATH),config:l.parseTsconfig(process.env.TSX_TSCONFIG_PATH)}:l.getTsconfig(),p=u&&l.createFilesMatcher(u),x=u&&l.createPathsMatcher(u),y=g.installSourceMapSupport(),m=a._extensions,N=m[".js"],R=[".cts",".mts",".ts",".tsx",".jsx"],b=[".js",".cjs",".mjs"];let v;q.connectingToServer.then(s=>{v=s},()=>{});const S=(s,e)=>{v&&v({type:"dependency",path:e});const n=R.some(r=>e.endsWith(r)),o=b.some(r=>e.endsWith(r));if(!n&&!o)return N(s,e);let t=P.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const r=d.transformDynamicImport(e,t);r&&(t=y(r))}else if(n||E(t)){const r=d.transformSync(t,e,{tsconfigRaw:p==null?void 0:p(e)});t=y(r)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{m[s]=S}),Object.defineProperty(m,".mjs",{value:S,enumerable:!1});const T=a._resolveFilename.bind(a);a._resolveFilename=(s,e,n,o)=>{var t;const r=s.indexOf("?");if(r!==-1&&(s=s.slice(0,r)),x&&!M.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(A))){const i=x(s);for(const h of i){const _=F(h,e,n,o);if(_)return _;try{return T(h,e,n,o)}catch{}}}const c=F(s,e,n,o);return c||T(s,e,n,o)};const F=(s,e,n,o)=>{const t=j.resolveTsPath(s);if(e!=null&&e.filename&&O.test(e.filename)&&t)for(const r of t)try{return T(r,e,n,o)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
1
+ "use strict";var f=require("path"),P=require("fs"),a=require("module"),l=require("get-tsconfig"),g=require("../source-map.cjs"),d=require("../index-971a6964.cjs"),j=require("../resolve-ts-path-3fca13b7.cjs"),q=require("../client-2f0df4a6.cjs");require("url"),require("esbuild"),require("crypto"),require("os"),require("../temporary-directory-2a027842.cjs"),require("net"),require("../get-pipe-path-86e97fc9.cjs");const E=s=>{if(s.includes("import")||s.includes("export"))try{return d.parseEsm(s)[3]}catch{return!0}return!1},M=/^\.{1,2}\//,O=/\.[cm]?tsx?$/,A=`${f.sep}node_modules${f.sep}`,u=process.env.TSX_TSCONFIG_PATH?{path:f.resolve(process.env.TSX_TSCONFIG_PATH),config:l.parseTsconfig(process.env.TSX_TSCONFIG_PATH)}:l.getTsconfig(),p=u&&l.createFilesMatcher(u),x=u&&l.createPathsMatcher(u),y=g.installSourceMapSupport(),m=a._extensions,N=m[".js"],R=[".cts",".mts",".ts",".tsx",".jsx"],b=[".js",".cjs",".mjs"];let v;q.connectingToServer.then(s=>{v=s},()=>{});const S=(s,e)=>{v&&v({type:"dependency",path:e});const n=R.some(r=>e.endsWith(r)),o=b.some(r=>e.endsWith(r));if(!n&&!o)return N(s,e);let t=P.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const r=d.transformDynamicImport(e,t);r&&(t=y(r))}else if(n||E(t)){const r=d.transformSync(t,e,{tsconfigRaw:p==null?void 0:p(e)});t=y(r)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{m[s]=S}),Object.defineProperty(m,".mjs",{value:S,enumerable:!1});const T=a._resolveFilename.bind(a);a._resolveFilename=(s,e,n,o)=>{var t;const r=s.indexOf("?");if(r!==-1&&(s=s.slice(0,r)),x&&!M.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(A))){const i=x(s);for(const h of i){const _=F(h,e,n,o);if(_)return _;try{return T(h,e,n,o)}catch{}}}const c=F(s,e,n,o);return c||T(s,e,n,o)};const F=(s,e,n,o)=>{const t=j.resolveTsPath(s);if(e!=null&&e.filename&&O.test(e.filename)&&t)for(const r of t)try{return T(r,e,n,o)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
@@ -1 +1 @@
1
- import f from"path";import x from"fs";import m from"module";import{parseTsconfig as F,getTsconfig as j,createFilesMatcher as E,createPathsMatcher as O}from"get-tsconfig";import{installSourceMapSupport as P}from"../source-map.mjs";import{p as M,t as g,a as A}from"../index-bd1ceb03.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 M(t)[3]}catch{return!0}return!1},I=/^\.{1,2}\//,C=/\.[cm]?tsx?$/,D=`${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)}:j(),h=a&&E(a),_=a&&O(a),v=P(),l=m._extensions,G=l[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"];let p;R.then(t=>{p=t},()=>{});const y=(t,s)=>{p&&p({type:"dependency",path:s});const r=H.some(o=>s.endsWith(o)),n=X.some(o=>s.endsWith(o));if(!r&&!n)return G(t,s);let e=x.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const o=g(s,e);o&&(e=v(o))}else if(r||b(e)){const o=A(e,s,{tsconfigRaw:h==null?void 0:h(s)});e=v(o)}t._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(t=>{l[t]=y}),Object.defineProperty(l,".mjs",{value:y,enumerable:!1});const d=m._resolveFilename.bind(m);m._resolveFilename=(t,s,r,n)=>{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 i=_(t);for(const u of i){const T=S(u,s,r,n);if(T)return T;try{return d(u,s,r,n)}catch{}}}const c=S(t,s,r,n);return c||d(t,s,r,n)};const S=(t,s,r,n)=>{const e=N(t);if(s!=null&&s.filename&&C.test(s.filename)&&e)for(const o of e)try{return d(o,s,r,n)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
1
+ import f from"path";import x from"fs";import m from"module";import{parseTsconfig as F,getTsconfig as j,createFilesMatcher as E,createPathsMatcher as O}from"get-tsconfig";import{installSourceMapSupport as P}from"../source-map.mjs";import{p as M,t as g,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 M(t)[3]}catch{return!0}return!1},I=/^\.{1,2}\//,C=/\.[cm]?tsx?$/,D=`${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)}:j(),h=a&&E(a),_=a&&O(a),v=P(),l=m._extensions,G=l[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"];let p;R.then(t=>{p=t},()=>{});const y=(t,s)=>{p&&p({type:"dependency",path:s});const r=H.some(o=>s.endsWith(o)),n=X.some(o=>s.endsWith(o));if(!r&&!n)return G(t,s);let e=x.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const o=g(s,e);o&&(e=v(o))}else if(r||b(e)){const o=A(e,s,{tsconfigRaw:h==null?void 0:h(s)});e=v(o)}t._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(t=>{l[t]=y}),Object.defineProperty(l,".mjs",{value:y,enumerable:!1});const d=m._resolveFilename.bind(m);m._resolveFilename=(t,s,r,n)=>{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 i=_(t);for(const u of i){const T=S(u,s,r,n);if(T)return T;try{return d(u,s,r,n)}catch{}}}const c=S(t,s,r,n);return c||d(t,s,r,n)};const S=(t,s,r,n)=>{const e=N(t);if(s!=null&&s.filename&&C.test(s.filename)&&e)for(const o of e)try{return d(o,s,r,n)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};