From 0d3db56483fa745b7371c474262483dd0e83fe6a Mon Sep 17 00:00:00 2001 From: Byron Date: Thu, 24 Jan 2019 13:48:18 -0800 Subject: [PATCH] add dispose() fn to cleanup watcher and child process --- lib/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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(); + } } /**