Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't ignore first item via ignore function #335

Closed
adamcohen opened this issue Aug 13, 2015 · 3 comments
Closed

can't ignore first item via ignore function #335

adamcohen opened this issue Aug 13, 2015 · 3 comments

Comments

@adamcohen
Copy link

I'm noticing some strange behaviour when passing a function for the ignored parameter if the first call returns true.

var chokidar = require('chokidar')
var count = 0

function ignored (file) {
  console.log('file', file)

  if (count++ === 0) { return true }
  return false
}

chokidar.watch('.', {
  ignored: function (file) { return ignored(file) }
}).on('all', function (event, path) {
  console.log(event, path)
})

Expected output: a list of files in the current directory as each one is passed to the ignored function
Actual output: file . then exit. No other files are examined

If I change the count conditional to something else, like count === 2, it causes the third item to be ignored as expected, and continues passing every other file in the current directory to the ignored function.

Unless I'm missing something here, it seems as though it's not possible to continue execution if you want to ignore the first item passed to the ignore function.

@paulmillr
Copy link
Owner

You're watching .

The directory is passed as a first item to watcher — and to ignored function. If you ignore it then no subdirectories would be served.

That sounds reasonable to me.

@adamcohen
Copy link
Author

Thanks for getting back to me. I was trying to chase down an issue in forever-monitor which started occurring after you switched the watch module to chokidir. This particular block of code in forever-monitor was preventing anything from being watched:

function ignored (file) {
  if (this.watchIgnoreDotFiles && path.basename(file)[0] === '.') {
    return false;
  }
}

The problem is that if you watch ., which is what most people probably use by default, then everything else is ignored by the above conditional. It's definitely reasonable behaviour that if you ignore a directory that all subdirs are ignored. Now that I know this is the case, I'll submit a PR to forever-monitor to fix this issue. Thanks again for your help

@paulmillr
Copy link
Owner

Prob just add the && path !== '.' and that's it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants