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 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 latest major version of Node.js v12 and up _(likely to change in the future)_
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 `ESBK_TSCONFIG_PATH` environment variable:
107
+ Alternatively, use the `TSX_TSCONFIG_PATH` environment variable:
110
108
 
111
109
  ```sh
112
- ESBK_TSCONFIG_PATH=./path/to/tsconfig.custom.json tsx ./file.ts
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 [`--loader`](https://nodejs.org/api/esm.html#loaders) flag. This will add TypeScript & ESM support for both ESM and CommonJS contexts.
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 --loader tsx ./file.ts
163
+ node --import tsx ./file.ts
160
164
  ```
161
165
 
162
166
  Or as an environment variable:
163
167
  ```sh
164
- NODE_OPTIONS='--loader tsx' node ./file.ts
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
  ```
@@ -1 +1 @@
1
- "use strict";var y=require("path"),g=require("fs"),x=require("module"),i=require("get-tsconfig"),n=require("../source-map-13827956.cjs"),T=require("../index-d696346e.cjs"),E=require("../resolve-ts-path-43f50656.cjs");require("source-map-support"),require("url"),require("esbuild"),require("crypto"),require("os");function u(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var f=u(y),O=u(g),l=u(x);const P=/^\.{1,2}\//,M=/\.[cm]?tsx?$/,b=`${f.default.sep}node_modules${f.default.sep}`,d=process.env.ESBK_TSCONFIG_PATH?{path:f.default.resolve(process.env.ESBK_TSCONFIG_PATH),config:i.parseTsconfig(process.env.ESBK_TSCONFIG_PATH)}:i.getTsconfig(),h=d&&i.createFilesMatcher(d),F=d&&i.createPathsMatcher(d),N=n.installSourceMapSupport(),q=n.compareNodeVersion([13,2,0])>=0||n.compareNodeVersion([12,20,0])>=0&&n.compareNodeVersion([13,0,0])<0,m=l.default._extensions,A=m[".js"],R=[".js",".cjs",".cts",".mjs",".mts",".ts",".tsx",".jsx"],S=(s,e)=>{if(!R.some(o=>e.endsWith(o)))return A(s,e);process.send&&process.send({type:"dependency",path:e});let r=O.default.readFileSync(e,"utf8");if(e.endsWith(".cjs")&&q){const o=T.transformDynamicImport(e,r);o&&(r=N(o,e))}else{const o=T.transformSync(r,e,{tsconfigRaw:h==null?void 0:h(e)});r=N(o,e)}s._compile(r,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{m[s]=S}),Object.defineProperty(m,".mjs",{value:S,enumerable:!1});const D=n.compareNodeVersion([16,0,0])>=0||n.compareNodeVersion([14,18,0])>=0,p=l.default._resolveFilename.bind(l.default);l.default._resolveFilename=(s,e,t,r)=>{var o;if(!D&&s.startsWith("node:")&&(s=s.slice(5)),F&&!P.test(s)&&!((o=e==null?void 0:e.filename)!=null&&o.includes(b))){const a=F(s);for(const v of a){const _=j(v,e,t,r);if(_)return _;try{return p(v,e,t,r)}catch{}}}const c=j(s,e,t,r);return c||p(s,e,t,r)};const j=(s,e,t,r)=>{const o=E.resolveTsPath(s);if(e!=null&&e.filename&&M.test(e.filename)&&o)try{return p(o[0],e,t,r)}catch(c){const{code:a}=c;if(a!=="MODULE_NOT_FOUND"&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
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}};
@@ -1 +1 @@
1
- import l from"path";import S from"fs";import m from"module";import{parseTsconfig as j,getTsconfig as E,createFilesMatcher as x,createPathsMatcher as y}from"get-tsconfig";import{i as O,c}from"../source-map-53867ec2.mjs";import{a as N,b as P}from"../index-915aae05.mjs";import{r as g}from"../resolve-ts-path-a8cb04a4.mjs";import"source-map-support";import"url";import"esbuild";import"crypto";import"os";const b=/^\.{1,2}\//,A=/\.[cm]?tsx?$/,M=`${l.sep}node_modules${l.sep}`,a=process.env.ESBK_TSCONFIG_PATH?{path:l.resolve(process.env.ESBK_TSCONFIG_PATH),config:j(process.env.ESBK_TSCONFIG_PATH)}:E(),_=a&&x(a),T=a&&y(a),v=O(),R=c([13,2,0])>=0||c([12,20,0])>=0&&c([13,0,0])<0,f=m._extensions,I=f[".js"],C=[".js",".cjs",".cts",".mjs",".mts",".ts",".tsx",".jsx"],F=(o,s)=>{if(!C.some(t=>s.endsWith(t)))return I(o,s);process.send&&process.send({type:"dependency",path:s});let e=S.readFileSync(s,"utf8");if(s.endsWith(".cjs")&&R){const t=N(s,e);t&&(e=v(t,s))}else{const t=P(e,s,{tsconfigRaw:_==null?void 0:_(s)});e=v(t,s)}o._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(o=>{f[o]=F}),Object.defineProperty(f,".mjs",{value:F,enumerable:!1});const D=c([16,0,0])>=0||c([14,18,0])>=0,d=m._resolveFilename.bind(m);m._resolveFilename=(o,s,r,e)=>{var t;if(!D&&o.startsWith("node:")&&(o=o.slice(5)),T&&!b.test(o)&&!((t=s==null?void 0:s.filename)!=null&&t.includes(M))){const i=T(o);for(const p of i){const u=h(p,s,r,e);if(u)return u;try{return d(p,s,r,e)}catch{}}}const n=h(o,s,r,e);return n||d(o,s,r,e)};const h=(o,s,r,e)=>{const t=g(o);if(s!=null&&s.filename&&A.test(s.filename)&&t)try{return d(t[0],s,r,e)}catch(n){const{code:i}=n;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw n}};
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}};