Skip to content

Commit 6172043

Browse files
committed
Watcher should track newly created files
Currently newly created are added to the graph but not added the watcher. Fixes sass#1891
1 parent eb7f013 commit 6172043

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

bin/node-sass

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,11 @@ function watch(options, emitter) {
245245
return graph;
246246
};
247247

248-
var watch = [];
249-
var graph = buildGraph(options);
250-
251-
// Add all files to watch list
252-
for (var i in graph.index) {
253-
watch.push(i);
254-
}
255-
256-
var gaze = new Gaze();
257-
gaze.add(watch);
258-
gaze.on('error', emitter.emit.bind(emitter, 'error'));
259-
260-
gaze.on('changed', function(file) {
248+
var updateWatcher = function(file) {
249+
var graph = buildGraph(options);
261250
var files = [file];
262251

263252
// descendents may be added, so we need a new graph
264-
graph = buildGraph(options);
265253
graph.visitAncestors(file, function(parent) {
266254
files.push(parent);
267255
});
@@ -278,10 +266,25 @@ function watch(options, emitter) {
278266
renderFile(file, options, emitter);
279267
}
280268
});
281-
});
269+
};
282270

283-
gaze.on('added', function() {
284-
graph = buildGraph(options);
271+
var watch = [];
272+
var graph = buildGraph(options);
273+
274+
// Add all files to watch list
275+
for (var i in graph.index) {
276+
watch.push(i);
277+
}
278+
279+
var gaze = new Gaze();
280+
gaze.add(watch);
281+
gaze.on('error', emitter.emit.bind(emitter, 'error'));
282+
283+
gaze.on('changed', function(file) {
284+
updateWatcher(file);
285+
});
286+
gaze.on('added', function(file) {
287+
updateWatcher(file);
285288
});
286289

287290
gaze.on('deleted', function() {

0 commit comments

Comments
 (0)