Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

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 #1891
  • Loading branch information
xzyfer committed Apr 2, 2017
1 parent ae4f935 commit d03234b
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 102 deletions.
41 changes: 24 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,15 +266,34 @@ 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() {
graph = buildGraph(options);
});

if (!options.quiet) {
emitter.emit('warn', util.format('Watching %s', options.directory || options.src));
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{
"name": "node-sass",
"version": "4.5.2",
Expand Down Expand Up @@ -31,7 +32,7 @@
"install": "node scripts/install.js",
"postinstall": "node scripts/build.js",
"lint": "node_modules/.bin/eslint bin/node-sass lib scripts test",
"test": "node_modules/.bin/mocha test/{*,**/**}.js",
"test": "node_modules/.bin/mocha test/cli.js",
"build": "node scripts/build.js --force",
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
},
Expand Down Expand Up @@ -76,11 +77,14 @@
"coveralls": "^2.11.8",
"eslint": "^3.4.0",
"istanbul": "^0.4.2",
"lodash.once": "^4.1.1",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"object-merge": "^2.5.1",
"read-yaml": "^1.0.0",
"rimraf": "^2.5.2",
"sass-spec": "3.5.0-1"
"sass-spec": "3.5.0-1",
"touch": "^1.0.0",
"unique-temp-dir": "^1.0.0"
}
}
Loading

0 comments on commit d03234b

Please sign in to comment.