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.12.10
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.13.0
Choose a head ref
  • 15 commits
  • 36 files changed
  • 1 contributor

Commits on Sep 13, 2023

  1. chore: upgrade dev deps

    privatenumber committed Sep 13, 2023
    Copy the full SHA
    5642b9a View commit details
  2. Copy the full SHA
    497ea8d View commit details
  3. Copy the full SHA
    3f94114 View commit details
  4. Copy the full SHA
    d95728c View commit details
  5. Copy the full SHA
    67a776a View commit details

Commits on Sep 14, 2023

  1. Copy the full SHA
    7b8503c View commit details

Commits on Sep 17, 2023

  1. docs: add mission

    privatenumber authored Sep 17, 2023
    Copy the full SHA
    f25f60a View commit details

Commits on Sep 21, 2023

  1. Copy the full SHA
    7c1ace7 View commit details
  2. Copy the full SHA
    cb226a1 View commit details
  3. Copy the full SHA
    412a9c4 View commit details
  4. Copy the full SHA
    0e65cbf View commit details

Commits on Sep 22, 2023

  1. Copy the full SHA
    42c35e6 View commit details
  2. Copy the full SHA
    f1c1ed0 View commit details
  3. Copy the full SHA
    f8837b7 View commit details

Commits on Sep 24, 2023

  1. Copy the full SHA
    e46366d View commit details
30 changes: 27 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
timeout-minutes: 10
os: [ubuntu-latest]
timeout-minutes: 15

steps:
- name: Checkout
@@ -26,7 +26,31 @@ jobs:
uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- name: Get pnpm store directory
shell: bash
run: echo "PNPM_STORE=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Cache pnpm
with:
path: ${{ env.PNPM_STORE }}
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-

- name: Install dependencies
run: pnpm install

- name: Get Node.js cache directory
shell: bash
run: echo "NVE_CACHE=$(node -e 'console.log(require("cachedir")("nve"))')" >> $GITHUB_ENV

- name: Cache Node.js versions
uses: actions/cache@v3
with:
path: ${{ env.NVE_CACHE }}
key: ${{ runner.os }}-nodejs-${{ hashFiles('tests/utils/node-versions.ts') }}
restore-keys: ${{ runner.os }}-nodejs-

- name: Test
run: pnpm test
48 changes: 26 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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>

> _TypeScript Execute (`tsx`)_: Node.js enhanced with [esbuild](https://esbuild.github.io/) to run TypeScript & ESM files
> _TypeScript Execute (`tsx`)_: Node.js enhanced to run TypeScript & ESM files
### Features
- Blazing fast on-demand TypeScript & ESM compilation
@@ -10,7 +10,7 @@
- Hides experimental feature warnings
- TypeScript REPL
- Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths)
- Tested on Linux & Windows with Node.js v12~18
- Tested on Linux & Windows with Node.js v12~20

> **💡 Protip: Looking to bundle your TypeScript project?**
>
@@ -41,6 +41,11 @@ 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
3. Support the latest major version of Node.js v12 and up _(likely to change in the future)_

## Install

@@ -148,22 +153,33 @@ tsx --no-cache ./file.ts

`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.

To use `tsx` as a Node.js loader, simply pass it in to the [`--loader`](https://nodejs.org/api/esm.html#loaders) flag.

> 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.
To use `tsx` as a Node.js loader, pass it in to the [`--loader`](https://nodejs.org/api/esm.html#loaders) flag. This will add TypeScript & ESM support for both ESM and CommonJS contexts.

```sh
# As a CLI flag
node --loader tsx ./file.ts
```

# As an environment variable
Or as an environment variable:
```sh
NODE_OPTIONS='--loader tsx' node ./file.ts
```

> Tip: In rare circumstances, you might be limited to using the [`-r, --require`](https://nodejs.org/api/cli.html#-r---require-module) flag.
>
> You can use [`@esbuild-kit/cjs-loader`](https://github.com/esbuild-kit/cjs-loader), but transformations will only be applied to `require()` (not `import`).
> **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.
#### ESM only loader

If you only need to add TypeScript support in a Module context, you can use the ESM loader:

```sh
node --loader tsx/esm ./file.ts
```

#### CommonJS only loader
If you only need to add TypeScript & ESM support in a CommonJS context, you can use the CJS loader:

```sh
node --require tsx/cjs ./file.ts
```

### Hashbang

@@ -189,14 +205,6 @@ $ ./file.ts hello
argv: [ 'hello' ]
```

