tsx 3.4.2 → 3.5.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 +36 -18
- package/dist/cli.cjs +15 -15
- package/dist/cli.js +15 -15
- package/dist/loader.cjs +1 -1
- package/dist/loader.js +1 -1
- package/dist/package-0f4ac2cf.js +1 -0
- package/dist/package-853fb12a.cjs +1 -0
- package/dist/{pkgroll_create-require-d7ed1b4a.cjs → pkgroll_create-require-6cd0a902.cjs} +0 -0
- package/dist/{pkgroll_create-require-91c05cc3.js → pkgroll_create-require-890b6873.js} +0 -0
- package/dist/repl.cjs +3 -3
- package/dist/repl.js +3 -3
- package/package.json +11 -10
- package/dist/package-80b512a7.cjs +0 -1
- package/dist/package-f202b71b.js +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tsx
|
|
2
2
|
|
|
3
|
-
_TypeScript Execute (tsx)_: Node.js enhanced with [esbuild](https://esbuild.github.io/) to run TypeScript & ESM files
|
|
3
|
+
> _TypeScript Execute (`tsx`)_: Node.js enhanced with [esbuild](https://esbuild.github.io/) to run TypeScript & ESM files
|
|
4
4
|
|
|
5
5
|
### Features
|
|
6
6
|
- Blazing fast on-demand TypeScript & ESM compilation
|
|
@@ -11,6 +11,22 @@ _TypeScript Execute (tsx)_: Node.js enhanced with [esbuild](https://esbuild.gith
|
|
|
11
11
|
- TypeScript REPL
|
|
12
12
|
- Tested on Linux & Windows with Node.js v12~18
|
|
13
13
|
|
|
14
|
+
<sub>Support this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub>
|
|
15
|
+
|
|
16
|
+
## About
|
|
17
|
+
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM, in both `commonjs` & `module` package types.
|
|
18
|
+
|
|
19
|
+
It's powered by [esbuild](https://esbuild.github.io/) so it's insanely fast.
|
|
20
|
+
|
|
21
|
+
Want to just run TypeScript code? Try tsx:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx tsx ./script.ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkout the [comparison](https://github.com/privatenumber/ts-runtime-comparison).
|
|
28
|
+
|
|
29
|
+
|
|
14
30
|
## Install
|
|
15
31
|
|
|
16
32
|
### Local installation
|
|
@@ -36,13 +52,13 @@ npx tsx ...
|
|
|
36
52
|
|
|
37
53
|
### Global installation
|
|
38
54
|
|
|
39
|
-
If you want to use it in any arbitrary project without [npx](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
|
|
55
|
+
If you want to use it in any arbitrary project without [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
|
|
40
56
|
|
|
41
57
|
```sh
|
|
42
58
|
npm install --global tsx
|
|
43
59
|
```
|
|
44
60
|
|
|
45
|
-
|
|
61
|
+
Then, you can call `tsx` directly:
|
|
46
62
|
|
|
47
63
|
```sh
|
|
48
64
|
tsx ...
|
|
@@ -59,26 +75,26 @@ tsx ./file.ts
|
|
|
59
75
|
```
|
|
60
76
|
|
|
61
77
|
### Watch mode
|
|
62
|
-
Run file and automatically re-run on changes
|
|
78
|
+
Run file and automatically re-run on changes:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
tsx watch ./file.ts
|
|
82
|
+
```
|
|
63
83
|
|
|
64
84
|
All imported files are watched except from the following directories:
|
|
65
85
|
`node_modules`, `bower_components`, `vendor`, `dist`, and `.*` (hidden directories).
|
|
66
86
|
|
|
67
87
|
Press <kbd>Return</kbd> to manually re-run.
|
|
68
88
|
|
|
69
|
-
```sh
|
|
70
|
-
tsx watch ./file.ts
|
|
71
|
-
```
|
|
72
|
-
|
|
73
89
|
### REPL
|
|
74
|
-
Start a TypeScript REPL by running with no arguments
|
|
90
|
+
Start a TypeScript REPL by running with no arguments:
|
|
75
91
|
|
|
76
92
|
```sh
|
|
77
93
|
tsx
|
|
78
94
|
```
|
|
79
95
|
|
|
80
96
|
### Cache
|
|
81
|
-
Modules transformations are cached in the system cache directory ([`TMPDIR`](https://en.wikipedia.org/wiki/TMPDIR)). Transforms are cached by content hash so duplicate dependencies are not re-transformed.
|
|
97
|
+
Modules transformations are cached in the system cache directory ([`TMPDIR`](https://en.wikipedia.org/wiki/TMPDIR)). Transforms are cached by content hash, so duplicate dependencies are not re-transformed.
|
|
82
98
|
|
|
83
99
|
Set the `--no-cache` flag to disable the cache:
|
|
84
100
|
|
|
@@ -88,11 +104,11 @@ tsx --no-cache ./file.ts
|
|
|
88
104
|
|
|
89
105
|
### Node.js Loader
|
|
90
106
|
|
|
91
|
-
`tsx` is a standalone binary designed to be used in
|
|
107
|
+
`tsx` is a standalone binary designed to be used in place of `node`, but sometimes you'll want to use `node` directly. For example, when adding TypeScript & ESM support to npm-installed binaries.
|
|
92
108
|
|
|
93
|
-
To use tsx with Node.js, pass it
|
|
109
|
+
To use `tsx` with Node.js, pass it to the [`--loader`](https://nodejs.org/api/esm.html#loaders) flag.
|
|
94
110
|
|
|
95
|
-
> Note: Node.js's experimental feature warnings will not be suppressed when used as a loader
|
|
111
|
+
> Note: Node.js's experimental feature warnings will not be suppressed when used as a loader.
|
|
96
112
|
|
|
97
113
|
```sh
|
|
98
114
|
# As a CLI flag
|
|
@@ -102,15 +118,15 @@ node --loader tsx ./file.ts
|
|
|
102
118
|
NODE_OPTIONS='--loader tsx' node ./file.ts
|
|
103
119
|
```
|
|
104
120
|
|
|
105
|
-
> Tip: In rare circumstances, you might be limited to
|
|
121
|
+
> Tip: In rare circumstances, you might be limited to using the [`-r, --require`](https://nodejs.org/api/cli.html#-r---require-module) flag.
|
|
106
122
|
>
|
|
107
|
-
> You can use [`@esbuild-kit/cjs-loader`](https://github.com/esbuild-kit/cjs-loader) but transformations will only be applied to `require()`.
|
|
123
|
+
> You can use [`@esbuild-kit/cjs-loader`](https://github.com/esbuild-kit/cjs-loader), but transformations will only be applied to `require()`.
|
|
108
124
|
|
|
109
125
|
## Dependencies
|
|
110
126
|
|
|
111
127
|
- [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader) - Node.js Loader to transform TypeScript to ESM.
|
|
112
128
|
|
|
113
|
-
- [@esbuild-kit/cjs-loader](https://github.com/esbuild-kit/cjs-loader) - Node.js `
|
|
129
|
+
- [@esbuild-kit/cjs-loader](https://github.com/esbuild-kit/cjs-loader) - Node.js `require()` hook to transform TypeScript & ESM to CommonJS.
|
|
114
130
|
|
|
115
131
|
|
|
116
132
|
## FAQ
|
|
@@ -126,8 +142,10 @@ It's recommended to run TypeScript separately as a command (`tsc --noEmit`) or v
|
|
|
126
142
|
|
|
127
143
|
They are both tools to run TypeScript files.
|
|
128
144
|
|
|
129
|
-
The main difference is that `tsx` is powered by [esbuild](https://esbuild.github.io/) for blazing fast TypeScript compilation
|
|
145
|
+
The main difference is that `tsx` is powered by [esbuild](https://esbuild.github.io/) for blazing fast TypeScript compilation, whereas `ts-node` uses the TypeScript compiler, [which is not as fast](https://esbuild.github.io/faq/#:~:text=typescript%20benchmark).
|
|
146
|
+
|
|
147
|
+
Because esbuild doesn't do type checking, `tsx` is more equivalent to `ts-node --esm --transpileOnly`.
|
|
130
148
|
|
|
131
|
-
|
|
149
|
+
[Here's an exhaustive comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx` vs `ts-node` (and other runtimes).
|
|
132
150
|
|
|
133
151
|
If you migrated from `ts-node`, please share your performance gains [here](https://github.com/esbuild-kit/tsx/discussions/10)!
|