Unverified Commit a3ae9667 by Michael Mifsud Committed by GitHub

Merge pull request #2151 from sass/more-watcher-fixes

Fix watching of entry points
parents e3ca0757 2326b5f4
......@@ -250,8 +250,6 @@ function watch(options, emitter) {
});
};
watcher.reset(options);
var gaze = new Gaze();
gaze.add(watcher.reset(options));
gaze.on('error', emitter.emit.bind(emitter, 'error'));
......
var grapher = require('sass-graph'),
clonedeep = require('lodash.clonedeep'),
path = require('path'),
config = {},
watcher = {},
graph = null;
......@@ -30,8 +31,14 @@ watcher.changed = function(absolutePath) {
this.reset();
if (absolutePath && path.basename(absolutePath)[0] !== '_') {
files.changed.push(absolutePath);
}
graph.visitAncestors(absolutePath, function(parent) {
if (path.basename(parent)[0] !== '_') {
files.changed.push(parent);
}
});
graph.visitDescendents(absolutePath, function(child) {
......@@ -50,7 +57,7 @@ watcher.added = function(absolutePath) {
this.reset();
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
if (Object.keys(graph.index).indexOf(absolutePath) === -1) {
files.added.push(absolutePath);
}
......@@ -69,7 +76,9 @@ watcher.removed = function(absolutePath) {
};
graph.visitAncestors(absolutePath, function(parent) {
if (path.basename(parent)[0] !== '_') {
files.changed.push(parent);
}
});
if (Object.keys(graph.index).indexOf(absolutePath) !== -1) {
......
@import "partials/three";
.one {
color: darkred;
}
@import "partials/three";
.two {
color: darkblue;
}
@import "partials/two";
.two {
color: blue;
}
......@@ -20,37 +20,67 @@ describe('watcher', function() {
beforeEach(function() {
watcher.reset({
directory: main,
loadPaths: [main]
includePath: [main]
});
});
describe('when a file is changed in the graph', function() {
it('should return the files to compile', function() {
var files = watcher.changed(path.join(main, 'partials', '_one.scss'));
assert.deepEqual(files, {
added: [],
changed: [path.join(main, 'one.scss')],
removed: [],
describe('when a file is changed', function() {
describe('and it is in the graph', function() {
describe('if it is a partial', function() {
it('should record its ancestors as changed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.changed, [
path.join(main, 'one.scss'),
]);
});
it('should record its decendants as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_three.scss'),
]);
});
describe('and @imports previously not imported files', function() {
it('should also return the new imported files', function() {
it('should record nothing as removed', function() {
var file = path.join(main, 'partials', '_one.scss');
fs.writeFileSync(file, '@import "partials/three.scss";', { flag: 'a' });
var files = watcher.changed(file);
assert.deepEqual(files, {
added: [path.join(main, 'partials', '_three.scss')],
changed: [path.join(main, 'one.scss')],
removed: [],
assert.deepEqual(files.removed, []);
});
});
describe('if it is not a partial', function() {
it('should record itself as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.changed, [
file,
]);
});
it('should record its decendants as added', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_one.scss'),
path.join(main, 'partials', '_three.scss'),
]);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.removed, []);
});
});
});
describe('when a file is changed outside the graph', function() {
it('should return an empty array', function() {
var files = watcher.changed(path.join(sibling, 'partials', '_three.scss'));
describe('and is not in the graph', function() {
describe('if it is a partial', function() {
it('should not record anything', function() {
var file = path.join(sibling, 'partials', '_three.scss');
var files = watcher.changed(file);
assert.deepEqual(files, {
added: [],
changed: [],
......@@ -59,60 +89,143 @@ describe('watcher', function() {
});
});
describe('when a file is added in the graph', function() {
it('should return only the added file', function() {
var file = path.join(main, 'three.scss');
fs.writeFileSync(file, '@import "paritals/two.scss";');
var files = watcher.added(file);
describe('if it is not a partial', function() {
it('should record itself as changed', function() {
var file = path.join(sibling, 'three.scss');
var files = watcher.changed(file);
assert.deepEqual(files, {
added: [file],
changed: [],
added: [],
changed: [file],
removed: [],
});
});
});
});
});
describe('and @imports previously not imported files', function() {
it('should also return the new imported files', function() {
var file = path.join(main, 'three.scss');
fs.writeFileSync(file, '@import "partials/three.scss";');
describe('when a file is added', function() {
describe('and it is in the graph', function() {
describe('if it is a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files, {
added: [
file,
assert.deepEqual(files.added, []);
});
it('should record its decendants as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_three.scss')
],
changed: [],
removed: [],
]);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.changed, []);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.removed, []);
});
});
describe('when a file is added outside the graph', function() {
it('should return an empty array', function() {
var files = watcher.added(path.join(sibling, 'three.scss'));
assert.deepEqual(files, {
added: [],
changed: [],
removed: [],
describe('if it is not a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'three.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, []);
});
it('should record its decendants as added', function() {
var file = path.join(main, 'one.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_one.scss'),
path.join(main, 'partials', '_three.scss'),
]);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.added(file);
assert.deepEqual(files.changed, []);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.added(file);
assert.deepEqual(files.removed, []);
});
});
});
});
describe('when a file is removed', function() {
describe('and it is in the graph', function() {
describe('if it is a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.added, []);
});
it('should record its ancestors as changed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.changed, [
path.join(main, 'one.scss'),
]);
});
it('should record itself as removed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.removed, [file]);
});
});
describe('if it is not a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.added, []);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.changed, []);
});
it('should record itself as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.removed, [file]);
});
});
});
describe('when a file is removed from the graph', function() {
it('should return the files to compile', function() {
var files = watcher.removed(path.join(main, 'partials', '_one.scss'));
describe('and is not in the graph', function() {
describe('if it is a partial', function() {
it('should record nothing', function() {
var file = path.join(sibling, 'partials', '_three.scss');
var files = watcher.removed(file);
assert.deepEqual(files, {
added: [],
changed: [path.join(main, 'one.scss')],
removed: [path.join(main, 'partials', '_one.scss')],
changed: [],
removed: [],
});
});
});
describe('when a file is removed from outside the graph', function() {
it('should return an empty array', function() {
var files = watcher.removed(path.join(sibling, 'partials', '_three.scss'));
describe('if it is not a partial', function() {
it('should record nothing', function() {
var file = path.join(sibling, 'three.scss');
var files = watcher.removed(file);
assert.deepEqual(files, {
added: [],
changed: [],
......@@ -121,29 +234,72 @@ describe('watcher', function() {
});
});
});
});
});
describe('with file', function() {
beforeEach(function() {
watcher.reset({
src: path.join(main, 'one.scss'),
loadPaths: [main]
includePath: [main]
});
});
describe('when a file is changed in the graph', function() {
it('should return the files to compile', function() {
var files = watcher.changed(path.join(main, 'partials', '_one.scss'));
assert.deepEqual(files, {
added: [],
changed: [path.join(main, 'one.scss')],
removed: [],
describe('when a file is changed', function() {
describe('and it is in the graph', function() {
describe('if it is a partial', function() {
it('should record its decendents as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_three.scss'),
]);
});
it('should record its ancenstors as changed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.changed, [
path.join(main, 'one.scss'),
]);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.removed, []);
});
});
describe('if it is not a partial', function() {
it('should record its decendents as added', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_one.scss'),
path.join(main, 'partials', '_three.scss'),
]);
});
it('should record itself as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.changed, [file]);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.changed(file);
assert.deepEqual(files.removed, []);
});
});
});
describe('when a file is changed outside the graph', function() {
it('should return an empty array', function() {
var files = watcher.changed(path.join(sibling, 'partials', '_three.scss'));
describe('and it is not in the graph', function() {
describe('if it is a partial', function() {
it('should record nothing', function() {
var file = path.join(sibling, 'partials', '_three.scss');
var files = watcher.changed(file);
assert.deepEqual(files, {
added: [],
changed: [],
......@@ -152,33 +308,188 @@ describe('watcher', function() {
});
});
describe('if it is not a partial', function() {
it('should record nothing as added', function() {
var file = path.join(sibling, 'three.scss');
var files = watcher.changed(file);
assert.deepEqual(files.added, []);
});
it('should record itself as changed', function() {
var file = path.join(sibling, 'three.scss');
var files = watcher.changed(file);
assert.deepEqual(files.changed, [file]);
});
it('should record nothing as removed', function() {
var file = path.join(sibling, 'three.scss');
var files = watcher.changed(file);
assert.deepEqual(files.removed, []);
});
});
});
});
describe('when a file is added', function() {
it('should return an empty array', function() {
describe('and it is in the graph', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, []);
});
it('should record its decendants as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, [
path.join(main, 'partials', '_three.scss'),
]);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.changed, []);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.removed, []);
});
});
describe('and it is not in the graph', function() {
beforeEach(function() {
watcher.reset({
src: path.join(main, 'two.scss'),
includePath: [main]
});
});
describe('if it is a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, [
file,
]);
});
it('should not record its decendants as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.added(file);
assert.deepEqual(files.added, [
file,
]);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.changed, []);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'partials', '_three.scss');
var files = watcher.added(file);
assert.deepEqual(files.removed, []);
});
});
describe('if it is not a partial', function() {
it('should record itself as added', function() {
var file = path.join(main, 'three.scss');
fs.writeFileSync(file, '@import "paritals/one.scss";');
var files = watcher.added(file);
assert.deepEqual(files, {
added: [],
changed: [],
removed: [],
assert.deepEqual(files.added, [
file,
]);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.added(file);
assert.deepEqual(files.changed, []);
});
it('should record nothing as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.added(file);
assert.deepEqual(files.removed, []);
});
});
});
});
describe('when a file is removed', function() {
describe('and it is in the graph', function() {
describe('if it is a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.added, []);
});
it('should record its ancestors as changed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.changed, [
path.join(main, 'one.scss'),
]);
});
it('should record itself as removed', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.removed, [file]);
});
});
describe('if it is not a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.added, []);
});
it('should record nothing as changed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.changed, []);
});
it('should record itself as removed', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files.removed, [file]);
});
});
});
describe('and is not in the graph', function() {
beforeEach(function() {
watcher.reset({
src: path.join(main, 'two.scss'),
includePath: [main]
});
});
describe('when a file is removed from the graph', function() {
it('should return the files to compile', function() {
var files = watcher.removed(path.join(main, 'partials', '_one.scss'));
describe('if it is a partial', function() {
it('should record nothing as added', function() {
var file = path.join(main, 'partials', '_one.scss');
var files = watcher.removed(file);
assert.deepEqual(files, {
added: [],
changed: [path.join(main, 'one.scss')],
removed: [path.join(main, 'partials', '_one.scss')],
changed: [],
removed: [],
});
});
});
describe('when a file is removed from outside the graph', function() {
it('should return an empty array', function() {
var files = watcher.removed(path.join(sibling, 'partials', '_three.scss'));
describe('if it is not a partial', function() {
it('should record nothing', function() {
var file = path.join(main, 'one.scss');
var files = watcher.removed(file);
assert.deepEqual(files, {
added: [],
changed: [],
......@@ -187,4 +498,6 @@ describe('watcher', function() {
});
});
});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment