Skip to content

Commit 97f9afd

Browse files
authored
V11 breaking changes (#1760)
* remove node12 stuff * bump minimum supported TS version to 3.8 to match DT * install source-map-support in register, not create * Remove ts.createIncrementalProgram fallback to ts.createEmitAndSemanticDiagnosticsBuilderProgram * Make enableExperimentalEsmLoaderInterop() on by default; remove conditional code * Remove deprecated `ts-script` bin * make bin.ts `main()` export @internal * change `nodeEval` function signature to accept `context: Context` instead of `: any` * fix version check * Add node18 @tsconfig/bases; remove node10 and node12; change dependencies to be wildcard; will respect whatever version you want to use * More stuff for bumping minimum supported node12 -> node14 * remove test workaround that avoided old bug in node nightly * fix test failing due to `lib` change in @tsconfig/bases node18 * merge fixes * fix
1 parent 0e0da59 commit 97f9afd

29 files changed

+604
-850
lines changed

.github/workflows/continuous-integration.yml

+16-35
Original file line numberDiff line numberDiff line change
@@ -51,91 +51,72 @@ jobs:
5151
matrix:
5252
os: [ubuntu, windows]
5353
# Don't forget to add all new flavors to this list!
54-
flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
54+
flavor: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
5555
include:
56-
# Node 12.15
57-
- flavor: 1
58-
node: 12.15
59-
nodeFlag: 12_15
60-
typescript: latest
61-
typescriptFlag: latest
62-
# Node 12.16
63-
# Earliest version that supports getFormat, etc hooks: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#12.16.0
64-
- flavor: 2
65-
node: 12.16
66-
nodeFlag: 12_16
67-
typescript: latest
68-
typescriptFlag: latest
69-
# Node 12
70-
- flavor: 3
71-
node: 12
72-
nodeFlag: 12
73-
typescript: latest
74-
typescriptFlag: latest
7556
# Node 14.13.0
7657
# To test ESM builtin module resolution immediately before a node behavioral change: https://github.com/TypeStrong/ts-node/issues/1130
77-
- flavor: 4
58+
- flavor: 1
7859
node: 14.13.0
7960
nodeFlag: 14_13_0
8061
typescript: latest
8162
typescriptFlag: latest
8263
# Node 14
83-
- flavor: 5
64+
- flavor: 2
8465
node: 14
8566
nodeFlag: 14
8667
typescript: latest
8768
typescriptFlag: latest
88-
- flavor: 6
69+
- flavor: 3
8970
node: 14
9071
nodeFlag: 14
91-
typescript: 2.7
92-
typescriptFlag: 2_7
93-
- flavor: 7
72+
typescript: 4.0
73+
typescriptFlag: 4_0
74+
- flavor: 4
9475
node: 14
9576
nodeFlag: 14
9677
typescript: next
9778
typescriptFlag: next
9879
# Node 16
9980
# Node 16.11.1
10081
# Earliest version that supports old ESM Loader Hooks API: https://github.com/TypeStrong/ts-node/pull/1522
101-
- flavor: 8
82+
- flavor: 5
10283
node: 16.11.1
10384
nodeFlag: 16_11_1
10485
typescript: latest
10586
typescriptFlag: latest
106-
- flavor: 9
87+
- flavor: 6
10788
node: 16
10889
nodeFlag: 16
10990
typescript: latest
11091
typescriptFlag: latest
11192
downgradeNpm: true
112-
- flavor: 10
93+
- flavor: 7
11394
node: 16
11495
nodeFlag: 16
115-
typescript: 2.7
116-
typescriptFlag: 2_7
96+
typescript: 4.0
97+
typescriptFlag: 4_0
11798
downgradeNpm: true
118-
- flavor: 11
99+
- flavor: 8
119100
node: 16
120101
nodeFlag: 16
121102
typescript: next
122103
typescriptFlag: next
123104
downgradeNpm: true
124105
# Node 18
125-
- flavor: 12
106+
- flavor: 9
126107
node: 18
127108
nodeFlag: 18
128109
typescript: latest
129110
typescriptFlag: latest
130111
downgradeNpm: true
131-
- flavor: 13
112+
- flavor: 10
132113
node: 18
133114
nodeFlag: 18
134115
typescript: next
135116
typescriptFlag: next
136117
downgradeNpm: true
137118
# Node nightly
138-
- flavor: 14
119+
- flavor: 11
139120
node: nightly
140121
nodeFlag: nightly
141122
typescript: latest

ava.config.cjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ module.exports = {
1515
NODE_PATH: ''
1616
},
1717
require: ['./src/test/remove-env-var-force-color.js'],
18-
nodeArguments: semver.gte(process.version, '14.0.0')
19-
? ['--loader', './src/test/test-loader.mjs', '--no-warnings']
20-
: [],
18+
nodeArguments: ['--loader', './src/test/test-loader.mjs', '--no-warnings'],
2119
timeout: '300s',
2220
concurrency: 1,
2321
};

