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

add dispose() fn to cleanup watcher and child process #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -173,6 +178,11 @@ module.exports = function(script, scriptArgs, nodeArgs, opts) {
})

start()

return function dispose() {
stop();
watcher.removeAll();
}
}

/**
Expand Down