From 01b0abcc988599a6fa0bb035665e6be820375abd Mon Sep 17 00:00:00 2001 From: Benjamin Haines Date: Mon, 4 Apr 2016 13:53:53 +1200 Subject: [PATCH 1/2] Add --poll flag Use polling to monitor for changes. Omitting the interval will default to 100ms. This option is useful if you're watching an NFS volume. --- index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 20f862a..34a1b72 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,10 @@ var argv = require("yargs") .describe('s', 'Alternative input syntax parser') .alias('p', 'parser') .describe('p', 'Alternative CSS parser') + .option('poll', { + describe: 'Use polling to monitor for changes.', + default: false, + }) .alias('t', 'stringifier') .describe('t', 'Alternative output stringifier') .alias('w', 'watch') @@ -146,8 +150,16 @@ async.forEach(inputFiles, compile, onError); function fsWatcher(entryPoints) { var watchedFiles = entryPoints; var index = {}; // source files by entry point + var opts = {}; + + if (argv.poll) { + opts.usePolling = true; + } + if (typeof argv.poll === 'number') { + opts.interval = argv.poll; + } - var watcher = require('chokidar').watch(watchedFiles); + var watcher = require('chokidar').watch(watchedFiles, opts); // recompile if any watched file is modified // TODO: only recompile relevant entry point watcher.on('change', function() { From 09bca4cfd495eaa34bdbee5f3ce58b26f5c904c1 Mon Sep 17 00:00:00 2001 From: RyanZim Date: Sat, 20 Aug 2016 11:44:04 -0400 Subject: [PATCH 2/2] Add test for --poll --- Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile b/Makefile index aaa3d55..d9b9998 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,17 @@ test-watch: test/import-*.css kill `cat test/watch.pid` # FIXME: never reached on failure rm test/watch.pid +test-watch-poll: test/import-*.css + echo '@import "import-foo.css";' > test/import-index.css + ./bin/postcss -c test/config-watch.js -w --poll & echo $$! > test/watch.pid + sleep 1 + $(DIFF) test/build/watch.css test/ref/watch-1.css + echo '@import "import-bar.css";' >> test/import-index.css + sleep 1 + $(DIFF) test/build/watch.css test/ref/watch-2.css + kill `cat test/watch.pid` # FIXME: never reached on failure + rm test/watch.pid + test-local-plugins: cd test; ../bin/postcss --use a-dummy-plugin --local-plugins -o build/local-plugins in.css