From 9f04dae4167bfeadf7f69920958bb19f86572a08 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 6 Jun 2024 17:47:44 +0900 Subject: [PATCH] docs: clarify programmatic api usage --- docs/.vitepress/config.ts | 2 +- docs/index.md | 6 +++--- docs/node/cjs.md | 3 +++ docs/node/esm.md | 11 +++++++++++ docs/node/index.md | 3 +++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index c234f852d..9e1a424c4 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -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', }, diff --git a/docs/index.md b/docs/index.md index 4ab801622..65dd36f4c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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:
@@ -12,11 +12,11 @@ node file.js ```sh -tsx file.js +tsx file.ts ```
-Since it's Node.js underneath, all command-line flags are supported. Use `tsx` as you would use `node`! +All Node.js command-line flags are supported—use `tsx` the same way you would use `node`! ## Features diff --git a/docs/node/cjs.md b/docs/node/cjs.md index c4398a12b..2703a75ee 100644 --- a/docs/node/cjs.md +++ b/docs/node/cjs.md @@ -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 diff --git a/docs/node/esm.md b/docs/node/esm.md index 9356797fc..f8fa7429c 100644 --- a/docs/node/esm.md +++ b/docs/node/esm.md @@ -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() ``` diff --git a/docs/node/index.md b/docs/node/index.md index 7a32492f4..fb49fa1ca 100644 --- a/docs/node/index.md +++ b/docs/node/index.md @@ -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') ```