Skip to content

Commit 538212a

Browse files
committed
add watch param
1 parent 1020ae0 commit 538212a

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/compiler.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@ var tsHandler
1111

1212
var getCompiledPath = require('./get-compiled-path')
1313
var tmpDir = '.ts-node'
14+
1415
var sourceMapSupportPath = require.resolve('source-map-support').replace(/\\/g, '/')
1516

1617
var extensions = ['.ts', '.tsx']
1718
var empty = function() {}
1819
var cwd = process.cwd()
19-
var comilationInstanceStampt = Math.random()
20+
var compilationInstanceStamp = Math.random()
2021
.toString()
2122
.slice(2)
2223

2324
var compiler = {
2425
allowJs: false,
2526
tsConfigPath: '',
2627
getCompilationId: function() {
27-
return comilationInstanceStampt
28+
return compilationInstanceStamp
29+
},
30+
createCompiledDir: function() {
31+
var compiledDir = compiler.getCompiledDir()
32+
if (!fs.existsSync(compiledDir)) {
33+
mkdirp.sync(compiler.getCompiledDir())
34+
}
2835
},
29-
getCompiledDir: function() {
36+
getCompiledDir: function() {
3037
return path.join(tmpDir, 'compiled').replace(/\\/g, '/')
3138
},
3239
getCompileReqFilePath: function() {
@@ -37,12 +44,12 @@ var compiler = {
3744
},
3845
getCompilerReadyFilePath: function() {
3946
return path
40-
.join(os.tmpdir(), 'ts-node-dev-ready-' + comilationInstanceStampt)
47+
.join(os.tmpdir(), 'ts-node-dev-ready-' + compilationInstanceStamp)
4148
.replace(/\\/g, '/')
4249
},
4350
getChildHookPath: function() {
4451
return path
45-
.join(os.tmpdir(), 'ts-node-dev-hook-' + comilationInstanceStampt + '.js')
52+
.join(os.tmpdir(), 'ts-node-dev-hook-' + compilationInstanceStamp + '.js')
4653
.replace(/\\/g, '/')
4754
},
4855
writeReadyFile: function() {
@@ -172,7 +179,7 @@ var compiler = {
172179

173180
/* clean up compiled on each new init*/
174181
rimraf.sync(compiler.getCompiledDir())
175-
mkdirp.sync(compiler.getCompiledDir())
182+
compiler.createCompiledDir()
176183
/* check if `allowJs` compiler option enable */
177184
var allowJsEnabled = require.extensions['.js'] !== originalJsHandler
178185
if (allowJsEnabled) {

lib/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
4040
var watcher = filewatcher({
4141
forcePolling: opts.poll,
4242
interval: parseInt(opts.interval),
43-
debounce: parseInt(opts.debounce)
44-
})
43+
debounce: parseInt(opts.debounce),
44+
recursive: true
45+
})
4546
var starting = false
4647
watcher.on('change', function(file) {
4748
if (file === compiler.tsConfigPath) {
4849
notify('Reinitializing TS compilation')
4950
compiler.init(opts)
5051
}
5152
/* eslint-disable no-octal-escape */
52-
if (cfg.clear) process.stdout.write('\033[2J\033[H')
53-
notify('Restarting', file + ' has been modified')
54-
compiler.compileChanged(file)
53+
54+
if (cfg.clear || cfg.cls) {
55+
process.stdout.write('\033[2J\033[H')
56+
}
57+
notify('Restarting', file + ' has been modified')
58+
compiler.compileChanged(file)
5559
if (starting) {
5660
log.debug('Already starting')
5761
return
@@ -85,6 +89,10 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
8589
tsNodeVersion + ', typescript version',
8690
tsVersion
8791
)
92+
for (let watched of (opts.watch || '').split(',')) {
93+
console.log('add watch', watched)
94+
watcher.add(watched)
95+
}
8896
var cmd = nodeArgs.concat(wrapper, script, scriptArgs)
8997
var childHookPath = compiler.getChildHookPath()
9098

0 commit comments

Comments
 (0)