Skip to content

Commit

Permalink
TS_NODE_OPTIONS
Browse files Browse the repository at this point in the history
This will remap all `TS_NODE_` environment to
`NODE_` environment variables for the child process
being spawned.

Fixes TypeStrong#471
  • Loading branch information
stelcheck committed Dec 15, 2017
1 parent 1541dfe commit f68e6e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ ts-node -p '"Hello, world!"'

# Pipe scripts to execute with TypeScript.
echo "console.log('Hello, world!')" | ts-node

# Passing NODE_OPTIONS to the underlying process using TS_NODE_OPTIONS.
# All `TS_NODE_*` environment variables will be passed as `NODE_*` environment
# variables to your code.
TS_NODE_ENV="--inspect-brk" ts-node
```

![TypeScript REPL](https://github.com/TypeStrong/ts-node/raw/master/screenshot.png)
Expand Down
12 changes: 12 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ v8flags(function (err, v8flags) {
'--expose-http2'
])

const env: { [key: string]: string | undefined } = {}

for (const key of Object.keys(process.env)) {
const val = process.env[key]
if (key.substring(0, 8) === 'TS_NODE_') {
env[key.substring(3)] = val
} else {
env[key] = val
}
}

for (let i = 0; i < argv.length; i++) {
const arg = argv[i]
const flag = arg.split('=', 1)[0]
Expand All @@ -62,6 +73,7 @@ v8flags(function (err, v8flags) {
//
// See: https://nodejs.org/api/child_process.html#child_process_options_detached
detached: true,
env,
stdio: 'inherit'
}
)
Expand Down

0 comments on commit f68e6e3

Please sign in to comment.