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() {