node-glob-gitignore icon indicating copy to clipboard operation
node-glob-gitignore copied to clipboard

Fix negative prefixed positive tests

Open bcomnes opened this issue 3 years ago • 1 comments

Here is a problem I noticed:

!(node_modules)**/*.{png,ico} doesn't match anything in node-glob-ignore, but it does match when passed directly to glob. (E.g. any png or ico file in a subdirectory in the current directly that's not inside of node_modules, and no deeper).

This is due to this line dropping the glob:

https://github.com/kaelzhang/node-glob-gitignore/blob/c8a236a52a14e6d1e8ba692c4a210dc79e817e7e/src/util.js#L83-L88

Now, I could pass in ./!(node_modules)**/*.{png,ico} or **/!(node_modules)**/*.{png,ico} (probably the more desirable glob) but that starts to diverge from globs that work in glob.

I know its better to use the ignore array here, but I'm trying to generally retain the same API of a tool that was formerly using glob.

I'm thinking that's a bug in the design of that function, but I'm curious what you think. Perhaps checking to make sure the negative glob isn't for a group, which would indicate that it is in fact a positively matching glob. That is the fix I added in this PR but looking for your thoughts on the solution.

bcomnes avatar Feb 06 '22 23:02 bcomnes

Hey, just checking back in to see if you have any thoughts on this approach.

bcomnes avatar Feb 11 '22 04:02 bcomnes