tsx 3.13.0 → 3.14.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 +10 -3
- 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-5f60304b.cjs +22 -0
- package/dist/index-9eae64fa.mjs +22 -0
- package/dist/loader.cjs +1 -1
- package/dist/loader.mjs +1 -1
- package/dist/node-features-53cd96d9.mjs +1 -0
- package/dist/node-features-ecef9e7b.cjs +1 -0
- package/dist/package-15561fbc.mjs +1 -0
- package/dist/package-70ca1027.cjs +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 +1 -1
- package/dist/index-915aae05.mjs +0 -22
- 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-ecd0e331.cjs → pkgroll_create-require-3c9491e9.cjs} +0 -0
- /package/dist/{pkgroll_create-require-b777b06d.mjs → pkgroll_create-require-f1630a78.mjs} +0 -0
package/README.md
CHANGED
|
@@ -153,15 +153,15 @@ tsx --no-cache ./file.ts
|
|
|
153
153
|
|
|
154
154
|
`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
155
|
|
|
156
|
-
To use `tsx` as a Node.js loader, pass it in to the [`--
|
|
156
|
+
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
157
|
|
|
158
158
|
```sh
|
|
159
|
-
node --
|
|
159
|
+
node --import tsx ./file.ts
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
Or as an environment variable:
|
|
163
163
|
```sh
|
|
164
|
-
NODE_OPTIONS='--
|
|
164
|
+
NODE_OPTIONS='--import tsx' node ./file.ts
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
> **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 +170,13 @@ NODE_OPTIONS='--loader tsx' node ./file.ts
|
|
|
170
170
|
|
|
171
171
|
If you only need to add TypeScript support in a Module context, you can use the ESM loader:
|
|
172
172
|
|
|
173
|
+
##### Node.js v20.6.0 and above
|
|
174
|
+
```sh
|
|
175
|
+
node --import tsx/esm ./file.ts
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
##### Node.js v20.5.1 and below
|
|
179
|
+
|
|
173
180
|
```sh
|
|
174
181
|
node --loader tsx/esm ./file.ts
|
|
175
182
|
```
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=require("path"),x=require("fs"),E=require("module"),c=require("get-tsconfig"),O=require("../source-map.cjs"),p=require("../index-5f60304b.cjs"),P=require("../resolve-ts-path-43f50656.cjs"),T=require("../node-features-ecef9e7b.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 d=u(g),M=u(x),l=u(E);const q=/^\.{1,2}\//,N=/\.[cm]?tsx?$/,b=`${d.default.sep}node_modules${d.default.sep}`,i=process.env.ESBK_TSCONFIG_PATH?{path:d.default.resolve(process.env.ESBK_TSCONFIG_PATH),config:c.parseTsconfig(process.env.ESBK_TSCONFIG_PATH)}:c.getTsconfig(),h=i&&c.createFilesMatcher(i),F=i&&c.createPathsMatcher(i),S=O.installSourceMapSupport(),f=l.default._extensions,A=f[".js"],R=[".js",".cjs",".cts",".mjs",".mts",".ts",".tsx",".jsx"],j=(s,e)=>{if(!R.some(t=>e.endsWith(t)))return A(s,e);process.send&&process.send({type:"dependency",path:e});let r=M.default.readFileSync(e,"utf8");if(e.endsWith(".cjs")&&T.nodeSupportsImport){const t=p.transformDynamicImport(e,r);t&&(r=S(t,e))}else{const t=p.transformSync(r,e,{tsconfigRaw:h==null?void 0:h(e)});r=S(t,e)}s._compile(r,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{f[s]=j}),Object.defineProperty(f,".mjs",{value:j,enumerable:!1});const v=l.default._resolveFilename.bind(l.default);l.default._resolveFilename=(s,e,o,r)=>{var t;if(!T.supportsNodePrefix&&s.startsWith("node:")&&(s=s.slice(5)),F&&!q.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(b))){const a=F(s);for(const m of a){const _=y(m,e,o,r);if(_)return _;try{return v(m,e,o,r)}catch{}}}const n=y(s,e,o,r);return n||v(s,e,o,r)};const y=(s,e,o,r)=>{const t=P.resolveTsPath(s);if(e!=null&&e.filename&&N.test(e.filename)&&t)try{return v(t[0],e,o,r)}catch(n){const{code:a}=n;if(a!=="MODULE_NOT_FOUND"&&a!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw n}};
|
package/dist/cjs/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from"path";import h from"fs";import i from"module";import{parseTsconfig as S,getTsconfig as j,createFilesMatcher as E,createPathsMatcher as x}from"get-tsconfig";import{installSourceMapSupport as y}from"../source-map.mjs";import{a as O,b as P}from"../index-9eae64fa.mjs";import{r as b}from"../resolve-ts-path-a8cb04a4.mjs";import{a as g,b as N}from"../node-features-53cd96d9.mjs";import"source-map-support";import"url";import"esbuild";import"crypto";import"os";const A=/^\.{1,2}\//,M=/\.[cm]?tsx?$/,R=`${a.sep}node_modules${a.sep}`,m=process.env.ESBK_TSCONFIG_PATH?{path:a.resolve(process.env.ESBK_TSCONFIG_PATH),config:S(process.env.ESBK_TSCONFIG_PATH)}:j(),u=m&&E(m),_=m&&x(m),T=y(),l=i._extensions,I=l[".js"],C=[".js",".cjs",".cts",".mjs",".mts",".ts",".tsx",".jsx"],v=(o,s)=>{if(!C.some(t=>s.endsWith(t)))return I(o,s);process.send&&process.send({type:"dependency",path:s});let e=h.readFileSync(s,"utf8");if(s.endsWith(".cjs")&&N){const t=O(s,e);t&&(e=T(t,s))}else{const t=P(e,s,{tsconfigRaw:u==null?void 0:u(s)});e=T(t,s)}o._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(o=>{l[o]=v}),Object.defineProperty(l,".mjs",{value:v,enumerable:!1});const f=i._resolveFilename.bind(i);i._resolveFilename=(o,s,r,e)=>{var t;if(!g&&o.startsWith("node:")&&(o=o.slice(5)),_&&!A.test(o)&&!((t=s==null?void 0:s.filename)!=null&&t.includes(R))){const c=_(o);for(const p of c){const d=F(p,s,r,e);if(d)return d;try{return f(p,s,r,e)}catch{}}}const n=F(o,s,r,e);return n||f(o,s,r,e)};const F=(o,s,r,e)=>{const t=b(o);if(s!=null&&s.filename&&M.test(s.filename)&&t)try{return f(t[0],s,r,e)}catch(n){const{code:c}=n;if(c!=="MODULE_NOT_FOUND"&&c!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw n}};
|