Comparing version
{ | ||
"name": "tsx", | ||
"version": "4.1.2", | ||
"version": "4.7.0", | ||
"description": "TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript & ESM files", | ||
@@ -40,5 +40,4 @@ "keywords": [ | ||
"dependencies": { | ||
"esbuild": "~0.18.20", | ||
"get-tsconfig": "^4.7.2", | ||
"source-map-support": "^0.5.21" | ||
"esbuild": "~0.19.10", | ||
"get-tsconfig": "^4.7.2" | ||
}, | ||
@@ -45,0 +44,0 @@ "optionalDependencies": { |
163
README.md
@@ -13,5 +13,9 @@ # tsx <a href="https://npm.im/tsx"><img src="https://badgen.net/npm/v/tsx"></a> <a href="https://npm.im/tsx"><img src="https://badgen.net/npm/dm/tsx"></a> <a href="https://packagephobia.now.sh/result?p=tsx"><img src="https://packagephobia.now.sh/badge?p=tsx"></a> | ||
> **💡 Protip: Looking to bundle your TypeScript project?** | ||
> [!TIP] | ||
> **Do you need to compile your TypeScript projects?** Try [pkgroll](https://github.com/privatenumber/pkgroll)—the zero-config bundler _tsx_ uses! | ||
> | ||
> 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`! | ||
> _pkgroll_ is a thin layer over Rollup that auto-configures it based on your `package.json` entry points. | ||
> | ||
> It supports next-gen TS formats, export maps, `.d.ts` generation, and more! | ||
@@ -31,8 +35,24 @@ <br> | ||
## About | ||
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM, in both `commonjs` & `module` package types. | ||
`tsx` is a CLI command (alternative to `node`) for seamlessly running TypeScript & ESM in both `commonjs` & `module` package types. | ||
It's powered by [esbuild](https://esbuild.github.io/) so it's insanely fast. | ||
This is for you if you ever wanted: | ||
- A command that can _just run_ TypeScript code without dealing with configuration | ||
- Better interoperability in codebases that use ESM and CJS dependencies | ||
- Something really fast it's unnoticeable! | ||
Want to just run TypeScript code? Try tsx: | ||
> [!TIP] | ||
> **tsx is not just for TypeScript!** It also helps Node load `module` type packages. | ||
> | ||
> If you're getting the following error, give _tsx_ a try! | ||
> ``` | ||
> require('ESM package'); | ||
> ^ | ||
> | ||
> Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported. | ||
> Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules. | ||
> ``` | ||
### Quick start | ||
Try tsx now without setup! Just pass in a TypeScript file: | ||
```sh | ||
@@ -42,8 +62,5 @@ npx tsx ./script.ts | ||
How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkout the [comparison](https://github.com/privatenumber/ts-runtime-comparison). | ||
### Mission | ||
tsx strives to: | ||
1. Enhance Node.js with TypeScript compatibility | ||
2. Improve ESM <-> CJS interoperability | ||
1. Enhance Node.js with TypeScript support | ||
2. Improve ESM <-> CJS interoperability as the ecosystem migrates to ESM | ||
3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs) | ||
@@ -59,3 +76,3 @@ | ||
You can reference it directly in the `package.json#scripts` object: | ||
Then you can reference it directly in the `package.json#scripts` object (you don't need npx here): | ||
```json5 | ||
@@ -91,5 +108,11 @@ { | ||
`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. | ||
### tsx is a Node.js wrapper | ||
_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). | ||
```sh | ||
# --no-warnings is a Node.js flag | ||
tsx --no-warnings ./file.ts | ||
``` | ||
### Run TypeScript / ESM / CJS module | ||
@@ -224,2 +247,92 @@ | ||
### VS Code debugging | ||
#### Setup | ||
Create the following configuration file in your project to setup debugging in VS Code: | ||
`.vscode/launch.json` | ||
```json5 | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
/* | ||
Each config in this array is an option in the debug drop-down | ||
See below for configurations to add... | ||
*/ | ||
], | ||
} | ||
``` | ||
#### Debugging method 1: Run tsx directly from VSCode | ||
1. Add the following configuration to the `configurations` array in `.vscode/launch.json`: | ||
```json5 | ||
{ | ||
"name": "tsx", | ||
"type": "node", | ||
"request": "launch", | ||
// Debug current file in VSCode | ||
"program": "${file}", | ||
/* | ||
Path to tsx binary | ||
Assuming locally installed | ||
*/ | ||
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/tsx", | ||
/* | ||
Open terminal when debugging starts (Optional) | ||
Useful to see console.logs | ||
*/ | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
// Files to exclude from debugger (e.g. call stack) | ||
"skipFiles": [ | ||
// Node.js internal core modules | ||
"<node_internals>/**", | ||
// Ignore all dependencies (optional) | ||
"${workspaceFolder}/node_modules/**", | ||
], | ||
} | ||
``` | ||
2. In VSCode, open the file you want to run | ||
3. Go to VSCode's debug panel, select "tsx" in the drop down, and hit the play button (<kbd>F5</kbd>). | ||
#### Debugging method 2: Attach to a running Node.js process | ||
> This method works for any Node.js process and it's not specific to tsx | ||
1. Add the following configuration to the `configurations` array in `.vscode/launch.json`: | ||
```json | ||
{ | ||
"name": "Attach to process", | ||
"type": "node", | ||
"request": "attach", | ||
"port": 9229, | ||
"skipFiles": [ | ||
// Node.js internal core modules | ||
"<node_internals>/**", | ||
// Ignore all dependencies (optional) | ||
"${workspaceFolder}/node_modules/**", | ||
], | ||
} | ||
``` | ||
2. Run tsx with `--inspect-brk` in a terminal window: | ||
```sh | ||
tsx --inspect-brk ./your-file.ts | ||
``` | ||
3. Go to VSCode's debug panel, select "Attach to process" in the drop down, and hit the play button (<kbd>F5</kbd>). | ||
See the [VSCode documentation on _Launch Configuration_](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration) for more information. | ||
<br> | ||
@@ -243,3 +356,3 @@ | ||
### Why is it named `tsx`? | ||
### Why is it named _tsx_? | ||
@@ -252,7 +365,7 @@ `tsx` stands for "TypeScript execute". Mirroring [`npx`](https://docs.npmjs.com/cli/v8/commands/npx), which stands for "Node.js package execute". | ||
### Does it do type-checking? | ||
### Does it type check the code it runs? | ||
No, [esbuild does not support type checking](https://esbuild.github.io/faq/#:~:text=TypeScript%20type%20checking%20(just%20run%20tsc%20separately)). | ||
No. tsx is designed to be a simple TypeScript runner. | ||
It's recommended to run TypeScript separately as a command (`tsc --noEmit`) or via [IDE IntelliSense](https://code.visualstudio.com/docs/languages/typescript). | ||
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. | ||
@@ -284,13 +397,9 @@ | ||
### Can it use esbuild plugins? | ||
No. tsx uses esbuild's [Transform API](https://esbuild.github.io/api/#transform-api), which doesn't support plugins. | ||
### Does it have a configuration file? | ||
No. tsx's integration with Node.js is designed to be seamless so there is no configuration. | ||
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. | ||
### Does it have any limitations? | ||
Transformations are handled by esbuild, so it shares the same limitations such as: | ||
TypeScript & ESM transformations are handled by [esbuild](https://esbuild.github.io/), so it shares the same limitations such as: | ||
@@ -303,12 +412,2 @@ - Compatibility with code executed via `eval()` is not preserved | ||
### Does Yarn PnP work? | ||
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. | ||
### There's an outdated dependency in tsx—can you update? | ||
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. | ||
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. | ||
## Sponsors | ||
@@ -315,0 +414,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 4 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
393583
1.6%3
-25%35
20.69%1559
0.52%428
30.09%16
300%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated