From df3c05b1801383b6633acf4aa941c1195ebcd88d Mon Sep 17 00:00:00 2001 From: stelcheck Date: Sun, 10 Dec 2017 13:12:45 +0900 Subject: [PATCH] Support trace-warnings flag, TS_NODE_OPTIONS This will remap all `TS_NODE_` environment to `NODE_` environment variables for the child process being spawned. Fixes #465 #471 --- README.md | 5 +++++ src/bin.ts | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b11a961e0..d35d1ac32 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/src/bin.ts b/src/bin.ts index 8b8e76401..0b2a69bbf 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -32,9 +32,21 @@ v8flags(function (err, v8flags) { '--perf-basic-prof', '--preserve-symlinks', '--expose-gc', - '--expose-http2' + '--expose-http2', + '--trace-warnings' ]) + 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] @@ -53,7 +65,10 @@ v8flags(function (err, v8flags) { const proc = spawn( process.execPath, nodeArgs.concat(join(__dirname, '_bin.js'), scriptArgs), - { stdio: 'inherit' } + { + env, + stdio: 'inherit' + } ) proc.on('exit', function (code: number, signal: string) {