diff --git a/lib/index.js b/lib/index.js index 131c102..7c8937c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,6 +7,7 @@ var fs = require('fs') const tsNodeVersion = require('ts-node').VERSION var tsVersion = require('typescript').version +let didInit = false; module.exports = function(script, scriptArgs, nodeArgs, opts) { if (typeof script !== 'string' || script.length === 0) { throw new TypeError('`script` must be a string') @@ -29,7 +30,11 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) { var log = require('./log')(cfg) var notify = require('./notify')(cfg, log) opts.log = log - compiler.init(opts) + + if (!didInit) { + compiler.init(opts) + didInit = true; + } compiler.notify = notify compiler.stop = stop @@ -173,6 +178,11 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) { }) start() + + return function dispose() { + stop(); + watcher.removeAll(); + } } /**