diff --git a/README.md b/README.md index d69238d..7000d3a 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,12 @@ tsnd --respawn server.ts - `--prefer-ts` (default: false) - for each `.js` file (that is not in `node_modules`) will try to check if corresponding `.ts` version exists and require it. - `--ignore-watch` (default: []) - files/folders to be [ignored by `node-dev`](https://github.com/fgnass/node-dev#ignore-paths). **But also this behaviour enhanced:** it will also make up `new RegExp` of passed ignore string and check absolute paths of required files for match. So, to ignore everything in `node_modules`, just pass `--ignore-watch node_modules`. - - `--debug` - Some additional debug output. - `--interval` - Polling interval (ms) - `--debounce` - Debounce file change events (ms, non-polling mode) - `--clear` (`--cls`) Will clear screen on restart - `--watch` - Explicitly add files or folders to watch and restart on change (list separated by commas) -- `--exit-child` - Adds 'SIGTERM' exit handler in a child process. +- `--dont-exit-child` - Don't exit the child process on changes/SIGTERM **Caveats and points of notice:** diff --git a/bin/ts-node-dev b/bin/ts-node-dev old mode 100644 new mode 100755 index 7575ede..117d759 --- a/bin/ts-node-dev +++ b/bin/ts-node-dev @@ -33,7 +33,7 @@ var opts = minimist(devArgs, { 'prefer-ts-exts', 'tree-kill', 'clear', 'cls', - 'exit-child', + 'dont-exit-child', 'rs' ], string: [ diff --git a/lib/child-require-hook.js b/lib/child-require-hook.js index 36515e4..6d959b2 100644 --- a/lib/child-require-hook.js +++ b/lib/child-require-hook.js @@ -11,7 +11,7 @@ var preferTs = false var ignore = [/node_modules/] var readyFile var execCheck = false -var exitChild = false +var dontExitChild = false var sourceMapSupportPath var checkFileScript = join(__dirname, 'check-file-exists.js') @@ -113,10 +113,11 @@ if (readyFile) { } } -if (exitChild) { +if (!dontExitChild) { process.on('SIGTERM', function() { + // This is to make sure debuggers (e.g. Chrome) close console.log('Child got SIGTERM, exiting.') - process.exit() + process.kill(process.pid, 'SIGINT') }) } diff --git a/lib/compiler.js b/lib/compiler.js index 08a2bc3..c0fded9 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -26,14 +26,14 @@ var compiler = { tsConfigPath: '', getCompilationId: function() { return compilationInstanceStamp - }, - createCompiledDir: function() { + }, + createCompiledDir: function() { var compiledDir = compiler.getCompiledDir() if (!fs.existsSync(compiledDir)) { mkdirp.sync(compiler.getCompiledDir()) - } + } }, - getCompiledDir: function() { + getCompiledDir: function() { return path.join(tmpDir, 'compiled').replace(/\\/g, '/') }, getCompileReqFilePath: function() { @@ -56,7 +56,7 @@ var compiler = { var fileData = fs.writeFileSync(compiler.getCompilerReadyFilePath(), '') }, writeChildHookFile: function(options) { - + var fileData = fs.readFileSync( path.join(__dirname, 'child-require-hook.js'), 'utf-8' @@ -73,10 +73,9 @@ var compiler = { } if (options['exec-check']) { fileData = fileData.replace('execCheck = false', 'execCheck = true') - } - - if (options['exit-child']) { - fileData = fileData.replace('exitChild = false', 'exitChild = true') + } + if (options['dont-exit-child']) { + fileData = fileData.replace('dontExitChild = false', 'dontExitChild = true') } if (options['ignore'] !== undefined) { var ignore = options['ignore'] @@ -112,7 +111,7 @@ var compiler = { fileData = fileData.replace( 'var sourceMapSupportPath', 'var sourceMapSupportPath = "' + sourceMapSupportPath + '"' - ) + ) fileData = fileData.replace( /__dirname/, '"' + __dirname.replace(/\\/g, '/') + '"' @@ -171,7 +170,7 @@ var compiler = { options['ignoreDiagnostics'] || options['ignore-diagnostics'], logError: options['log-error'], disableWarnings: options['disableWarnings'], - preferTsExts: options['prefer-ts-exts'], + preferTsExts: options['prefer-ts-exts'], compilerOptions: compilerOptions, files: options['files'] || true }