Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into switch-to-c8
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jul 14, 2022
2 parents 6e056f4 + 97f9afd commit c090710
Show file tree
Hide file tree
Showing 66 changed files with 1,519 additions and 1,097 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prettier formatting
9d05cb684fc3a6e492832100a125ea07d1cc98c5

51 changes: 16 additions & 35 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,91 +51,72 @@ jobs:
matrix:
os: [ubuntu, windows]
# Don't forget to add all new flavors to this list!
flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
include:
# Node 12.15
- flavor: 1
node: 12.15
nodeFlag: 12_15
typescript: latest
typescriptFlag: latest
# Node 12.16
# Earliest version that supports getFormat, etc hooks: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.16.0
- flavor: 2
node: 12.16
nodeFlag: 12_16
typescript: latest
typescriptFlag: latest
# Node 12
- flavor: 3
node: 12
nodeFlag: 12
typescript: latest
typescriptFlag: latest
# Node 14.13.0
# To test ESM builtin module resolution immediately before a node behavioral change: https://github.com/TypeStrong/ts-node/issues/1130
- flavor: 4
- flavor: 1
node: 14.13.0
nodeFlag: 14_13_0
typescript: latest
typescriptFlag: latest
# Node 14
- flavor: 5
- flavor: 2
node: 14
nodeFlag: 14
typescript: latest
typescriptFlag: latest
- flavor: 6
- flavor: 3
node: 14
nodeFlag: 14
typescript: 2.7
typescriptFlag: 2_7
- flavor: 7
typescript: 4.0
typescriptFlag: 4_0
- flavor: 4
node: 14
nodeFlag: 14
typescript: next
typescriptFlag: next
# Node 16
# Node 16.11.1
# Earliest version that supports old ESM Loader Hooks API: https://github.com/TypeStrong/ts-node/pull/1522
- flavor: 8
- flavor: 5
node: 16.11.1
nodeFlag: 16_11_1
typescript: latest
typescriptFlag: latest
- flavor: 9
- flavor: 6
node: 16
nodeFlag: 16
typescript: latest
typescriptFlag: latest
downgradeNpm: true
- flavor: 10
- flavor: 7
node: 16
nodeFlag: 16
typescript: 2.7
typescriptFlag: 2_7
typescript: 4.0
typescriptFlag: 4_0
downgradeNpm: true
- flavor: 11
- flavor: 8
node: 16
nodeFlag: 16
typescript: next
typescriptFlag: next
downgradeNpm: true
# Node 18
- flavor: 12
- flavor: 9
node: 18
nodeFlag: 18
typescript: latest
typescriptFlag: latest
downgradeNpm: true
- flavor: 13
- flavor: 10
node: 18
nodeFlag: 18
typescript: next
typescriptFlag: next
downgradeNpm: true
# Node nightly
- flavor: 14
- flavor: 11
node: nightly
nodeFlag: nightly
typescript: latest
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ We publish using `np`: https://npm.im/np
2. Rebuild the README (see instructions above, necessary because npmjs.com renders the readme)
3. (optional) Update the api-extractor report; check for unexpected changes. See below
4. Publish with `np`
- `np --branch main --no-tests`
- `--no-tests` because we must rely on CI to test ts-node. Even if you *did* run the tests locally, you would only be testing a single operating system, node version, and TypeScript version, so locally-run tests are insufficient.
5. Add changelog to the Github Release; match formatting from previous releases
6. Move `docs` branch to head of `main`
- this rebuilds the website
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,18 @@ These tricks will make ts-node faster.

## Skip typechecking

It is often better to use `tsc --noEmit` to typecheck as part of your tests or linting. In these cases, ts-node can skip typechecking.
It is often better to typecheck as part of your tests or linting. You can run `tsc --noEmit` to do this. In these cases, ts-node can skip typechecking, making it much faster.

To skip typechecking in ts-node, do one of the following:

