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 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, in both `commonjs` & `module` package types.
30
+ `tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM in both `commonjs` & `module` package types.
31
31
 
32
- It's powered by [esbuild](https://esbuild.github.io/) so it's insanely fast.
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
- Want to just run TypeScript code? Try tsx:
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
- tsx strives to:
44
- 1. Enhance Node.js with TypeScript compatibility
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
- You can reference it directly in the `package.json#scripts` object:
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
- `tsx` is designed to be a drop-in replacement for `node`, so you can use it just the way you would use Node.js. All command-line arguments (with the exception of a few) are propagated to Node.js.
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">
@@ -1 +1 @@
1
- "use strict";var S=require("path"),j=require("fs"),E=require("module"),i=require("get-tsconfig"),O=require("../source-map.cjs"),f=require("../index-cd956ba0.cjs"),M=require("../resolve-ts-path-43f50656.cjs");require("source-map-support"),require("../node-features-84a305a1.cjs"),require("url"),require("esbuild"),require("crypto"),require("os");function d(s){return s&&typeof s=="object"&&"default"in s?s:{default:s}}var m=d(S),q=d(j),l=d(E);const P=s=>{if(s.includes("import")||s.includes("export")){const[e,n]=f.parseEsm(s);return e.length>0||n.length>0}return!1},b=/^\.{1,2}\//,A=/\.[cm]?tsx?$/,N=`${m.default.sep}node_modules${m.default.sep}`,u=process.env.TSX_TSCONFIG_PATH?{path:m.default.resolve(process.env.TSX_TSCONFIG_PATH),config:i.parseTsconfig(process.env.TSX_TSCONFIG_PATH)}:i.getTsconfig(),h=u&&i.createFilesMatcher(u),x=u&&i.createPathsMatcher(u),y=O.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(t=>e.endsWith(t)),o=I.some(t=>e.endsWith(t));if(!n&&!o)return R(s,e);let r=q.default.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const t=f.transformDynamicImport(e,r);t&&(r=y(t,e))}else if(n||P(r)){const t=f.transformSync(r,e,{tsconfigRaw:h==null?void 0:h(e)});r=y(t,e)}s._compile(r,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 r;const t=s.indexOf("?");if(t!==-1&&(s=s.slice(0,t)),x&&!b.test(s)&&!((r=e==null?void 0:e.filename)!=null&&r.includes(N))){const a=x(s);for(const p of a){const T=g(p,e,n,o);if(T)return T;try{return _(p,e,n,o)}catch{}}}const c=g(s,e,n,o);return c||_(s,e,n,o)};const g=(s,e,n,o)=>{const r=M.resolveTsPath(s);if(e!=null&&e.filename&&A.test(e.filename)&&r)for(const t of r)try{return _(t,e,n,o)}catch(c){const{code:a}=c;if(a!=="MODULE_NOT_FOUND"&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
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}};
@@ -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-a3068c79.mjs";import{r as b}from"../resolve-ts-path-a8cb04a4.mjs";import"source-map-support";import"../node-features-a792cc3d.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}};
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}};