Skip to content

Commit 9ef7993

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 ae4f935 commit 9ef7993

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

Diff for: bin/node-sass

+23-24
Original file line numberDiff line numberDiff line change
@@ -257,37 +257,36 @@ function watch(options, emitter) {
257257
gaze.add(watch);
258258
gaze.on('error', emitter.emit.bind(emitter, 'error'));
259259

260-
gaze.on('changed', function(file) {
261-
var files = [file];
260+
gaze.on('changed', updateWatcher);
261+
gaze.on('added', updateWatcher);
262262

263-
// descendents may be added, so we need a new graph
263+
gaze.on('deleted', function() {
264264
graph = buildGraph(options);
265-
graph.visitAncestors(file, function(parent) {
266-
files.push(parent);
267-
});
268-
269-
// Add children to watcher
270-
graph.visitDescendents(file, function(child) {
271-
if (watch.indexOf(child) === -1) {
272-
watch.push(child);
273-
gaze.add(child);
274-
}
275-
});
276-
files.forEach(function(file) {
277-
if (path.basename(file)[0] !== '_') {
278-
renderFile(file, options, emitter);
279-
}
280-
});
281265
});
266+
}
282267

283-
gaze.on('added', function() {
284-
graph = buildGraph(options);
268+
function updateWatcher(file) {
269+
var files = [file];
270+
271+
// descendents may be added, so we need a new graph
272+
graph = buildGraph(options);
273+
graph.visitAncestors(file, function(parent) {
274+
files.push(parent);
285275
});
286276

287-
gaze.on('deleted', function() {
288-
graph = buildGraph(options);
277+
// Add children to watcher
278+
graph.visitDescendents(file, function(child) {
279+
if (watch.indexOf(child) === -1) {
280+
watch.push(child);
281+
gaze.add(child);
282+
}
289283
});
290-
}
284+
files.forEach(function(file) {
285+
if (path.basename(file)[0] !== '_') {
286+
renderFile(file, options, emitter);
287+
}
288+
});
289+
};
291290

292291
/**
293292
* Run

0 commit comments

Comments
 (0)