Skip to content

Commit

Permalink
Update watched file list when files are added or removed (sass#1539)
Browse files Browse the repository at this point in the history
Currently we build the Sass import graph when the CLI watcher is
started. However the graph is not update updated when files are
added or deleted. The latest is a big deal but the former results
in new files not triggered rebuilds when they're changed. The only
way to currently resolve this is to restart the CLI watcher.

This patch rebuilds the Sass import graph when files are added or
deleted to the watch always works as expected.

Fixes sass#1538
  • Loading branch information
xzyfer committed May 10, 2016
1 parent a04e84d commit ad4c44c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,24 @@ function getOptions(args, options) {
*/

function watch(options, emitter) {
var watch = [];
var buildGraph = function(options) {
var graphOptions = {
loadPaths: options.includePath,
extensions: ['scss', 'sass', 'css']
};

if (options.directory) {
var graph = grapher.parseDir(options.directory, graphOptions);
} else {
var graph = grapher.parseFile(options.src, graphOptions);
}

var graphOptions = { loadPaths: options.includePath, extensions: ['scss', 'sass', 'css'] };
var graph;
if (options.directory) {
graph = grapher.parseDir(options.directory, graphOptions);
} else {
graph = grapher.parseFile(options.src, graphOptions);
return graph;
}

var watch = [];
var graph = buildGraph(options);

// Add all files to watch list
for (var i in graph.index) {
watch.push(i);
Expand All @@ -260,6 +268,14 @@ function watch(options, emitter) {
}
});
});

gaze.on('added', function(file) {
graph = buildGraph(options);
});

gaze.on('deleted', function(file) {
graph = buildGraph(options);
});
}

/**
Expand Down

0 comments on commit ad4c44c

Please sign in to comment.