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

Fixed watch behavior #782

Merged
merged 1 commit into from
Mar 29, 2015
Merged
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
37 changes: 16 additions & 21 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ var cli = meow({
'recursive',
'source-map-embed',
'source-map-contents',
'source-comments'
'source-comments',
'watch'
],
string: [
'functions',
Expand All @@ -64,8 +65,7 @@ var cli = meow({
'output',
'output-style',
'precision',
'source-map-root',
'watch'
'source-map-root'
],
alias: {
c: 'source-comments',
Expand All @@ -82,7 +82,8 @@ var cli = meow({
'indent-width': 2,
linefeed: 'lf',
'output-style': 'nested',
precision: 5
precision: 5,
recursive: true
}
});

Expand Down Expand Up @@ -139,7 +140,7 @@ function getEmitter() {
*/

function getOptions(args, options) {
options.src = options.watch ? options.watch : args[0];
options.src = args[0];

if (args[1]) {
options.dest = path.resolve(process.cwd(), args[1]);
Expand All @@ -161,26 +162,20 @@ function getOptions(args, options) {
*/

function watch(options, emitter) {
var dir = options.watch;
var gaze = new Gaze();

if (dir === true) {
dir = [];
} else if (!Array.isArray(dir)) {
dir = [dir];
var glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
var src = isSassFile(options.src) ? options.src : path.join(options.src, glob);
var graph = grapher.parseDir(path.resolve(path.dirname(src)), { loadPaths: options.includePath });
var watch = [];

// Add all files to watch list
for (var i in graph.index) {
watch.push(i);
}

dir.push(options.src);
dir = dir.map(function(d) {
var glob = options.recursive ? '**/*.{sass,scss}' : '*.{sass,scss}';
return isSassFile(d) ? d : path.join(d, glob);
});

gaze.add(dir);
var gaze = new Gaze();
gaze.add(watch);
gaze.on('error', emitter.emit.bind(emitter, 'error'));

var graph = grapher.parseDir(options.src, { loadPaths: options.includePath });

gaze.on('changed', function(file) {
var files = [file];
graph.visitAncestors(file, function(parent) {
Expand Down
22 changes: 22 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ describe('cli', function() {
fs.appendFileSync(src, 'body{background:white}');
}, 500);
});

it('should watch the full sass dep tree for a single file', function(done) {
var src = fixture('watching/index.scss');
var foo = fixture('watching/foo.scss');

fs.writeFileSync(foo, '');

var bin = spawn(cli, [
'--output-style', 'compressed',
'--watch', src
]);

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert(data.trim() === 'body{background:white}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this line, fs.unlinkSync(fixtures('watching/index.css')) and then git rm test/fixtures/watching/index.css to prevent it from bleeding into source-control.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you please rebase into one commit?

done();
});

setTimeout(function() {
fs.appendFileSync(foo, 'body{background:white}');
}, 500);
});
});

describe('node-sass in.scss --output out.css', function() {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/watching/foo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{background:white}
1 change: 1 addition & 0 deletions test/fixtures/watching/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './foo';