* Enable [swc](#swc)
* This is by far the fastest option
* Enable [`transpileOnly`](#transpileonly) to skip typechecking without swc

## With typechecking

If you absolutely must typecheck in ts-node:

* Avoid dynamic `require()` which may trigger repeated typechecking; prefer `import`
* Try with and without `--files`; one may be faster depending on your project
* Check `tsc --showConfig`; make sure all executed files are included
Expand Down
1 change: 1 addition & 0 deletions api-extractor/ts-node.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface CreateOptions {
esm?: boolean;
experimentalReplAwait?: boolean;
experimentalSpecifierResolution?: 'node' | 'explicit';
experimentalTsImportSpecifiers?: boolean;
// (undocumented)
fileExists?: (path: string) => boolean;
files?: boolean;
Expand Down
4 changes: 1 addition & 3 deletions ava.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ module.exports = {
NODE_PATH: ''
},
require: ['./src/test/remove-env-var-force-color.js'],
nodeArguments: semver.gte(process.version, '14.0.0')
? ['--loader', './src/test/test-loader.mjs', '--no-warnings']
: [],
nodeArguments: ['--loader', './src/test/test-loader.mjs', '--no-warnings'],
timeout: '300s',
concurrency: 1,
};
Expand Down
2 changes: 1 addition & 1 deletion dist-raw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ in a factory function, we will not indent the function body, to avoid whitespace

One obvious problem with this approach: the code has been pulled from one version of node, whereas users of ts-node
run multiple versions of node.
Users running node 12 may see that ts-node behaves like node 14, for example.
Users running node 14 may see that ts-node behaves like node 18, for example.

## `raw` directory

Expand Down
3 changes: 1 addition & 2 deletions dist-raw/node-internal-modules-cjs-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) {

ObjectDefineProperty(object, name, {
get: () => {
// Node 12 hack; remove when we drop node12 support
const lib = (dummyModule.require || require)(name);
const lib = dummyModule.require(name);

// Disable the current getter/setter and set up a new
// non-enumerable property.
Expand Down
16 changes: 8 additions & 8 deletions dist-raw/node-internal-modules-cjs-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,11 @@ const Module_resolveFilename = function _resolveFilename(request, parent, isMain
paths = Module._resolveLookupPaths(request, parent);
}

// if (parent?.filename) {
// node 12 hack
if (parent != null && parent.filename) {
if (parent?.filename) {
if (request[0] === '#') {
const pkg = readPackageScope(parent.filename) || {};

// if (pkg.data?.imports != null) {
// node 12 hack
if (pkg.data != null && pkg.data.imports != null) {
if (pkg.data?.imports != null) {
try {
return finalizeEsmResolution(
packageImportsResolve(request, pathToFileURL(parent.filename),
Expand Down Expand Up @@ -559,11 +555,15 @@ return {
/**
* copied from Module._extensions['.js']
* https://github.com/nodejs/node/blob/v15.3.0/lib/internal/modules/cjs/loader.js#L1113-L1120
* Assert that script can be loaded as CommonJS when we attempt to require it.
* If it should be loaded as ESM, throw ERR_REQUIRE_ESM like node does.
*
* @param {import('../src/index').Service} service
* @param {NodeJS.Module} module
* @param {string} filename
*/
function assertScriptCanLoadAsCJSImpl(service, module, filename) {
function assertScriptCanLoadAsCJS(service, module, filename) {
const pkg = readPackageScope(filename);

// ts-node modification: allow our configuration to override
Expand All @@ -588,6 +588,6 @@ function assertScriptCanLoadAsCJSImpl(service, module, filename) {

module.exports = {
createCjsLoader,
assertScriptCanLoadAsCJSImpl,
assertScriptCanLoadAsCJS,
readPackageScope
};
2 changes: 0 additions & 2 deletions dist-raw/node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function parseArgv(argv) {
'--preserve-symlinks-main': Boolean,
'--input-type': String,
'--experimental-specifier-resolution': String,
// Legacy alias for node versions prior to 12.16
'--es-module-specifier-resolution': '--experimental-specifier-resolution',
'--experimental-policy': String,
'--conditions': [String],
'--pending-deprecation': Boolean,
Expand Down
9 changes: 9 additions & 0 deletions dist-raw/runmain-hack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {pathToFileURL} = require('url');

// Hack to avoid Module.runMain on node 18.6.0
// Keeping it simple for now, isolated in this file.
// Could theoretically probe `getFormat` impl to determine if `import()` or `Module._load()` is best
// Note that I attempted a try-catch around `Module._load`, but it poisons some sort of cache such that subsequent `import()` is impossible.
exports.run = function(entryPointPath) {
import(pathToFileURL(entryPointPath));
}
3 changes: 3 additions & 0 deletions node18/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/node18/tsconfig.json"
}
Loading

0 comments on commit c090710

Please sign in to comment.