tsx 4.6.1 → 4.7.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 +24 -23
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.mjs +1 -1
- package/dist/cli.cjs +12 -12
- package/dist/cli.mjs +26 -26
- package/dist/esm/index.cjs +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/loader.cjs +1 -1
- package/dist/loader.mjs +1 -1
- package/dist/node-features-c450ed54.cjs +1 -0
- package/dist/node-features-fb266590.mjs +1 -0
- package/dist/package-22dbf202.cjs +1 -0
- package/dist/package-a2d7442c.mjs +1 -0
- package/dist/repl.cjs +1 -1
- package/dist/repl.mjs +1 -1
- package/package.json +2 -2
- package/dist/node-features-6a939068.mjs +0 -1
- package/dist/node-features-92fd0e3b.cjs +0 -1
- package/dist/package-126ef1cf.mjs +0 -1
- package/dist/package-48ff69ab.cjs +0 -1
package/README.md
CHANGED
|
@@ -10,9 +10,13 @@
|
|
|
10
10
|
- TypeScript REPL
|
|
11
11
|
- Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
> [!TIP]
|
|
15
|
+
> **Do you need to compile your TypeScript projects?** Try [pkgroll](https://github.com/privatenumber/pkgroll)—the zero-config bundler _tsx_ uses!
|
|
14
16
|
>
|
|
15
|
-
>
|
|
17
|
+
> _pkgroll_ is a thin layer over Rollup that auto-configures it based on your `package.json` entry points.
|
|
18
|
+
>
|
|
19
|
+
> It supports next-gen TS formats, export maps, `.d.ts` generation, and more!
|
|
16
20
|
|
|
17
21
|
<br>
|
|
18
22
|
|
|
@@ -34,6 +38,18 @@ This is for you if you ever wanted:
|
|
|
34
38
|
- Better interoperability in codebases that use ESM and CJS dependencies
|
|
35
39
|
- Something really fast it's unnoticeable!
|
|
36
40
|
|
|
41
|
+
> [!TIP]
|
|
42
|
+
> **tsx is not just for TypeScript!** It also helps Node load `module` type packages.
|
|
43
|
+
>
|
|
44
|
+
> If you're getting the following error, give _tsx_ a try!
|
|
45
|
+
> ```
|
|
46
|
+
> require('ESM package');
|
|
47
|
+
> ^
|
|
48
|
+
>
|
|
49
|
+
> Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported.
|
|
50
|
+
> Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules.
|
|
51
|
+
> ```
|
|
52
|
+
|
|
37
53
|
### Quick start
|
|
38
54
|
Try tsx now without setup! Just pass in a TypeScript file:
|
|
39
55
|
|
|
@@ -46,7 +62,6 @@ npx tsx ./script.ts
|
|
|
46
62
|
2. Improve ESM <-> CJS interoperability as the ecosystem migrates to ESM
|
|
47
63
|
3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs)
|
|
48
64
|
|
|
49
|
-
|
|
50
65
|
## Install
|
|
51
66
|
|
|
52
67
|
### Local installation
|
|
@@ -332,7 +347,7 @@ If there's a problem you're encountering or something you need help with, don't
|
|
|
332
347
|
|
|
333
348
|
## FAQ
|
|
334
349
|
|
|
335
|
-
### Why is it named
|
|
350
|
+
### Why is it named _tsx_?
|
|
336
351
|
|
|
337
352
|
`tsx` stands for "TypeScript execute". Mirroring [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), which stands for "Node.js package execute".
|
|
338
353
|
|
|
@@ -340,11 +355,11 @@ The 3-character package name offers an elegant developer experience, allowing us
|
|
|
340
355
|
|
|
341
356
|
Unfortunately, it overlaps with React's [TSX/JSX](https://www.typescriptlang.org/docs/handbook/jsx.html), which stands for "TypeScript XML".
|
|
342
357
|
|
|
343
|
-
### Does it
|
|
358
|
+
### Does it type check the code it runs?
|
|
344
359
|
|
|
345
|
-
No
|
|
360
|
+
No. tsx is designed to be a simple TypeScript runner.
|
|
346
361
|
|
|
347
|
-
|
|
362
|
+
If you need type-checking, you can use an IDE like [VS Code](https://code.visualstudio.com) and it will type-check as you code via [IntelliSense](https://code.visualstudio.com/docs/languages/typescript). Alternatively, you can run the TypeScript Compiler only for type-checking (e.g. `tsc --noEmit`) as a linting step.
|
|
348
363
|
|
|
349
364
|
|
|
350
365
|
### How is `tsx` different from [`ts-node`](https://github.com/TypeStrong/ts-node)?
|
|
@@ -371,17 +386,13 @@ As a bonus, tsx also comes with a watcher to speed up your development.
|
|
|
371
386
|
|
|
372
387
|
[Here's an exhaustive technical comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx`, `ts-node`, and other runtimes.
|
|
373
388
|
|
|
374
|
-
### Can it use esbuild plugins?
|
|
375
|
-
|
|
376
|
-
No. tsx uses esbuild's [Transform API](https://esbuild.github.io/api/#transform-api), which doesn't support plugins.
|
|
377
|
-
|
|
378
389
|
### Does it have a configuration file?
|
|
379
390
|
|
|
380
|
-
No. tsx's integration with Node.js is designed to be seamless
|
|
391
|
+
No. tsx's integration with Node.js is designed to be simple & seamless. However, it supports a few properties from `tsconfig.json` to determine how to compile TypeScript files.
|
|
381
392
|
|
|
382
393
|
### Does it have any limitations?
|
|
383
394
|
|
|
384
|
-
|
|
395
|
+
TypeScript & ESM transformations are handled by [esbuild](https://esbuild.github.io/), so it shares the same limitations such as:
|
|
385
396
|
|
|
386
397
|
- Compatibility with code executed via `eval()` is not preserved
|
|
387
398
|
- Only [certain `tsconfig.json` properties](https://esbuild.github.io/content-types/#tsconfig-json) are supported
|
|
@@ -389,16 +400,6 @@ Transformations are handled by esbuild, so it shares the same limitations such a
|
|
|
389
400
|
|
|
390
401
|
For details, refer to esbuild's [JavaScript caveats](https://esbuild.github.io/content-types/#javascript-caveats) and [TypeScript caveats](https://esbuild.github.io/content-types/#typescript-caveats) documentation.
|
|
391
402
|
|
|
392
|
-
### Does Yarn PnP work?
|
|
393
|
-
|
|
394
|
-
In CommonJS mode, yes. But in Module/ESM mode, [Node.js version v19.6.0 and up](https://github.com/nodejs/node/blob/v19.6.0/doc/changelogs/CHANGELOG_V19.md#esm-leverage-loaders-when-resolving-subsequent-loaders) is required.
|
|
395
|
-
|
|
396
|
-
### There's an outdated dependency in tsx—can you update?
|
|
397
|
-
|
|
398
|
-
Dependencies are typically declared with SemVer ranges to allow updates. You can use the [`npm update <package name>`](https://docs.npmjs.com/cli/v8/commands/npm-update) command to automatically update them to the latest version within the defined range.
|
|
399
|
-
|
|
400
|
-
If the dependencies are out of the specified range, it indicates a potential breaking change that requires manual review. You're welcome to submit a pull request to initiate the upgrade.
|
|
401
|
-
|
|
402
403
|
## Sponsors
|
|
403
404
|
|
|
404
405
|
<p align="center">
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=require("path"),
|
|
1
|
+
"use strict";var f=require("path"),P=require("fs"),a=require("module"),l=require("get-tsconfig"),g=require("../source-map.cjs"),d=require("../index-5d1f01e6.cjs"),j=require("../resolve-ts-path-3fca13b7.cjs"),q=require("../client-2f0df4a6.cjs");require("url"),require("esbuild"),require("crypto"),require("os"),require("../temporary-directory-2a027842.cjs"),require("net"),require("../get-pipe-path-86e97fc9.cjs");const E=s=>{if(s.includes("import")||s.includes("export"))try{return d.parseEsm(s)[3]}catch{return!0}return!1},M=/^\.{1,2}\//,O=/\.[cm]?tsx?$/,A=`${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(),p=u&&l.createFilesMatcher(u),x=u&&l.createPathsMatcher(u),y=g.installSourceMapSupport(),m=a._extensions,N=m[".js"],R=[".cts",".mts",".ts",".tsx",".jsx"],b=[".js",".cjs",".mjs"];let v;q.connectingToServer.then(s=>{v=s},()=>{});const S=(s,e)=>{v&&v({type:"dependency",path:e});const n=R.some(r=>e.endsWith(r)),o=b.some(r=>e.endsWith(r));if(!n&&!o)return N(s,e);let t=P.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const r=d.transformDynamicImport(e,t);r&&(t=y(r))}else if(n||E(t)){const r=d.transformSync(t,e,{tsconfigRaw:p==null?void 0:p(e)});t=y(r)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{m[s]=S}),Object.defineProperty(m,".mjs",{value:S,enumerable:!1});const T=a._resolveFilename.bind(a);a._resolveFilename=(s,e,n,o)=>{var t;const r=s.indexOf("?");if(r!==-1&&(s=s.slice(0,r)),x&&!M.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(A))){const i=x(s);for(const h of i){const _=F(h,e,n,o);if(_)return _;try{return T(h,e,n,o)}catch{}}}const c=F(s,e,n,o);return c||T(s,e,n,o)};const F=(s,e,n,o)=>{const t=j.resolveTsPath(s);if(e!=null&&e.filename&&O.test(e.filename)&&t)for(const r of t)try{return T(r,e,n,o)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="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 x from"fs";import m from"module";import{parseTsconfig as F,getTsconfig as j,createFilesMatcher as E,createPathsMatcher as O}from"get-tsconfig";import{installSourceMapSupport as P}from"../source-map.mjs";import{p as M,t as g,a as A}from"../index-bd1ceb03.mjs";import{r as N}from"../resolve-ts-path-eb3847f5.mjs";import{c as R}from"../client-e665d820.mjs";import"url";import"esbuild";import"crypto";import"os";import"../temporary-directory-04b36185.mjs";import"net";import"../get-pipe-path-b74d9893.mjs";const b=t=>{if(t.includes("import")||t.includes("export"))try{return M(t)[3]}catch{return!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)}:j(),h=a&&E(a),_=a&&O(a),v=P(),l=m._extensions,G=l[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"];let p;R.then(t=>{p=t},()=>{});const y=(t,s)=>{p&&p({type:"dependency",path:s});const r=H.some(o=>s.endsWith(o)),n=X.some(o=>s.endsWith(o));if(!r&&!n)return G(t,s);let e=x.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const o=g(s,e);o&&(e=v(o))}else if(r||b(e)){const o=A(e,s,{tsconfigRaw:h==null?void 0:h(s)});e=v(o)}t._compile(e,s)};[".js",".ts",".tsx",".jsx"].forEach(t=>{l[t]=y}),Object.defineProperty(l,".mjs",{value:y,enumerable:!1});const d=m._resolveFilename.bind(m);m._resolveFilename=(t,s,r,n)=>{var e;const o=t.indexOf("?");if(o!==-1&&(t=t.slice(0,o)),_&&!I.test(t)&&!((e=s==null?void 0:s.filename)!=null&&e.includes(D))){const i=_(t);for(const u of i){const T=S(u,s,r,n);if(T)return T;try{return d(u,s,r,n)}catch{}}}const c=S(t,s,r,n);return c||d(t,s,r,n)};const S=(t,s,r,n)=>{const e=N(t);if(s!=null&&s.filename&&C.test(s.filename)&&e)for(const o of e)try{return d(o,s,r,n)}catch(c){const{code:i}=c;if(i!=="MODULE_NOT_FOUND"&&i!=="ERR_PACKAGE_PATH_NOT_EXPORTED")throw c}};
|