tsx 3.13.0 → 4.0.0
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 +19 -8
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.mjs +1 -1
- package/dist/cli.cjs +22 -22
- package/dist/cli.mjs +22 -22
- package/dist/esm/index.cjs +13 -1
- package/dist/esm/index.mjs +13 -1
- package/dist/index-5ae6ac30.cjs +14 -0
- package/dist/{index-915aae05.mjs → index-dcf242e7.mjs} +10 -18
- package/dist/loader.cjs +1 -1
- package/dist/loader.mjs +1 -1
- package/dist/node-features-18fdd9fd.mjs +1 -0
- package/dist/node-features-72f7f76d.cjs +1 -0
- package/dist/package-1cb7ac5f.cjs +1 -0
- package/dist/package-eb460814.mjs +1 -0
- package/dist/preflight.cjs +1 -1
- package/dist/preflight.mjs +1 -1
- package/dist/repl.cjs +1 -1
- package/dist/repl.mjs +1 -1
- package/dist/source-map.cjs +2 -1
- package/dist/source-map.mjs +2 -1
- package/package.json +5 -2
- package/dist/index-d696346e.cjs +0 -22
- package/dist/loaders-deprecated-261ba186.mjs +0 -12
- package/dist/loaders-deprecated-630b2616.cjs +0 -12
- package/dist/package-362913cd.mjs +0 -1
- package/dist/package-83943f92.cjs +0 -1
- package/dist/source-map-13827956.cjs +0 -2
- package/dist/source-map-53867ec2.mjs +0 -2
- /package/dist/{pkgroll_create-require-b777b06d.mjs → pkgroll_create-require-77731cc2.mjs} +0 -0
- /package/dist/{pkgroll_create-require-ecd0e331.cjs → pkgroll_create-require-cc577b16.cjs} +0 -0
package/README.md
CHANGED
|
@@ -6,11 +6,9 @@
|
|
|
6
6
|
- Blazing fast on-demand TypeScript & ESM compilation
|
|
7
7
|
- Works in both [CommonJS and ESM packages](https://nodejs.org/api/packages.html#type)
|
|
8
8
|
- Supports next-gen TypeScript extensions (`.cts` & `.mts`)
|
|
9
|
-
- Supports `node:` import prefixes
|
|
10
9
|
- Hides experimental feature warnings
|
|
11
10
|
- TypeScript REPL
|
|
12
11
|
- Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
|
|
13
|
-
- Tested on Linux & Windows with Node.js v12~20
|
|
14
12
|
|
|
15
13
|
> **💡 Protip: Looking to bundle your TypeScript project?**
|
|
16
14
|
>
|
|
@@ -45,7 +43,7 @@ How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkou
|
|
|
45
43
|
tsx strives to:
|
|
46
44
|
1. Enhance Node.js with TypeScript compatibility
|
|
47
45
|
2. Improve ESM <-> CJS interoperability
|
|
48
|
-
3. Support the
|
|
46
|
+
3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs)
|
|
49
47
|
|
|
50
48
|
## Install
|
|
51
49
|
|
|
@@ -106,10 +104,10 @@ To set a custom path, use the `--tsconfig` flag:
|
|
|
106
104
|
tsx --tsconfig ./path/to/tsconfig.custom.json ./file.ts
|
|
107
105
|
```
|
|
108
106
|
|
|
109
|
-
Alternatively, use the `
|
|
107
|
+
Alternatively, use the `TSX_TSCONFIG_PATH` environment variable:
|
|
110
108
|
|
|
111
109
|
```sh
|
|
112
|
-
|
|
110
|
+
TSX_TSCONFIG_PATH=./path/to/tsconfig.custom.json tsx ./file.ts
|
|
113
111
|
```
|
|
114
112
|
|
|
115
113
|
### Watch mode
|
|
@@ -149,19 +147,25 @@ Set the `--no-cache` flag to disable the cache:
|
|
|
149
147
|
tsx --no-cache ./file.ts
|
|
150
148
|
```
|
|
151
149
|
|
|
150
|
+
Alternatively, use the `TSX_DISABLE_CACHE` environment variable:
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
TSX_DISABLE_CACHE=1 tsx ./file.ts
|
|
154
|
+
```
|
|
155
|
+
|
|
152
156
|
### Node.js Loader
|
|
153
157
|
|
|
154
158
|
`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.
|
|
155
159
|
|
|
156
|
-
To use `tsx` as a Node.js loader, pass it in to the [`--
|
|
160
|
+
To use `tsx` as a Node.js loader, pass it in to the [`--import`](https://nodejs.org/api/module.html#enabling) flag. This will add TypeScript & ESM support for both Module and CommonJS contexts.
|
|
157
161
|
|
|
158
162
|
```sh
|
|
159
|
-
node --
|
|
163
|
+
node --import tsx ./file.ts
|
|
160
164
|
```
|
|
161
165
|
|
|
162
166
|
Or as an environment variable:
|
|
163
167
|
```sh
|
|
164
|
-
NODE_OPTIONS='--
|
|
168
|
+
NODE_OPTIONS='--import tsx' node ./file.ts
|
|
165
169
|
```
|
|
166
170
|
|
|
167
171
|
> **Note:** The loader is limited to adding support for loading TypeScript/ESM files. CLI features such as _watch mode_ or suppressing "experimental feature" warnings will not be available.
|
|
@@ -170,6 +174,13 @@ NODE_OPTIONS='--loader tsx' node ./file.ts
|
|
|
170
174
|
|
|
171
175
|
If you only need to add TypeScript support in a Module context, you can use the ESM loader:
|
|
172
176
|
|
|
177
|
+
##### Node.js v20.6.0 and above
|
|
178
|
+
```sh
|
|
179
|
+
node --import tsx/esm ./file.ts
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
##### Node.js v20.5.1 and below
|
|
183
|
+
|
|
173
184
|
```sh
|
|
174
185
|
node --loader tsx/esm ./file.ts
|
|
175
186
|
```
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=require("path"),M=require("fs"),E=require("module"),i=require("get-tsconfig"),f=require("../source-map.cjs"),d=require("../index-5ae6ac30.cjs"),O=require("../resolve-ts-path-43f50656.cjs");require("source-map-support"),require("../node-features-72f7f76d.cjs"),require("url"),require("esbuild"),require("crypto"),require("os");function m(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var p=m(j),q=m(M),l=m(E);const P=s=>{if(s.includes("import")||s.includes("export")){const[e,n]=d.parseEsm(s);return e.length>0||n.length>0}return!1},b=/^\.{1,2}\//,A=/\.[cm]?tsx?$/,N=`${p.default.sep}node_modules${p.default.sep}`,u=process.env.TSX_TSCONFIG_PATH?{path:p.default.resolve(process.env.TSX_TSCONFIG_PATH),config:i.parseTsconfig(process.env.TSX_TSCONFIG_PATH)}:i.getTsconfig(),S=u&&i.createFilesMatcher(u),x=u&&i.createPathsMatcher(u),y=f.installSourceMapSupport(),v=l.default._extensions,R=v[".js"],D=[".cts",".mts",".ts",".tsx",".jsx"],I=[".js",".cjs",".mjs"],F=(s,e)=>{process.send&&process.send({type:"dependency",path:e});const n=D.some(r=>e.endsWith(r)),o=I.some(r=>e.endsWith(r));if(!n&&!o)return R(s,e);let t=q.default.readFileSync(e,"utf8");if(f.shouldStripSourceMap&&(t=f.stripSourceMap(t)),e.endsWith(".cjs")){const r=d.transformDynamicImport(e,t);r&&(t=y(r,e))}else if(n||P(t)){const r=d.transformSync(t,e,{tsconfigRaw:S==null?void 0:S(e)});t=y(r,e)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{v[s]=F}),Object.defineProperty(v,".mjs",{value:F,enumerable:!1});const _=l.default._resolveFilename.bind(l.default);l.default._resolveFilename=(s,e,n,o)=>{var t;const r=s.indexOf("?");if(r!==-1&&(s=s.slice(0,r)),x&&!b.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(N))){const a=x(s);for(const T of a){const h=g(T,e,n,o);if(h)return h;try{return _(T,e,n,o)}catch{}}}const c=g(s,e,n,o);return c||_(s,e,n,o)};const g=(s,e,n,o)=>{const t=O.resolveTsPath(s);if(e!=null&&e.filename&&A.test(e.filename)&&t)for(const r of t)try{return _(r,e,n,o)}catch(c){const{code:a}=c;if(a!=="MODULE_NOT_FOUND"&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
|
package/dist/cjs/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import f from"path";import x from"fs";import m from"module";import{parseTsconfig as F,getTsconfig as y,createFilesMatcher as j,createPathsMatcher as E}from"get-tsconfig";import{installSourceMapSupport as O,shouldStripSourceMap as g,stripSourceMap as M}from"../source-map.mjs";import{p as P,a as b,b as A}from"../index-dcf242e7.mjs";import{r as N}from"../resolve-ts-path-a8cb04a4.mjs";import"source-map-support";import"../node-features-18fdd9fd.mjs";import"url";import"esbuild";import"crypto";import"os";const R=o=>{if(o.includes("import")||o.includes("export")){const[s,r]=P(o);return s.length>0||r.length>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)}:y(),T=a&&j(a),_=a&&E(a),v=O(),l=m._extensions,G=l[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"],h=(o,s)=>{process.send&&process.send({type:"dependency",path:s});const r=H.some(e=>s.endsWith(e)),n=X.some(e=>s.endsWith(e));if(!r&&!n)return G(o,s);let t=x.readFileSync(s,"utf8");if(g&&(t=M(t)),s.endsWith(".cjs")){const e=b(s,t);e&&(t=v(e,s))}else if(r||R(t)){const e=A(t,s,{tsconfigRaw:T==null?void 0:T(s)});t=v(e,s)}o._compile(t,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,r,n)=>{var t;const e=o.indexOf("?");if(e!==-1&&(o=o.slice(0,e)),_&&!I.test(o)&&!((t=s==null?void 0:s.filename)!=null&&t.includes(D))){const i=_(o);for(const d of i){const u=S(d,s,r,n);if(u)return u;try{return p(d,s,r,n)}catch{}}}const c=S(o,s,r,n);return c||p(o,s,r,n)};const S=(o,s,r,n)=>{const t=N(o);if(s!=null&&s.filename&&C.test(s.filename)&&t)for(const e of t)try{return p(e,s,r,n)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
|