-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix "esm" jsdoc * categorize typedocs; exclude jsonschema tags from typedoc * Resolve #1607: explain common ESM errors in troubleshooting page * improve dark theme contrast * Fix amendment to typedoc categories * big docs overhaul * changes to cater to our readme rendering script * lint-fix * final fixes
- Loading branch information
Showing
22 changed files
with
706 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: API | ||
--- | ||
|
||
ts-node's complete API is documented here: [API Docs](https://typestrong.org/ts-node/api/) | ||
|
||
Here are a few highlights of what you can accomplish: | ||
|
||
- [`create()`](https://typestrong.org/ts-node/api/index.html#create) creates ts-node's compiler service without | ||
registering any hooks. | ||
- [`createRepl()`](https://typestrong.org/ts-node/api/index.html#createRepl) creates an instance of our REPL service, so | ||
you can create your own TypeScript-powered REPLs. | ||
- [`createEsmHooks()`](https://typestrong.org/ts-node/api/index.html#createEsmHooks) creates our ESM loader hooks, | ||
suitable for composing with other loaders or augmenting with additional features. |
1 change: 1 addition & 0 deletions
1
website/docs/imports.md → .../commonjs-vs-native-ecmascript-modules.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
--- | ||
title: How It Works | ||
title: How it works | ||
--- | ||
|
||
ts-node works by registering hooks for `.ts`, `.tsx`, `.js`, and/or `.jsx` extensions. | ||
|
||
Vanilla `node` loads `.js` by reading code from disk and executing it. Our hook runs in the middle, transforming code from TypeScript to JavaScript and passing the result to `node` for execution. This transformation will respect your `tsconfig.json` as if you had compiled via `tsc`. | ||
|
||
`.js` and `.jsx` are only transformed when [`allowJs`](https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options) is enabled. | ||
|
||
`.tsx` and `.jsx` are only transformed when [`jsx`](https://www.typescriptlang.org/docs/handbook/jsx.html) is enabled. | ||
|
||
> **Warning:** if a file is ignored or its file extension is not registered, node will either fail to resolve the file or will attempt to execute it as JavaScript without any transformation. This may cause syntax errors or other failures, because node does not understand TypeScript type syntax nor bleeding-edge ECMAScript features. | ||
> **Warning:** When ts-node is used with `allowJs`, all non-ignored JavaScript files are transformed using the TypeScript compiler. | ||
## Skipping `node_modules` | ||
|
||
By default, ts-node avoids compiling files in `/node_modules/` for three reasons: | ||
|
||
1. Modules should always be published in a format node.js can consume | ||
2. Transpiling the entire dependency tree will make your project slower | ||
3. Differing behaviours between TypeScript and node.js (e.g. ES2015 modules) can result in a project that works until you decide to support a feature natively from node.js | ||
|
||
If you need to import uncompiled TypeScript in `node_modules`, use [`--skipIgnore`](./options#transpilation) or [`TS_NODE_SKIP_IGNORE`](./options#transpilation) to bypass this restriction. | ||
|
||
## Skipping pre-compiled TypeScript | ||
|
||
If a compiled JavaScript file with the same name as a TypeScript file already exists, the TypeScript file will be ignored. ts-node will import the pre-compiled JavaScript. | ||
|
||
To force ts-node to import the TypeScript source, not the precompiled JavaScript, use [`--preferTsExts`](./options#transpilation). | ||
We also register a few other hooks to apply sourcemaps to stack traces and remap from `.js` imports to `.ts`. |
Oops, something went wrong.