Skip to content

Commit f0e6921

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 89ac5ac commit f0e6921

File tree

3 files changed

+162
-102
lines changed

3 files changed

+162
-102
lines changed

Diff for: bin/node-sass

+24-17
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,15 +266,34 @@ 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() {
288291
graph = buildGraph(options);
289292
});
293+
294+
if (!options.quiet) {
295+
emitter.emit('warn', util.format('Watching %s', options.directory || options.src));
296+
}
290297
}
291298

292299
/**

Diff for: package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
{
23
"name": "node-sass",
34
"version": "4.5.2",
@@ -31,7 +32,7 @@
3132
"install": "node scripts/install.js",
3233
"postinstall": "node scripts/build.js",
3334
"lint": "node_modules/.bin/eslint bin/node-sass lib scripts test",
34-
"test": "node_modules/.bin/mocha test/{*,**/**}.js",
35+
"test": "node_modules/.bin/mocha test/cli.js",
3536
"build": "node scripts/build.js --force",
3637
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
3738
},
@@ -76,11 +77,14 @@
7677
"coveralls": "^2.11.8",
7778
"eslint": "^3.4.0",
7879
"istanbul": "^0.4.2",
80+
"lodash.once": "^4.1.1",
7981
"mocha": "^3.1.2",
8082
"mocha-lcov-reporter": "^1.2.0",
8183
"object-merge": "^2.5.1",
8284
"read-yaml": "^1.0.0",
8385
"rimraf": "^2.5.2",
84-
"sass-spec": "3.5.0-1"
86+
"sass-spec": "3.5.0-1",
87+
"touch": "^1.0.0",
88+
"unique-temp-dir": "^1.0.0"
8589
}
8690
}

0 commit comments

Comments
 (0)