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 +18 -10
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.mjs +1 -1
- package/dist/cli.cjs +24 -24
- package/dist/cli.mjs +24 -24
- package/dist/esm/index.cjs +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/{index-6a8696ce.cjs → index-798b46f9.cjs} +10 -10
- package/dist/{index-b858f597.mjs → index-a948fc61.mjs} +10 -10
- package/dist/loader.cjs +1 -1
- package/dist/loader.mjs +1 -1
- package/dist/package-a7e4efe9.cjs +1 -0
- package/dist/package-c3cf89e0.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 -3
- package/dist/source-map.mjs +2 -3
- package/package.json +1 -1
- package/dist/package-11bc6009.mjs +0 -1
- package/dist/package-d0720f8f.cjs +0 -1
- /package/dist/{pkgroll_create-require-b1422635.mjs → pkgroll_create-require-82fe4d50.mjs} +0 -0
- /package/dist/{pkgroll_create-require-22777494.cjs → pkgroll_create-require-a306261c.cjs} +0 -0
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
|
|
30
|
+
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM in both `commonjs` & `module` package types.
|
|
31
31
|
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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}};
|
package/dist/cjs/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import f from"path";import
|
|
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}};
|