Closed yuanchuan closed 4 years ago
The format of the flag might be something else. We need to find the most proper one.
if (condition) {
return { skip: true };
}
or
if (condition) {
return -1;
}
or pass the variable to use
filter(name, skip) {
if (condition) {
return skip;
}
}
or
filter(name, flag) {
if (condition) {
return flag.skip;
}
}
etc.
I like passing the skip
parameter - it's impossible to return the skip
value by accident for existing users, you don't have to remember special values, and it's easy to read.
So if you only want to see changes to .js files that are not in node_modules, you'd have
filter: (name, skip) => {
if (name==='node_modules') return skip
return /\.js$/i.test(name)
}
I think this reads nicely, even though the skip
value is truthy and would normally mean it passes
This is great :) now how to test it...
Would love to see your review @Krinkle :)
It took too long! I'm about to merge this PR. Hope there will be a better solution in the future. Thank you so much!
This is an attempt to fix #93 by introducing a third return value. For example:
I couldn't find a way to write a test at this moment
update
Now this is how to ignore and skip to watch the
node_modules
directory.In order to test it I've also added a new method to get all the watched paths.