browserify / watchify

watch mode for browserify builds
Other
1.79k stars 181 forks source link

Don't attach a watcher for files which are ignored. #236

Closed codeviking closed 9 years ago

codeviking commented 9 years ago

@zertosh Updated PR with the fix such that a watcher isn't attached to files which are explicitly ignored.

zertosh commented 9 years ago

I think this does it:

diff --git a/index.js b/index.js
index 6fb2398a..40647865 100644
--- a/index.js
+++ b/index.js
@@ -1,8 +1,8 @@
 var through = require('through2');
 var path = require('path');
+var anymatch = require('anymatch');
 var chokidar = require('chokidar');
 var xtend = require('xtend');
-var anymatch = require('anymatch');

 module.exports = watchify;
 module.exports.args = {
@@ -19,7 +19,7 @@ function watchify (b, opts) {

     var wopts = {persistent: true};
     if (opts.ignoreWatch) {
-        wopts.ignored = opts.ignoreWatch !== true
+        var ignored = opts.ignoreWatch !== true
             ? opts.ignoreWatch
             : '**/node_modules/**';
     }
@@ -96,10 +96,11 @@ function watchify (b, opts) {

     function watchFile (file, dep) {
         dep = dep || file;
-        // don't watch files which are explicitly ignored
-        if (wopts.ignored && (ignoredFiles[file] || anymatch([wopts.ignored], dep))) {
-          ignoredFiles[file] = true;
-          return;
+        if (ignored) {
+          if (!ignoredFiles.hasOwnProperty(file)) {
+            ignoredFiles[file] = anymatch(ignored, file);
+          }
+          if (ignoredFiles[file]) return;
         }
         if (!fwatchers[file]) fwatchers[file] = [];
         if (!fwatcherFiles[file]) fwatcherFiles[file] = [];
codeviking commented 9 years ago

Great points, thanks for the patch. I'll update and test locally.

No worries on timing!