Skip to content

Commit 1e6973f

Browse files
committed
Do not watch files more than once. And close them correctly on an error.
1 parent 2f0205d commit 1e6973f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

lib/webc.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ exports.watch = function(options, callback) {
2828
var watchersActive = false;
2929

3030
options.extension = function(inputPath, outputPath) {
31+
// do not add watcher if file is already watched
32+
for (var i = 0; i < watchers.length; i++) {
33+
if (watchers[i].path === inputPath) {
34+
return;
35+
}
36+
};
3137
var watcher = fs.watch(inputPath, function(event, filename) {
3238
if (!watchersActive) { return; }
3339

@@ -52,7 +58,7 @@ exports.watch = function(options, callback) {
5258
}
5359
}
5460
});
55-
watchers.push(watcher);
61+
watchers.push({ path: inputPath, watcher: watcher });
5662
};
5763

5864
exports.compile(options, function(err) {
@@ -63,7 +69,7 @@ exports.watch = function(options, callback) {
6369

6470
function stopWatchers() {
6571
for (var i = 0; i < watchers.length; i++) {
66-
watchers[i].close();
72+
watchers[i].watcher.close();
6773
};
6874
}
6975
};

0 commit comments

Comments
 (0)