Skip to content

Commit f68e6e3

Browse files
committed
TS_NODE_OPTIONS
This will remap all `TS_NODE_` environment to `NODE_` environment variables for the child process being spawned. Fixes #471
1 parent 1541dfe commit f68e6e3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ ts-node -p '"Hello, world!"'
4242

4343
# Pipe scripts to execute with TypeScript.
4444
echo "console.log('Hello, world!')" | ts-node
45+
46+
# Passing NODE_OPTIONS to the underlying process using TS_NODE_OPTIONS.
47+
# All `TS_NODE_*` environment variables will be passed as `NODE_*` environment
48+
# variables to your code.
49+
TS_NODE_ENV="--inspect-brk" ts-node
4550
```
4651

4752
![TypeScript REPL](https://github.com/TypeStrong/ts-node/raw/master/screenshot.png)

src/bin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ v8flags(function (err, v8flags) {
3636
'--expose-http2'
3737
])
3838

39+
const env: { [key: string]: string | undefined } = {}
40+
41+
for (const key of Object.keys(process.env)) {
42+
const val = process.env[key]
43+
if (key.substring(0, 8) === 'TS_NODE_') {
44+
env[key.substring(3)] = val
45+
} else {
46+
env[key] = val
47+
}
48+
}
49+
3950
for (let i = 0; i < argv.length; i++) {
4051
const arg = argv[i]
4152
const flag = arg.split('=', 1)[0]
@@ -62,6 +73,7 @@ v8flags(function (err, v8flags) {
6273
//
6374
// See: https://nodejs.org/api/child_process.html#child_process_options_detached
6475
detached: true,
76+
env,
6577
stdio: 'inherit'
6678
}
6779
)

0 commit comments

Comments
 (0)