From 9ef79932f29e348dbf124aada415019bea5fa6f6 Mon Sep 17 00:00:00 2001 From: xzyfer Date: Mon, 13 Feb 2017 16:33:34 +1100 Subject: [PATCH] Watcher should track newly created files Currently newly created are added to the graph but not added the watcher. Fixes #1891 --- bin/node-sass | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/bin/node-sass b/bin/node-sass index e94c12c77..3d0090fda 100755 --- a/bin/node-sass +++ b/bin/node-sass @@ -257,37 +257,36 @@ function watch(options, emitter) { gaze.add(watch); gaze.on('error', emitter.emit.bind(emitter, 'error')); - gaze.on('changed', function(file) { - var files = [file]; + gaze.on('changed', updateWatcher); + gaze.on('added', updateWatcher); - // descendents may be added, so we need a new graph + gaze.on('deleted', function() { graph = buildGraph(options); - graph.visitAncestors(file, function(parent) { - files.push(parent); - }); - - // Add children to watcher - graph.visitDescendents(file, function(child) { - if (watch.indexOf(child) === -1) { - watch.push(child); - gaze.add(child); - } - }); - files.forEach(function(file) { - if (path.basename(file)[0] !== '_') { - renderFile(file, options, emitter); - } - }); }); +} - gaze.on('added', function() { - graph = buildGraph(options); +function updateWatcher(file) { + var files = [file]; + + // descendents may be added, so we need a new graph + graph = buildGraph(options); + graph.visitAncestors(file, function(parent) { + files.push(parent); }); - gaze.on('deleted', function() { - graph = buildGraph(options); + // Add children to watcher + graph.visitDescendents(file, function(child) { + if (watch.indexOf(child) === -1) { + watch.push(child); + gaze.add(child); + } }); -} + files.forEach(function(file) { + if (path.basename(file)[0] !== '_') { + renderFile(file, options, emitter); + } + }); +}; /** * Run