From 4ed6de22b41c62ae199226577fc63052f7138db9 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 28 Mar 2015 23:22:35 -0500 Subject: [PATCH] Converted watch to a boolean and got it actually working correctly --- bin/node-sass | 37 +++++++++++++------------------ test/cli.js | 22 ++++++++++++++++++ test/fixtures/watching/foo.scss | 1 + test/fixtures/watching/index.scss | 1 + 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 test/fixtures/watching/foo.scss create mode 100644 test/fixtures/watching/index.scss diff --git a/bin/node-sass b/bin/node-sass index f85043271..bd4d83538 100755 --- a/bin/node-sass +++ b/bin/node-sass @@ -53,7 +53,8 @@ var cli = meow({ 'recursive', 'source-map-embed', 'source-map-contents', - 'source-comments' + 'source-comments', + 'watch' ], string: [ 'functions', @@ -64,8 +65,7 @@ var cli = meow({ 'output', 'output-style', 'precision', - 'source-map-root', - 'watch' + 'source-map-root' ], alias: { c: 'source-comments', @@ -82,7 +82,8 @@ var cli = meow({ 'indent-width': 2, linefeed: 'lf', 'output-style': 'nested', - precision: 5 + precision: 5, + recursive: true } }); @@ -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]); @@ -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) { diff --git a/test/cli.js b/test/cli.js index 16476e893..0310fbd26 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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}'); + done(); + }); + + setTimeout(function() { + fs.appendFileSync(foo, 'body{background:white}'); + }, 500); + }); }); describe('node-sass in.scss --output out.css', function() { diff --git a/test/fixtures/watching/foo.scss b/test/fixtures/watching/foo.scss new file mode 100644 index 000000000..d906a03ff --- /dev/null +++ b/test/fixtures/watching/foo.scss @@ -0,0 +1 @@ +body{background:white} \ No newline at end of file diff --git a/test/fixtures/watching/index.scss b/test/fixtures/watching/index.scss new file mode 100644 index 000000000..dece2c696 --- /dev/null +++ b/test/fixtures/watching/index.scss @@ -0,0 +1 @@ +@import './foo';