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 a11a3a8
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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() {
Expand Down

0 comments on commit a11a3a8

Please sign in to comment.