## Dependencies

#### [@esbuild-kit/esm-loader](https://github.com/esbuild-kit/esm-loader)
Node.js Loader to transform TypeScript to ESM.

#### [@esbuild-kit/cjs-loader](https://github.com/esbuild-kit/cjs-loader)
Node.js `require()` hook to transform TypeScript & ESM to CommonJS.

<br>

<p align="center">
@@ -284,10 +292,6 @@ If the dependencies are out of the specified range, it indicates a potential bre

## Sponsors

[**Holocron**](https://holocron.so#github-privatenumber)

[![Holocron](https://holocron.so/banners/github.png)](https://holocron.so#github-privatenumber)

<p align="center">
<a href="https://privatenumber-sponsors.vercel.app/api/sponsor?tier=silver1">
<picture>
59 changes: 34 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -23,19 +23,22 @@
],
"exports": {
"./package.json": "./package.json",
".": "./dist/loader.js",
"./cli": "./dist/cli.js",
".": "./dist/loader.mjs",
"./cjs": "./dist/cjs/index.cjs",
"./esm": "./dist/esm/index.mjs",
"./cli": "./dist/cli.mjs",
"./source-map": "./dist/source-map.cjs",
"./suppress-warnings": "./dist/suppress-warnings.cjs",
"./preflight": "./dist/preflight.cjs",
"./repl": "./dist/repl.js"
"./repl": "./dist/repl.mjs"
},
"bin": "./dist/cli.js",
"bin": "./dist/cli.mjs",
"scripts": {
"prepare": "pnpm simple-git-hooks",
"build": "pkgroll --target=node12.19 --minify",
"lint": "eslint --cache .",
"type-check": "tsc --noEmit",
"test": "pnpm build && node ./dist/cli.js tests/index.ts",
"test": "pnpm build && node ./dist/cli.mjs tests/index.ts",
"prepack": "pnpm build && clean-pkg-json"
},
"simple-git-hooks": {
@@ -45,38 +48,44 @@
"*.{js,ts,mjs,mts,cjs,cts,json}": "pnpm lint"
},
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.4.2",
"@esbuild-kit/core-utils": "^3.3.0",
"@esbuild-kit/esm-loader": "^2.6.3"
"esbuild": "~0.18.20",
"get-tsconfig": "^4.7.2",
"source-map-support": "^0.5.21"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
"fsevents": "~2.3.3"
},
"devDependencies": {
"@pvtnbr/eslint-config": "^0.36.0",
"@types/cross-spawn": "^6.0.2",
"@types/node": "^18.11.18",
"@types/react": "^18.0.26",
"@types/semver": "^7.3.13",
"@ampproject/remapping": "^2.2.1",
"@pvtnbr/eslint-config": "^0.37.0",
"@types/cross-spawn": "^6.0.3",
"@types/node": "^20.6.0",
"@types/react": "^18.2.21",
"@types/semver": "^7.5.1",
"@types/source-map-support": "^0.5.7",
"cachedir": "^2.4.0",
"chokidar": "^3.5.3",
"clean-pkg-json": "^1.2.0",
"cleye": "^1.3.1",
"cleye": "^1.3.2",
"cross-spawn": "^7.0.3",
"eslint": "^8.48.0",
"execa": "^6.1.0",
"es-module-lexer": "^1.3.1",
"eslint": "^8.49.0",
"execa": "^8.0.1",
"fs-fixture": "^1.2.0",
"get-node": "^13.5.0",
"kolorist": "^1.6.0",
"lint-staged": "^13.1.0",
"get-node": "^14.2.1",
"kolorist": "^1.8.0",
"lint-staged": "^14.0.1",
"magic-string": "^0.30.3",
"manten": "^1.1.0",
"node-pty": "^1.0.0",
"outdent": "^0.8.0",
"pkgroll": "^1.8.0",
"semver": "^7.3.8",
"simple-git-hooks": "^2.8.1",
"strip-ansi": "^7.0.1",
"pkgroll": "^1.11.1",
"semver": "^7.5.4",
"simple-git-hooks": "^2.9.0",
"strip-ansi": "^7.1.0",
"type-fest": "^4.3.1",
"type-flag": "^3.0.0",
"typescript": "^4.9.4"
"typescript": "^5.2.2"
},
"eslintConfig": {
"extends": "@pvtnbr",
Loading