Skip to content

Commit

Permalink
docs: clarify programmatic api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jun 6, 2024
1 parent 7c85303 commit 9f04dae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},

Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/node/cjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docs/node/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,6 +49,8 @@ import { register } from 'tsx/esm/api'
// register tsx enhancement
const unregister = register()

await import('./file.ts')

// Unregister when needed
unregister()
```
Expand Down
3 changes: 3 additions & 0 deletions docs/node/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```

0 comments on commit 9f04dae

Please sign in to comment.