tsx 4.1.3 → 4.2.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
@@ -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
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).
88
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
 
@@ -1 +1 @@
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-6a8696ce.cjs"),O=require("../resolve-ts-path-43f50656.cjs");require("source-map-support"),require("../node-features-84a305a1.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
+ "use strict";var S=require("path"),j=require("fs"),E=require("module"),i=require("get-tsconfig"),O=require("../source-map.cjs"),f=require("../index-798b46f9.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 +1 @@
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-b858f597.mjs";import{r as N}from"../resolve-ts-path-a8cb04a4.mjs";import"source-map-support";import"../node-features-a792cc3d.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}};
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-a948fc61.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}};