Skip to content

Commit

Permalink
Add CLI option for watcher polling interval
Browse files Browse the repository at this point in the history
In some environments the fs watcher falls back to polling for
changes. Both our current watcher and the proposed new watcher
both had support for user-defined polling intervals. I see no
reason not to add this for users who want extra control.

Fixes sass#801.
  • Loading branch information
xzyfer committed Sep 21, 2015
1 parent f6b5fd2 commit 7fd03e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var cli = meow({
' --source-map-root Base path, will be emitted in source-map as is',
' --include-path Path to look for imported files',
' --follow Follow symlinked directories',
' --poll-interval The filesystem polling interval in ms when the watcher has to poll',
' --precision The amount of precision allowed in decimal numbers',
' --importer Path to .js file containing custom importer',
' --functions Path to .js file containing custom functions',
Expand Down Expand Up @@ -240,7 +241,11 @@ function watch(options, emitter) {
watch.push(i);
}

var gaze = new Gaze();
if (options.pollInterval && typeof options.pollInterval !== 'number') {
emitter.emit('error', 'The --poll-interval must be an integer.');
}

var gaze = new Gaze(null, { interval: options.pollInterval });
gaze.add(watch);
gaze.on('error', emitter.emit.bind(emitter, 'error'));

Expand Down
17 changes: 16 additions & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var assert = require('assert'),
LIBSASS_VERSION = null;

describe('cli', function() {

before(function(done) {
var bin = spawn(cli, ['-v']);
bin.stdout.setEncoding('utf8');
Expand Down Expand Up @@ -235,6 +235,21 @@ describe('cli', function() {
}, 100);
});

it.only('should error when watching and --poll-interval is not an integer', function(done) {
var src = fixture('simple/tmp.scss');
var bin = spawn(cli, ['--watch', src]);
var didEmit = false;

bin.stderr.once('data', function() {
didEmit = true;
});

bin.once('close', function() {
assert.equal(didEmit, true);
done();
});
});

it('should emit `warn` on file change when using --watch option', function(done) {
var src = fixture('simple/tmp.scss');

Expand Down

0 comments on commit 7fd03e6

Please # to comment.