dist-raw/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ in a factory function, we will not indent the function body, to avoid whitespace
1010

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

1515
## `raw` directory
1616

dist-raw/node-internal-modules-cjs-helpers.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ function addBuiltinLibsToObject(object, dummyModuleName) {
6363

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

6968
// Disable the current getter/setter and set up a new
7069
// non-enumerable property.

dist-raw/node-internal-modules-cjs-loader.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,11 @@ const Module_resolveFilename = function _resolveFilename(request, parent, isMain
471471
paths = Module._resolveLookupPaths(request, parent);
472472
}
473473

474-
// if (parent?.filename) {
475-
// node 12 hack
476-
if (parent != null && parent.filename) {
474+
if (parent?.filename) {
477475
if (request[0] === '#') {
478476
const pkg = readPackageScope(parent.filename) || {};
479477

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

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

589589
module.exports = {
590590
createCjsLoader,
591-
assertScriptCanLoadAsCJSImpl,
591+
assertScriptCanLoadAsCJS,
592592
readPackageScope
593593
};

dist-raw/node-options.js

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ function parseArgv(argv) {
3030
'--preserve-symlinks-main': Boolean,
3131
'--input-type': String,
3232
'--experimental-specifier-resolution': String,
33-
// Legacy alias for node versions prior to 12.16
34-
'--es-module-specifier-resolution': '--experimental-specifier-resolution',
3533
'--experimental-policy': String,
3634
'--conditions': [String],
3735
'--pending-deprecation': Boolean,

node18/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@tsconfig/node18/tsconfig.json"
3+
}

package-lock.json

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-12
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@
2828
"./child-loader.mjs": "./child-loader.mjs",
2929
"./transpilers/swc": "./transpilers/swc.js",
3030
"./transpilers/swc-experimental": "./transpilers/swc-experimental.js",
31-
"./node10/tsconfig.json": "./node10/tsconfig.json",
32-
"./node12/tsconfig.json": "./node12/tsconfig.json",
3331
"./node14/tsconfig.json": "./node14/tsconfig.json",
34-
"./node16/tsconfig.json": "./node16/tsconfig.json"
32+
"./node16/tsconfig.json": "./node16/tsconfig.json",
33+
"./node18/tsconfig.json": "./node18/tsconfig.json"
3534
},
3635
"types": "dist/index.d.ts",
3736
"bin": {
3837
"ts-node": "dist/bin.js",
3938
"ts-node-cwd": "dist/bin-cwd.js",
4039
"ts-node-esm": "dist/bin-esm.js",
4140
"ts-node-script": "dist/bin-script.js",
42-
"ts-node-transpile-only": "dist/bin-transpile.js",
43-
"ts-script": "dist/bin-script-deprecated.js"
41+
"ts-node-transpile-only": "dist/bin-transpile.js"
4442
},
4543
"files": [
4644
"/transpilers/",
@@ -55,10 +53,9 @@
5553
"/LICENSE",
5654
"/tsconfig.schema.json",
5755
"/tsconfig.schemastore-schema.json",
58-
"/node10/",
59-
"/node12/",
6056
"/node14/",
61-
"/node16/"
57+
"/node16/",
58+
"/node18/"
6259
],
6360
"scripts": {
6461
"lint": "dprint check",
@@ -159,10 +156,9 @@
159156
},
160157
"dependencies": {
161158
"@cspotcode/source-map-support": "^0.8.0",
162-
"@tsconfig/node10": "^1.0.7",
163-
"@tsconfig/node12": "^1.0.7",
164-
"@tsconfig/node14": "^1.0.0",
165-
"@tsconfig/node16": "^1.0.2",
159+
"@tsconfig/node14": "*",
160+
"@tsconfig/node16": "*",
161+
"@tsconfig/node18": "*",
166162
"acorn": "^8.4.1",
167163
"acorn-walk": "^8.1.1",
168164
"arg": "^4.1.0",

src/bin-script-deprecated.ts

-10
This file was deleted.

src/bin.ts

+2-20
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import { findAndReadConfig } from './configuration';
3939
*
4040
* The functions are intentionally given uncreative names and left in the same order as the original code, to make a
4141
* smaller git diff.
42+
*
43+
* @internal
4244
*/
4345
export function main(
4446
argv: string[] = process.argv.slice(2),
@@ -97,19 +99,6 @@ export function bootstrap(state: BootstrapState) {
9799

98100
function parseArgv(argv: string[], entrypointArgs: Record<string, any>) {
99101
arg ??= require('arg');
100-
// HACK: technically, this function is not marked @internal so it's possible
101-
// that libraries in the wild are doing `require('ts-node/dist/bin').main({'--transpile-only': true})`
102-
// We can mark this function @internal in next major release.
103-
// For now, rewrite args to avoid a breaking change.
104-
entrypointArgs = { ...entrypointArgs };
105-
for (const key of Object.keys(entrypointArgs)) {
106-
entrypointArgs[
107-
key.replace(
108-
/([a-z])-([a-z])/g,
109-
(_$0, $1, $2: string) => `${$1}${$2.toUpperCase()}`
110-
)
111-
] = entrypointArgs[key];
112-
}
113102

114103
const args = {
115104
...entrypointArgs,
@@ -742,13 +731,6 @@ let guaranteedNonexistentDirectorySuffix = 0;
742731
* https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results
743732
*/
744733
function requireResolveNonCached(absoluteModuleSpecifier: string) {
745-
// node <= 12.1.x fallback: The trick below triggers a node bug on old versions.
746-
// On these old versions, pollute the require cache instead. This is a deliberate
747-
// ts-node limitation that will *rarely* manifest, and will not matter once node 12
748-
// is end-of-life'd on 2022-04-30
749-
const isSupportedNodeVersion = versionGteLt(process.versions.node, '12.2.0');
750-
if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier);
751-
752734
const { dir, base } = parsePath(absoluteModuleSpecifier);
753735
const relativeModuleSpecifier = `./${base}`;
754736

src/child/spawn-child.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { BootstrapState } from '../bin';
22
import { spawn } from 'child_process';
33
import { pathToFileURL } from 'url';
4-
import { versionGteLt } from '../util';
54
import { argPrefix, compress } from './argv-payload';
65

76
/**
@@ -11,11 +10,6 @@ import { argPrefix, compress } from './argv-payload';
1110
* the child process.
1211
*/
1312
export function callInChild(state: BootstrapState) {
14-
if (!versionGteLt(process.versions.node, '12.17.0')) {
15-
throw new Error(
16-
'`ts-node-esm` and `ts-node --esm` require node version 12.17.0 or newer.'
17-
);
18-
}
1913
const child = spawn(
2014
process.execPath,
2115
[

src/esm.ts

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ export function registerAndCreateEsmHooks(opts?: RegisterOptions) {
119119
}
120120

121121
export function createEsmHooks(tsNodeService: Service) {
122-
tsNodeService.enableExperimentalEsmLoaderInterop();
123-
124122
// Custom implementation that considers additional file extensions and automatically adds file extensions
125123
const nodeResolveImplementation = tsNodeService.getNodeEsmResolver();
126124
const nodeGetFormatImplementation = tsNodeService.getNodeEsmGetFormat();

0 commit comments

Comments
 (0)