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 13, 2017
1 parent cc7c3b3 commit 3b0dcc7
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b0dcc7

Please sign in to comment.