fast-glob
fast-glob copied to clipboard
fast-glob doesn't match list segments correctly
Environment
- OS Version: MacOS Big Sur (11.6.4)
- Node.js Version: 17
Actual behavior
List-segments are matched in a way that is compatible with glob
Expected behavior
Some matches are not reported properly when using glob patterns containing quotes
Steps to reproduce
- See linked PR with test: #366
@mrmlnc When checking this out in a bit more detail, it seems like when matching list segments the globstar (**)
can't evaluate to zero directories at the beginning of the pattern. This isn't standard, as it should be zero or more
.
To be clear, this means you get equal results currently for:
{book.xml,library/**/a/book.md}
but failing results for:
{book.xml,**/library/*/book.md}
Followed up on this a bit more, the issue might be in micromatch or picomatch rather then the fast-glob package. It looks like for the above glob pattern, makeRe
is returning this.
^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$
It should return something closer to this:
^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)library\/(?!\.)(?=.)[^/]*?\/book\.md))$
There is a pair of characters between literal library
and the end of the group behind it (\/
) that requires a slash at the beginning.
- ^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$
+ ^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)library\/(?!\.)(?=.)[^/]*?\/book\.md))$
'**/library/*/book.md'
micromatch
{
re: /^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/
}
fast-glob.utils.pattern.makeRe
{
re: /^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/
}
---
'{book.xml,**/library/*/book.md}'
micromatch
{
re: /^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
}
fast-glob.utils.pattern.makeRe
{
re: /^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
}
Well, looks like this is really a problem in the micromatch
package.
// {book.xml,**/library/*/book.md}
/^(?:(book\.xml|(?:(?:(?!(?:^|\/)\.).)*?)\/library\/(?!\.)(?=.)[^/]*?\/book\.md))$/
// **/library/*/book.md
/^(?:(?:^|\/|(?:(?:(?!(?:^|\/)\.).)*?)\/)library\/(?!\.)(?=.)[^/]*?\/book\.md)$/
A little later I will create an issue in micromatch and try to find the reason for the current behavior.
@mrmlnc Is there an upstream issue link for this? I'm trying to keep an eye on this. If there is any way that I can help out, let me know. This issue currently presents in Nx when we combine glob patterns for finding plugin project files.
Hey @mrmlnc! Just checking in on this again. If someone can point me to the right spot to start making changes I'd be happy to investigate this a bit further myself.
I repro'd on the picomatch repo and opened an issue there, hoping to accelerate this one too. Let me know if there is anything else from my side that could help with this.
Already fixed in the master by #395 in this package. Will be shipped with 3.3.0
.
Awesome! Thanks for the fix @mrmlnc! Happy maintainers month, hoping things are well for you.