Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: privatenumber/tsx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.8.2
Choose a base ref
...
head repository: privatenumber/tsx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.9.0
Choose a head ref
  • 5 commits
  • 5 files changed
  • 2 contributors

Commits on Aug 22, 2022

  1. Copy the full SHA
    d75b0ba View commit details

Commits on Aug 25, 2022

  1. docs: wording

    privatenumber authored Aug 25, 2022
    Copy the full SHA
    b77328f View commit details

Commits on Aug 29, 2022

  1. Copy the full SHA
    f4b23df View commit details
  2. Copy the full SHA
    034fb7f View commit details
  3. ci: use pnpm

    privatenumber committed Aug 29, 2022
    Copy the full SHA
    afde758 View commit details
Showing with 42 additions and 17 deletions.
  1. +7 −4 .github/workflows/release.yml
  2. +7 −4 .github/workflows/test.yml
  3. +16 −5 README.md
  4. +5 −4 package.json
  5. +7 −0 pnpm-lock.yaml
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -19,14 +19,17 @@ jobs:
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npx ci
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 7
run_install: true

- name: Lint
run: npm run lint
run: pnpm lint

- name: Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
run: pnpx semantic-release
11 changes: 7 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -22,12 +22,15 @@ jobs:
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npx ci
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.2
with:
version: 7
run_install: true

- name: Test
run: npm test
run: pnpm test

- name: Lint
if: ${{ matrix.os == 'ubuntu-latest' }}
run: npm run lint
run: pnpm lint
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -161,16 +161,27 @@ It's recommended to run TypeScript separately as a command (`tsc --noEmit`) or v

### How is `tsx` different from [`ts-node`](https://github.com/TypeStrong/ts-node)?

They are both tools to run TypeScript files.
They're both tools to run TypeScript files. But tsx does a lot more to improve the experience of using Node.js.

The main difference is that `tsx` is powered by [esbuild](https://esbuild.github.io/) for blazing fast TypeScript compilation, whereas `ts-node` uses the TypeScript compiler, [which is not as fast](https://esbuild.github.io/faq/#:~:text=typescript%20benchmark).
tsx _just works_. It's zero-config and doesn't require `tsconfig.json` to get started, making it easy for users that just want to run TypeScript code and not get caught up in the configuration.

Because esbuild doesn't do type checking, `tsx` is more equivalent to `ts-node --esm --transpileOnly`.
It's a single binary with no peer-dependencies (e.g. TypeScript or esbuild), so there is no setup necessary, enabling usage that is elegant and frictionless for first-time users:

[Here's an exhaustive comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx` vs `ts-node` (and other runtimes).
```
npx tsx ./script.ts
```

tsx is zero-config because it has smart detections built in. As a runtime, it detects what's imported to make many options in `tsconfig.json` redundant—which was designed for compiling matching files regardless of whether they're imported.

It seamlessly adapts between CommonJS and ESM package types by detecting how modules are loaded (`require()` or `import`) to determine how to compile them. It even adds support for `require()`ing ESM modules from CommonJS so you don't have to worry about your dependencies as the ecosystem migrates to ESM.

[Newer and unsupported syntax](https://esbuild.github.io/content-types/) & features like [importing `node:` prefixes](https://2ality.com/2021/12/node-protocol-imports.html) are downgraded by detecting the Node.js version. For large TypeScript codebases, it has [`tsconfig.json paths`](https://www.typescriptlang.org/tsconfig#paths) aliasing support out of the box.

At the core, tsx is powered by esbuild for [blazing fast TypeScript compilation](https://esbuild.github.io/faq/#:~:text=typescript%20benchmark), whereas `ts-node` (by default) uses the TypeScript compiler. Because esbuild doesn't type check, `tsx` is similar to `ts-node --esm --swc` (which uses the [SWC compiler](https://github.com/TypeStrong/ts-node#swc-1)).

If you migrated from `ts-node`, please share your performance gains [here](https://github.com/esbuild-kit/tsx/discussions/10)!
As a bonus, tsx also comes with a watcher to speed up your development.

[Here's an exhaustive technical comparison](https://github.com/privatenumber/ts-runtime-comparison) between `tsx`, `ts-node`, and other runtimes.

### Can it use esbuild plugins?

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"dist"
],
"exports": {
"./package.json": "./package.json",
".": "./dist/loader.js",
"./cli": "./dist/cli.js",
"./suppress-warnings": "./dist/suppress-warnings.cjs",
@@ -31,10 +32,9 @@
"scripts": {
"build": "pkgroll --target=node12.19 --minify",
"lint": "eslint --cache .",
"pretest": "npm run build",
"test": "node ./dist/cli.js tests/index.ts",
"prepack": "npm run build",
"prepublishOnly": "npm test"
"test": "pnpm build && node ./dist/cli.js tests/index.ts",
"prepack": "pnpm build && clean-pkg-json",
"prepublishOnly": "pnpm test"
},
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.3.3",
@@ -50,6 +50,7 @@
"@types/node": "^18.6.4",
"@types/semver": "^7.3.10",
"chokidar": "^3.5.3",
"clean-pkg-json": "^1.2.0",
"cleye": "^1.2.1",
"cross-spawn": "^7.0.3",
"eslint": "^8.21.0",
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.