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: v4.11.0
Choose a base ref
...
head repository: privatenumber/tsx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.14.1
Choose a head ref

Commits on May 24, 2024

  1. chore(deps): update dependency node to v20.13.1 (#547)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored May 24, 2024
    Copy the full SHA
    e7dae3b View commit details

Commits on May 28, 2024

  1. Copy the full SHA
    3d7bce7 View commit details
  2. test: external source maps

    closes #340
    privatenumber committed May 28, 2024
    Copy the full SHA
    f30b296 View commit details

Commits on May 29, 2024

  1. Copy the full SHA
    39507b8 View commit details

Commits on Jun 2, 2024

  1. test: log util

    privatenumber committed Jun 2, 2024
    Copy the full SHA
    59bb4ed View commit details

Commits on Jun 3, 2024

  1. Copy the full SHA
    5e70105 View commit details
  2. Copy the full SHA
    aa2b639 View commit details

Commits on Jun 4, 2024

  1. Copy the full SHA
    42e2745 View commit details
  2. Copy the full SHA
    e8bb062 View commit details
  3. Copy the full SHA
    4ef6632 View commit details
  4. Copy the full SHA
    a33c96a View commit details
  5. Copy the full SHA
    72d0896 View commit details

Commits on Jun 5, 2024

  1. Copy the full SHA
    a150ac1 View commit details
  2. Copy the full SHA
    48dd7ab View commit details
  3. Copy the full SHA
    585f117 View commit details
  4. Copy the full SHA
    e1464cf View commit details

Commits on Jun 6, 2024

  1. Copy the full SHA
    7c85303 View commit details
  2. Copy the full SHA
    9f04dae View commit details
  3. Copy the full SHA
    bd56e84 View commit details

Commits on Jun 7, 2024

  1. Copy the full SHA
    de900a1 View commit details
  2. Copy the full SHA
    4be7c7e View commit details
  3. Copy the full SHA
    c703300 View commit details
  4. Copy the full SHA
    0eb4e91 View commit details
  5. Copy the full SHA
    0a78bfd View commit details
  6. Copy the full SHA
    87a7683 View commit details

Commits on Jun 8, 2024

  1. Copy the full SHA
    89621bf View commit details
  2. Copy the full SHA
    02d3856 View commit details
  3. Copy the full SHA
    807f467 View commit details
  4. Copy the full SHA
    c35dbaa View commit details
  5. Copy the full SHA
    4503421 View commit details
  6. Copy the full SHA
    9e647a5 View commit details
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.12.2
v20.14.0
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ export default defineConfig({
siteTitle: 'tsx',

editLink: {
pattern: 'https://github.com/privatenumber/tsx/edit/develop/docs/:path',
pattern: 'https://github.com/privatenumber/tsx/edit/master/docs/:path',
text: 'Edit this page on GitHub',
},

6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

`tsx` stands for _TypeScript Execute_, and it's a simple command to run TypeScript in Node.js.

Because `tsx` is basically an alias to `node`, you can use it the same way:
`tsx` is basically an alias to `node`, so you can use it the same way:

<div class="tsx-before-after">

@@ -12,11 +12,11 @@ node file.js
<span class="hidden sm:block">→</span>
<span class="sm:hidden">↓</span>
```sh
tsx file.js
tsx file.ts
```
</div>

<sub>Since it's Node.js underneath, all command-line flags are supported. Use `tsx` as you would use `node`!</sub>
All Node.js command-line flags are supported—use `tsx` the same way you would use `node`!

## Features

3 changes: 3 additions & 0 deletions docs/node/cjs.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,9 @@ Load `tsx/cjs` at the top of your entry-file:

```js
require('tsx/cjs')

// Now you can load TS files
require('./file.ts')
```

### Registration & Unregistration
24 changes: 11 additions & 13 deletions docs/node/esm.md
Original file line number Diff line number Diff line change
@@ -32,6 +32,15 @@ NODE_OPTIONS='--loader tsx/esm' npx some-binary

## Programmatic API

Load `tsx/esm` at the top of your entry-file:

```js
import 'tsx/esm'

// Now you can load TS files
await import('./file.ts')
```

### Registration & Unregistration

```js
@@ -40,6 +49,8 @@ import { register } from 'tsx/esm/api'
// register tsx enhancement
const unregister = register()

await import('./file.ts')

// Unregister when needed
unregister()
```
@@ -57,19 +68,6 @@ register({
})
```

#### Tracking loaded files

Detect files that get loaded with the `onImport` hook:

```ts
register({
onImport: (file: string) => {
console.log(file)
// file:///foo.ts
}
})
```

### Scoped registration

If you want to register tsx without affecting the environment, you can add a namespace.
3 changes: 3 additions & 0 deletions docs/node/index.md
Original file line number Diff line number Diff line change
@@ -34,4 +34,7 @@ NODE_OPTIONS='--import tsx' npx eslint
Load `tsx` at the top of your entry-file:
```js
import 'tsx'

// Now you can load TS files
await import('./file.ts')
```
4 changes: 0 additions & 4 deletions docs/node/ts-import.md
Original file line number Diff line number Diff line change
@@ -8,10 +8,6 @@ The current file path must be passed in as the second argument to resolve the im

Since this is designed for one-time use, it does not cache loaded modules.

::: warning Caveat
CommonJS files are currently not enhanced due to this [Node.js bug](https://github.com/nodejs/node/issues/51327).
:::

## ESM usage

```js
2 changes: 1 addition & 1 deletion docs/node/tsx-require.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ Use this function for importing TypeScript files in CommonJS mode without adding
Note, the current file path must be passed in as the second argument to resolve the import context.

::: warning Caveats
- `import()` & asynchronous `require()` calls in the loaded files are not enhanced.
- `import()` calls in the loaded files are not enhanced.
- Because it compiles ESM syntax to run in CommonJS mode, top-level await is not supported
:::

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -29,8 +29,14 @@
".": "./dist/loader.mjs",
"./cjs": "./dist/cjs/index.cjs",
"./cjs/api": {
"types": "./dist/cjs/api/index.d.cts",
"default": "./dist/cjs/api/index.cjs"
"import": {
"types": "./dist/cjs/api/index.d.mts",
"default": "./dist/cjs/api/index.mjs"
},
"require": {
"types": "./dist/cjs/api/index.d.cts",
"default": "./dist/cjs/api/index.cjs"
}
},
"./esm": "./dist/esm/index.mjs",
"./esm/api": {
@@ -78,7 +84,7 @@
"devDependencies": {
"@ampproject/remapping": "^2.3.0",
"@types/cross-spawn": "^6.0.6",
"@types/node": "^20.12.11",
"@types/node": "^20.14.1",
"@types/split2": "^4.2.3",
"cachedir": "^2.4.0",
"chokidar": "^3.6.0",
@@ -91,18 +97,18 @@
"fs-require": "^1.6.0",
"get-node": "^15.0.1",
"kolorist": "^1.8.0",
"lint-staged": "^15.2.2",
"lintroll": "^1.5.2",
"lint-staged": "^15.2.5",
"lintroll": "^1.6.1",
"magic-string": "^0.30.10",
"manten": "^1.3.0",
"memfs": "^4.9.2",
"node-pty": "^1.0.0",
"outdent": "^0.8.0",
"pkgroll": "^2.0.2",
"pkgroll": "^2.1.1",
"simple-git-hooks": "^2.11.1",
"split2": "^4.2.0",
"strip-ansi": "^7.1.0",
"type-fest": "^4.18.2",
"type-fest": "^4.18.3",
"type-flag": "^3.0.0",
"typescript": "^5.4.5"
},
Loading