Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #55 from rollup/gh-30
Browse files Browse the repository at this point in the history
close when process is killed
  • Loading branch information
Rich-Harris authored Jul 12, 2017
2 parents 661124b + 3bd1aad commit c51a4aa
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,27 @@ export default function watch ( rollup, options ) {
// build on next tick, so consumers can listen for BUILD_START
process.nextTick( build );

watcher.close = () => {
function close () {
if ( closed ) return;
for ( const fw of filewatchers.values() ) {
fw.close();
}
closed = true;
};
}

watcher.close = close;

// ctrl-c
process.on('SIGINT', close);

// killall node
process.on('SIGTERM', close);

// in case we ever support stdin!
process.stdin.on('end', close);

// on error
process.on('uncaughtException', close);

return watcher;
}

0 comments on commit c51a4aa

Please sign in to comment.