tsx 3.4.2 → 3.4.3

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,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,21 @@ _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
+
15
+ ## About
16
+ `tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM, in both `commonjs` & `module` package types.
17
+
18
+ It's powered by [esbuild](https://esbuild.github.io/) so it's insanely fast.
19
+
20
+ Want to just run TypeScript code? Try tsx:
21
+
22
+ ```sh
23
+ npx tsx ./script.ts
24
+ ```
25
+
26
+ How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkout the [comparison](https://github.com/privatenumber/ts-runtime-comparison).
27
+
28
+
14
29
  ## Install
15
30
 
16
31
  ### Local installation
@@ -36,13 +51,13 @@ npx tsx ...
36
51
 
37
52
  ### Global installation
38
53
 
39
- If you want to use it in any arbitrary project without [npx](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
54
+ If you want to use it in any arbitrary project without [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), install it globally:
40
55
 
41
56
  ```sh
42
57
  npm install --global tsx
43
58
  ```
44
59
 
45
- You can call `tsx` directly:
60
+ Then, you can call `tsx` directly:
46
61
 
47
62
  ```sh
48
63
  tsx ...
@@ -59,26 +74,26 @@ tsx ./file.ts
59
74
  ```
60
75
 
61
76
  ### Watch mode
62
- Run file and automatically re-run on changes.
77
+ Run file and automatically re-run on changes:
78
+
79
+ ```sh
80
+ tsx watch ./file.ts
81
+ ```
63
82
 
64
83
  All imported files are watched except from the following directories:
65
84
  `node_modules`, `bower_components`, `vendor`, `dist`, and `.*` (hidden directories).
66
85
 
67
86
  Press <kbd>Return</kbd> to manually re-run.
68
87
 
69
- ```sh
70
- tsx watch ./file.ts
71
- ```
72
-
73
88
  ### REPL
74
- Start a TypeScript REPL by running with no arguments.
89
+ Start a TypeScript REPL by running with no arguments:
75
90
 
76
91
  ```sh
77
92
  tsx
78
93
  ```
79
94
 
80
95
  ### 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.
96
+ 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
97
 
83
98
  Set the `--no-cache` flag to disable the cache:
84
99
 
@@ -88,11 +103,11 @@ tsx --no-cache ./file.ts
88
103
 
89
104
  ### Node.js Loader
90
105
 
91
- `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.
106
+ `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
107
 
93
- To use tsx with Node.js, pass it into the [`--loader`](https://nodejs.org/api/esm.html#loaders) flag.
108
+ To use `tsx` with Node.js, pass it to the [`--loader`](https://nodejs.org/api/esm.html#loaders) flag.
94
109
 
95
- > Note: Node.js's experimental feature warnings will not be suppressed when used as a loader
110
+ > Note: Node.js's experimental feature warnings will not be suppressed when used as a loader.
96
111
 
97
112
  ```sh
98
113
  # As a CLI flag
@@ -102,15 +117,15 @@ node --loader tsx ./file.ts
102
117
  NODE_OPTIONS='--loader tsx' node ./file.ts
103
118
  ```
104
119
 
105
- > Tip: In rare circumstances, you might be limited to use the [`-r, --require`](https://nodejs.org/api/cli.html#-r---require-module) flag.
120
+ > Tip: In rare circumstances, you might be limited to using the [`-r, --require`](https://nodejs.org/api/cli.html#-r---require-module) flag.
106
121
  >
107
- > You can use [`@esbuild-kit/cjs-loader`](https://github.com/esbuild-kit/cjs-loader) but transformations will only be applied to `require()`.
122
+ > You can use [`@esbuild-kit/cjs-loader`](https://github.com/esbuild-kit/cjs-loader), but transformations will only be applied to `require()`.
108
123
 
109
124
  ## Dependencies
110
125
 
111
126
  - [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader) - Node.js Loader to transform TypeScript to ESM.
112
127
 
113
- - [@esbuild-kit/cjs-loader](https://github.com/esbuild-kit/cjs-loader) - Node.js `requie()` hook to transform TypeScript & ESM to CommonJS.
128
+ - [@esbuild-kit/cjs-loader](https://github.com/esbuild-kit/cjs-loader) - Node.js `require()` hook to transform TypeScript & ESM to CommonJS.
114
129
 
115
130
 
116
131
  ## FAQ
@@ -126,8 +141,10 @@ It's recommended to run TypeScript separately as a command (`tsc --noEmit`) or v
126
141
 
127
142
  They are both tools to run TypeScript files.
128
143
 
129
- 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).
144
+ 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).
145
+
146
+ Because esbuild doesn't do type checking, `tsx` is more equivalent to `ts-node --esm --transpileOnly`.
130
147
 
131
- Because esbuild doesn't do type checking, `tsx` is more equivalent to `ts-node --transpileOnly`.
148
+ [Here's an exhaustive comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx` vs `ts-node` (and other runtimes).
132
149
 
133
150
  If you migrated from `ts-node`, please share your performance gains [here](https://github.com/esbuild-kit/tsx/discussions/10)!