From 7b59080ac634aa182c813a7c0d29cab09f2a01d5 Mon Sep 17 00:00:00 2001 From: Staffan Eketorp Date: Sat, 14 Sep 2019 13:01:50 -0700 Subject: [PATCH 1/3] kill process with SIGINIT --- lib/child-require-hook.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/child-require-hook.js b/lib/child-require-hook.js index 36515e4..a565f1d 100644 --- a/lib/child-require-hook.js +++ b/lib/child-require-hook.js @@ -115,8 +115,9 @@ if (readyFile) { if (exitChild) { 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') }) } From ef90fffaff50456aca7096a87fc21ae88095ffb4 Mon Sep 17 00:00:00 2001 From: Staffan Eketorp Date: Fri, 4 Oct 2019 09:41:31 -0700 Subject: [PATCH 2/3] Reworked and documented option exitChild to dontExitChild. The existing behavior changed old behavior, and seems very unusual/. Reversed defaults --- README.md | 2 +- bin/ts-node-dev | 2 +- lib/child-require-hook.js | 3 ++- lib/compiler.js | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) mode change 100644 => 100755 bin/ts-node-dev diff --git a/README.md b/README.md index 08e852b..7000d3a 100644 --- a/README.md +++ b/README.md @@ -39,12 +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) +- `--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 a565f1d..e43be1d 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') @@ -114,6 +114,7 @@ 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.') diff --git a/lib/compiler.js b/lib/compiler.js index 3266f89..5b44920 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -75,7 +75,8 @@ var compiler = { fileData = fileData.replace('execCheck = false', 'execCheck = true') } if (options['exit-child']) { - fileData = fileData.replace('exitChick = false', 'exitChild = true') + if (options['dont-exit-child']) { + fileData = fileData.replace('dontExitChild = false', 'dontExitChild = true') } if (options['ignore'] !== undefined) { var ignore = options['ignore'] From 25dfd02a4ff78aff73ae41119e9474e9f1c8651b Mon Sep 17 00:00:00 2001 From: Staffan Eketorp Date: Fri, 4 Oct 2019 13:14:27 -0700 Subject: [PATCH 3/3] fix bad line --- lib/child-require-hook.js | 1 - lib/compiler.js | 17 ++++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/child-require-hook.js b/lib/child-require-hook.js index e43be1d..6d959b2 100644 --- a/lib/child-require-hook.js +++ b/lib/child-require-hook.js @@ -113,7 +113,6 @@ if (readyFile) { } } -if (exitChild) { if (!dontExitChild) { process.on('SIGTERM', function() { // This is to make sure debuggers (e.g. Chrome) close diff --git a/lib/compiler.js b/lib/compiler.js index 5b44920..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,8 +73,7 @@ var compiler = { } if (options['exec-check']) { fileData = fileData.replace('execCheck = false', 'execCheck = true') - } - if (options['exit-child']) { + } if (options['dont-exit-child']) { fileData = fileData.replace('dontExitChild = false', 'dontExitChild = true') } @@ -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 }