tsx 4.1.4 → 4.2.1
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 +108 -10
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.mjs +1 -1
- package/dist/cli.cjs +26 -26
- package/dist/cli.mjs +24 -24
- package/dist/esm/index.cjs +4 -4
- package/dist/esm/index.mjs +1 -1
- package/dist/index-129c7da4.cjs +16 -0
- package/dist/index-449380c0.mjs +16 -0
- package/dist/loader.cjs +1 -1
- package/dist/loader.mjs +1 -1
- package/dist/package-7163e2da.cjs +1 -0
- package/dist/package-9e1fc2a5.mjs +1 -0
- package/dist/pkgroll_create-require-c530e400.cjs +1 -0
- package/dist/preflight.cjs +1 -1
- package/dist/preflight.mjs +1 -1
- package/dist/repl.cjs +3 -3
- package/dist/repl.mjs +1 -1
- package/dist/resolve-ts-path-3fca13b7.cjs +1 -0
- package/dist/source-map.cjs +2 -2
- package/dist/source-map.mjs +1 -1
- package/package.json +1 -1
- package/dist/index-a3068c79.mjs +0 -14
- package/dist/index-cd956ba0.cjs +0 -14
- package/dist/package-372463c6.cjs +0 -1
- package/dist/package-cda48569.mjs +0 -1
- package/dist/pkgroll_create-require-e664799a.cjs +0 -1
- package/dist/resolve-ts-path-43f50656.cjs +0 -1
- /package/dist/{node-features-a792cc3d.mjs → node-features-2541e522.mjs} +0 -0
- /package/dist/{node-features-84a305a1.cjs → node-features-a3d031eb.cjs} +0 -0
- /package/dist/{pkgroll_create-require-6da665f0.mjs → pkgroll_create-require-b92e8e0d.mjs} +0 -0
- /package/dist/{resolve-ts-path-a8cb04a4.mjs → resolve-ts-path-eb3847f5.mjs} +0 -0
package/README.md
CHANGED
|
@@ -27,24 +27,26 @@
|
|
|
27
27
|
</p>
|
|
28
28
|
|
|
29
29
|
## About
|
|
30
|
-
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM
|
|
30
|
+
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM in both `commonjs` & `module` package types.
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
This is for you if you ever wanted:
|
|
33
|
+
- A command that can _just run_ TypeScript code without dealing with configuration
|
|
34
|
+
- Better interoperability in codebases that use ESM and CJS dependencies
|
|
35
|
+
- Something really fast it's unnoticeable!
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
### Quick start
|
|
38
|
+
Try tsx now without setup! Just pass in a TypeScript file:
|
|
35
39
|
|
|
36
40
|
```sh
|
|
37
41
|
npx tsx ./script.ts
|
|
38
42
|
```
|
|
39
43
|
|
|
40
|
-
How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkout the [comparison](https://github.com/privatenumber/ts-runtime-comparison).
|
|
41
|
-
|
|
42
44
|
### Mission
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
2. Improve ESM <-> CJS interoperability
|
|
45
|
+
1. Enhance Node.js with TypeScript support
|
|
46
|
+
2. Improve ESM <-> CJS interoperability as the ecosystem migrates to ESM
|
|
46
47
|
3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs)
|
|
47
48
|
|
|
49
|
+
|
|
48
50
|
## Install
|
|
49
51
|
|
|
50
52
|
### Local installation
|
|
@@ -53,7 +55,7 @@ If you're using it in an npm project, install it as a development dependency:
|
|
|
53
55
|
npm install --save-dev tsx
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
Then you can reference it directly in the `package.json#scripts` object (you don't need npx here):
|
|
57
59
|
```json5
|
|
58
60
|
{
|
|
59
61
|
"scripts": {
|
|
@@ -84,8 +86,14 @@ tsx ...
|
|
|
84
86
|
|
|
85
87
|
## Usage
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
### tsx is a Node.js wrapper
|
|
88
90
|
|
|
91
|
+
_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).
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
# --no-warnings is a Node.js flag
|
|
95
|
+
tsx --no-warnings ./file.ts
|
|
96
|
+
```
|
|
89
97
|
|
|
90
98
|
### Run TypeScript / ESM / CJS module
|
|
91
99
|
|
|
@@ -216,6 +224,96 @@ $ ./file.ts hello
|
|
|
216
224
|
argv: [ 'hello' ]
|
|
217
225
|
```
|
|
218
226
|
|
|
227
|
+
### VS Code debugging
|
|
228
|
+
|
|
229
|
+
#### Setup
|
|
230
|
+
|
|
231
|
+
Create the following configuration file in your project to setup debugging in VS Code:
|
|
232
|
+
|
|
233
|
+
`.vscode/launch.json`
|
|
234
|
+
```json5
|
|
235
|
+
{
|
|
236
|
+
"version": "0.2.0",
|
|
237
|
+
|
|
238
|
+
"configurations": [
|
|
239
|
+
/*
|
|
240
|
+
Each config in this array is an option in the debug drop-down
|
|
241
|
+
See below for configurations to add...
|
|
242
|
+
*/
|
|
243
|
+
],
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
#### Debugging method 1: Run tsx directly from VSCode
|
|
248
|
+
|
|
249
|
+
1. Add the following configuration to the `configurations` array in `.vscode/launch.json`:
|
|
250
|
+
```json5
|
|
251
|
+
{
|
|
252
|
+
"name": "tsx",
|
|
253
|
+
"type": "node",
|
|
254
|
+
"request": "launch",
|
|
255
|
+
|
|
256
|
+
// Debug current file in VSCode
|
|
257
|
+
"program": "${file}",
|
|
258
|
+
|
|
259
|
+
/*
|
|
260
|
+
Path to tsx binary
|
|
261
|
+
Assuming locally installed
|
|
262
|
+
*/
|
|
263
|
+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/tsx",
|
|
264
|
+
|
|
265
|
+
/*
|
|
266
|
+
Open terminal when debugging starts (Optional)
|
|
267
|
+
Useful to see console.logs
|
|
268
|
+
*/
|
|
269
|
+
"console": "integratedTerminal",
|
|
270
|
+
"internalConsoleOptions": "neverOpen",
|
|
271
|
+
|
|
272
|
+
// Files to exclude from debugger (e.g. call stack)
|
|
273
|
+
"skipFiles": [
|
|
274
|
+
// Node.js internal core modules
|
|
275
|
+
"<node_internals>/**",
|
|
276
|
+
|
|
277
|
+
// Ignore all dependencies (optional)
|
|
278
|
+
"${workspaceFolder}/node_modules/**",
|
|
279
|
+
],
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
2. In VSCode, open the file you want to run
|
|
284
|
+
|
|
285
|
+
3. Go to VSCode's debug panel, select "tsx" in the drop down, and hit the play button (<kbd>F5</kbd>).
|
|
286
|
+
|
|
287
|
+
#### Debugging method 2: Attach to a running Node.js process
|
|
288
|
+
|
|
289
|
+
> This method works for any Node.js process and it's not specific to tsx
|
|
290
|
+
|
|
291
|
+
1. Add the following configuration to the `configurations` array in `.vscode/launch.json`:
|
|
292
|
+
```json
|
|
293
|
+
{
|
|
294
|
+
"name": "Attach to process",
|
|
295
|
+
"type": "node",
|
|
296
|
+
"request": "attach",
|
|
297
|
+
"port": 9229,
|
|
298
|
+
"skipFiles": [
|
|
299
|
+
// Node.js internal core modules
|
|
300
|
+
"<node_internals>/**",
|
|
301
|
+
|
|
302
|
+
// Ignore all dependencies (optional)
|
|
303
|
+
"${workspaceFolder}/node_modules/**",
|
|
304
|
+
],
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
2. Run tsx with `--inspect-brk` in a terminal window:
|
|
308
|
+
|
|
309
|
+
```sh
|
|
310
|
+
tsx --inspect-brk ./your-file.ts
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
3. Go to VSCode's debug panel, select "Attach to process" in the drop down, and hit the play button (<kbd>F5</kbd>).
|
|
314
|
+
|
|
315
|
+
See the [VSCode documentation on _Launch Configuration_](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration) for more information.
|
|
316
|
+
|
|
219
317
|
<br>
|
|
220
318
|
|
|
221
319
|
<p align="center">
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=require("path"),S=require("fs"),a=require("module"),l=require("get-tsconfig"),g=require("../source-map.cjs"),m=require("../index-129c7da4.cjs"),j=require("../resolve-ts-path-3fca13b7.cjs");require("source-map-support"),require("../node-features-a3d031eb.cjs"),require("url"),require("esbuild"),require("crypto"),require("os");const E=s=>{if(s.includes("import")||s.includes("export")){const[e,n]=m.parseEsm(s);return e.length>0||n.length>0}return!1},O=/^\.{1,2}\//,q=/\.[cm]?tsx?$/,M=`${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(),_=u&&l.createFilesMatcher(u),h=u&&l.createPathsMatcher(u),x=g.installSourceMapSupport(),d=a._extensions,P=d[".js"],A=[".cts",".mts",".ts",".tsx",".jsx"],N=[".js",".cjs",".mjs"],F=(s,e)=>{process.send&&process.send({type:"dependency",path:e});const n=A.some(r=>e.endsWith(r)),o=N.some(r=>e.endsWith(r));if(!n&&!o)return P(s,e);let t=S.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const r=m.transformDynamicImport(e,t);r&&(t=x(r,e))}else if(n||E(t)){const r=m.transformSync(t,e,{tsconfigRaw:_==null?void 0:_(e)});t=x(r,e)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{d[s]=F}),Object.defineProperty(d,".mjs",{value:F,enumerable:!1});const v=a._resolveFilename.bind(a);a._resolveFilename=(s,e,n,o)=>{var t;const r=s.indexOf("?");if(r!==-1&&(s=s.slice(0,r)),h&&!O.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(M))){const i=h(s);for(const T of i){const p=y(T,e,n,o);if(p)return p;try{return v(T,e,n,o)}catch{}}}const c=y(s,e,n,o);return c||v(s,e,n,o)};const y=(s,e,n,o)=>{const t=j.resolveTsPath(s);if(e!=null&&e.filename&&q.test(e.filename)&&t)for(const r of t)try{return v(r,e,n,o)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
|
package/dist/cjs/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import f from"path";import F from"fs";import m from"module";import{parseTsconfig as y,getTsconfig as S,createFilesMatcher as j,createPathsMatcher as E}from"get-tsconfig";import{installSourceMapSupport as O}from"../source-map.mjs";import{p as g,a as M,b as P}from"../index-
|
|
1
|
+
import f from"path";import F from"fs";import m from"module";import{parseTsconfig as y,getTsconfig as S,createFilesMatcher as j,createPathsMatcher as E}from"get-tsconfig";import{installSourceMapSupport as O}from"../source-map.mjs";import{p as g,a as M,b as P}from"../index-449380c0.mjs";import{r as b}from"../resolve-ts-path-eb3847f5.mjs";import"source-map-support";import"../node-features-2541e522.mjs";import"url";import"esbuild";import"crypto";import"os";const A=o=>{if(o.includes("import")||o.includes("export")){const[s,n]=g(o);return s.length>0||n.length>0}return!1},N=/^\.{1,2}\//,R=/\.[cm]?tsx?$/,I=`${f.sep}node_modules${f.sep}`,a=process.env.TSX_TSCONFIG_PATH?{path:f.resolve(process.env.TSX_TSCONFIG_PATH),config:y(process.env.TSX_TSCONFIG_PATH)}:S(),T=a&&j(a),_=a&&E(a),v=O(),l=m._extensions,C=l[".js"],D=[".cts",".mts",".ts",".tsx",".jsx"],G=[".js",".cjs",".mjs"],h=(o,s)=>{process.send&&process.send({type:"dependency",path:s});const n=D.some(t=>s.endsWith(t)),r=G.some(t=>s.endsWith(t));if(!n&&!r)return C(o,s);let e=F.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const t=M(s,e);t&&(e=v(t,s))}else if(n||A(e)){const t=P(e,s,{tsconfigRaw:T==null?void 0:T(s)});e=v(t,s)}o._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(o=>{l[o]=h}),Object.defineProperty(l,".mjs",{value:h,enumerable:!1});const p=m._resolveFilename.bind(m);m._resolveFilename=(o,s,n,r)=>{var e;const t=o.indexOf("?");if(t!==-1&&(o=o.slice(0,t)),_&&!N.test(o)&&!((e=s==null?void 0:s.filename)!=null&&e.includes(I))){const i=_(o);for(const d of i){const u=x(d,s,n,r);if(u)return u;try{return p(d,s,n,r)}catch{}}}const c=x(o,s,n,r);return c||p(o,s,n,r)};const x=(o,s,n,r)=>{const e=b(o);if(s!=null&&s.filename&&R.test(s.filename)&&e)for(const t of e)try{return p(t,s,n,r)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
|