From 9e481d890d333210de3364379b0b1004ee2169f7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 10 Aug 2017 21:17:47 -0400 Subject: [PATCH] fix intermittent test failures --- src/watch/fileWatchers.js | 10 ++++++---- src/watch/index.js | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/watch/fileWatchers.js b/src/watch/fileWatchers.js index 85b5b2c61ed..15f69e4cbb1 100644 --- a/src/watch/fileWatchers.js +++ b/src/watch/fileWatchers.js @@ -29,11 +29,13 @@ export function deleteTask(id, target, chokidarOptionsHash) { const group = watchers.get(chokidarOptionsHash); const watcher = group.get(id); - watcher.tasks.delete(target); + if (watcher) { + watcher.tasks.delete(target); - if (watcher.tasks.size === 0) { - watcher.close(); - group.delete(id); + if (watcher.tasks.size === 0) { + watcher.close(); + group.delete(id); + } } } diff --git a/src/watch/index.js b/src/watch/index.js index 10b07f9c96a..4706d836d84 100644 --- a/src/watch/index.js +++ b/src/watch/index.js @@ -147,14 +147,8 @@ class Task { const watched = new Set(); bundle.modules.forEach(module => { - if (!this.filter(module.id)) return; - - if (~this.dests.indexOf(module.id)) { - throw new Error('Cannot import the generated bundle'); - } - watched.add(module.id); - addTask(module.id, this, this.chokidarOptions, this.chokidarOptionsHash); + this.watchFile(module.id); }); this.watched.forEach(id => { @@ -182,16 +176,30 @@ class Task { }); }) .catch(error => { + if (this.closed) return; + if (this.cache) { this.cache.modules.forEach(module => { // this is necessary to ensure that any 'renamed' files // continue to be watched following an error - addTask(module.id, this, this.chokidarOptions, this.chokidarOptionsHash); + this.watchFile(module.id); }); } throw error; }); } + + watchFile(id) { + if (!this.filter(id)) return; + + if (~this.dests.indexOf(id)) { + throw new Error('Cannot import the generated bundle'); + } + + // this is necessary to ensure that any 'renamed' files + // continue to be watched following an error + addTask(id, this, this.chokidarOptions, this.chokidarOptionsHash); + } } export default function watch(configs) {