Skip to content

Commit

Permalink
Watcher should track newly created files
Browse files Browse the repository at this point in the history
Currently newly created are added to the graph but not added the
watcher.

Fixes sass#1891
  • Loading branch information
xzyfer committed Feb 14, 2017
1 parent cc7c3b3 commit 68f7df0
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -258,34 +258,36 @@ function watch(options, emitter) {
gaze.on('error', emitter.emit.bind(emitter, 'error'));

gaze.on('changed', function(file) {
var files = [file];
updateWatcher(file, watch, buildGraph(options), gaze);
});
gaze.on('added', function(file) {
updateWatcher(file, watch, buildGraph(options), gaze);
});

// 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, watch, graph, gaze) {
var files = [file];

// descendents may be added, so we need a new graph
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);
}
});
}

Expand Down

0 comments on commit 68f7df0

Please # to comment.