Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/automatic detach from debugger #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
2 changes: 1 addition & 1 deletion bin/ts-node-dev
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var opts = minimist(devArgs, {
'prefer-ts-exts',
'tree-kill',
'clear', 'cls',
'exit-child',
'dont-exit-child',
'rs'
],
string: [
Expand Down
7 changes: 4 additions & 3 deletions lib/child-require-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
})
}

Expand Down
21 changes: 10 additions & 11 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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'
Expand All @@ -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']
Expand Down Expand Up @@ -112,7 +111,7 @@ var compiler = {
fileData = fileData.replace(
'var sourceMapSupportPath',
'var sourceMapSupportPath = "' + sourceMapSupportPath + '"'
)
)
fileData = fileData.replace(
/__dirname/,
'"' + __dirname.replace(/\\/g, '/') + '"'
Expand Down Expand Up @@ -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
}
Expand Down