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

Watcher should track newly created files #1896

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ function getEmitter() {
emitter.on('warn', function(data) {
if (!options.quiet) {
console.warn(data);
} else if (process.env.NODE_ENV) {
console.warn('TESTING', data);
}
});

Expand Down Expand Up @@ -245,23 +247,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 +268,38 @@ 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);
});

gaze.on('ready', function() {
if (process.env.NODE_ENV === 'test') {
setTimeout(function() {
console.warn('TESTING');
}, 1000);
}
});
}

/**
Expand Down
9 changes: 6 additions & 3 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 @@ -30,8 +31,8 @@
"coverage": "node scripts/coverage.js",
"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",
"lint": "eslint bin/node-sass lib scripts test",
"test": "mocha test/{*,**/**}.js",
"build": "node scripts/build.js --force",
"prepublish": "not-in-install && node scripts/prepublish.js || in-install"
},
Expand Down Expand Up @@ -81,6 +82,8 @@
"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