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 CHANGED
@@ -10,9 +10,13 @@
10
10
  - TypeScript REPL
11
11
  - Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
12
12
 
13
- > **💡 Protip: Looking to bundle your TypeScript project?**
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
- > If you're looking for a dead simple way to bundle your TypeScript projects, take a look at [`pkgroll`](https://github.com/privatenumber/pkgroll). It's an esbuild-enhanced Rollup that's auto configured based on your `package.json`!
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 `tsx`?
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 do type-checking?
358
+ ### Does it type check the code it runs?
344
359
 
345
- No, [esbuild does not support type checking](https://esbuild.github.io/faq/#:~:text=TypeScript%20type%20checking%20(just%20run%20tsc%20separately)).
360
+ No. tsx is designed to be a simple TypeScript runner.
346
361
 
347
- It's recommended to run TypeScript separately as a command (`tsc --noEmit`) or via [IDE IntelliSense](https://code.visualstudio.com/docs/languages/typescript).
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 so there is no configuration.
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
- Transformations are handled by esbuild, so it shares the same limitations such as:
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">
@@ -1 +1 @@
1
- "use strict";var f=require("path"),g=require("fs"),a=require("module"),l=require("get-tsconfig"),P=require("../source-map.cjs"),m=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{const[e,n]=m.parseEsm(s);return e.length>0||n.length>0}catch{return!0}return!1},O=/^\.{1,2}\//,M=/\.[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(),_=u&&l.createFilesMatcher(u),x=u&&l.createPathsMatcher(u),y=P.installSourceMapSupport(),d=a._extensions,N=d[".js"],R=[".cts",".mts",".ts",".tsx",".jsx"],b=[".js",".cjs",".mjs"];let v;q.connectingToServer.then(s=>{v=s},()=>{});const F=(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=g.readFileSync(e,"utf8");if(e.endsWith(".cjs")){const r=m.transformDynamicImport(e,t);r&&(t=y(r))}else if(n||E(t)){const r=m.transformSync(t,e,{tsconfigRaw:_==null?void 0:_(e)});t=y(r)}s._compile(t,e)};[".js",".ts",".tsx",".jsx"].forEach(s=>{d[s]=F}),Object.defineProperty(d,".mjs",{value:F,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&&!O.test(s)&&!((t=e==null?void 0:e.filename)!=null&&t.includes(A))){const i=x(s);for(const h of i){const p=S(h,e,n,o);if(p)return p;try{return T(h,e,n,o)}catch{}}}const c=S(s,e,n,o);return c||T(s,e,n,o)};const S=(s,e,n,o)=>{const t=j.resolveTsPath(s);if(e!=null&&e.filename&&M.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}};
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}};
@@ -1 +1 @@
1
- import f from"path";import F from"fs";import m from"module";import{parseTsconfig as S,getTsconfig as g,createFilesMatcher as j,createPathsMatcher as E}from"get-tsconfig";import{installSourceMapSupport as O}from"../source-map.mjs";import{p as P,t as M,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{const[s,r]=P(t);return s.length>0||r.length>0}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:S(process.env.TSX_TSCONFIG_PATH)}:g(),h=a&&j(a),_=a&&E(a),v=O(),l=m._extensions,G=l[".js"],H=[".cts",".mts",".ts",".tsx",".jsx"],X=[".js",".cjs",".mjs"];let p;R.then(t=>{p=t},()=>{});const x=(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=F.readFileSync(s,"utf8");if(s.endsWith(".cjs")){const o=M(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]=x}),Object.defineProperty(l,".mjs",{value:x,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=y(u,s,r,n);if(T)return T;try{return d(u,s,r,n)}catch{}}}const c=y(t,s,r,n);return c||d(t,s,r,n)};const y=(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}};
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}};