From 6172043b8c19a53d4a8ee06b45932fd2fcbe48ca 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 | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/bin/node-sass b/bin/node-sass index e94c12c77..1bbba5386 100755 --- a/bin/node-sass +++ b/bin/node-sass @@ -245,23 +245,11 @@ function watch(options, emitter) { return graph; }; - var watch = []; - var graph = buildGraph(options); - - // Add all files to watch list - for (var i in graph.index) { - watch.push(i); - } - - var gaze = new Gaze(); - gaze.add(watch); - gaze.on('error', emitter.emit.bind(emitter, 'error')); - - gaze.on('changed', function(file) { + var updateWatcher = function(file) { + var graph = buildGraph(options); var files = [file]; // descendents may be added, so we need a new graph - graph = buildGraph(options); graph.visitAncestors(file, function(parent) { files.push(parent); }); @@ -278,10 +266,25 @@ function watch(options, emitter) { renderFile(file, options, emitter); } }); - }); + }; - gaze.on('added', function() { - graph = buildGraph(options); + var watch = []; + var graph = buildGraph(options); + + // Add all files to watch list + for (var i in graph.index) { + watch.push(i); + } + + var gaze = new Gaze(); + gaze.add(watch); + gaze.on('error', emitter.emit.bind(emitter, 'error')); + + gaze.on('changed', function(file) { + updateWatcher(file); + }); + gaze.on('added', function(file) { + updateWatcher(file); }); gaze.on('deleted', function() {