Skip to content

Commit 3b510be

Browse files
authored
Fix ts-node with --no-experimental-strip-types (#2069)
1 parent be71b5e commit 3b510be

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
"yargs": "^17.2.1"
7272
},
7373
"scripts": {
74-
"sass-spec": "ts-node sass-spec.ts",
75-
"js-api-spec": "ts-node js-api-spec.ts",
74+
"sass-spec": "node ts-node-wrapper.mjs sass-spec.ts",
75+
"js-api-spec": "node ts-node-wrapper.mjs js-api-spec.ts",
7676
"test": "jest",
77-
"lint-spec": "ts-node lint-spec.ts",
77+
"lint-spec": "node ts-node-wrapper.mjs lint-spec.ts",
7878
"lint": "gts lint",
79-
"migrate": "ts-node migrate.ts",
79+
"migrate": "node ts-node-wrapper.mjs migrate.ts",
8080
"fix": "gts fix"
8181
},
8282
"engines": {

ts-node-wrapper.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* The new --experimental-strip-types node option conflicts with `ts-node`.
3+
* This wrapper disables it if it's supported by the current node version.
4+
*
5+
* See: https://github.com/TypeStrong/ts-node/issues/2152
6+
*
7+
* TODO: switch to native typescript support once node<22 are dropped.
8+
*/
9+
10+
import {execFileSync} from 'node:child_process';
11+
12+
try {
13+
execFileSync('node', ['--no-experimental-strip-types', '-e', ''], {
14+
shell: process.platform === 'win32',
15+
stdio: 'ignore',
16+
});
17+
18+
if (process.env.NODE_OPTIONS === undefined) {
19+
process.env.NODE_OPTIONS = '--no-experimental-strip-types';
20+
} else {
21+
process.env.NODE_OPTIONS += ' --no-experimental-strip-types';
22+
}
23+
} catch (_) {
24+
// ignore
25+
}
26+
27+
try {
28+
execFileSync('ts-node', process.argv.slice(2), {
29+
shell: process.platform === 'win32',
30+
stdio: 'inherit',
31+
});
32+
} catch (error) {
33+
if (error.code) {
34+
throw error;
35+
} else {
36+
process.exitCode = error.status;
37+
}
38+
}

0 commit comments

Comments
 (0)