-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(util): Replace micromatch with picomatch to fix issues with negated globs #11287
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome, thanks for doing this!
I'm happy to change to using picomatch directly 👍
Co-authored-by: Simen Bekkhus <[email protected]>
I don't know if you dug into the git history here, but the place you're changing now comes from #10131. If there is some better way than sorta replicating what micromatch does internally than what we landed on there, that'd be awesome 🙂 |
I only saw the inline comments but haven't really investigated. From the top of my head, I don't really know if this can be done with Edit: Also the reason for #10131 probably was updating from mm 3 to 4 because 3 had an internal in-memory cache so it would never parse the same glob twice. mm 4 on the other hand has no internal cache and keeps parsing over and over again. So thinking more about it #10131 might actually have been a partial fix for #9457, but there are still direct calls to |
Wonderful, thanks!
Any chance of re-adding a cache? I guess we could also create some wrapper module around micromatch with a cache (sorta ish what #10131 did, but broader) |
}, | ||
"devDependencies": { | ||
"@types/graceful-fs": "^4.1.2", | ||
"@types/is-ci": "^2.0.0", | ||
"@types/micromatch": "^4.0.0" | ||
"@types/micromatch": "^4.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need this one?
Published in |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This starts fixing some of the issues mentioned in #9464.
Problem 1:
This snippet does not ignore anything right now when run through
globsToMatcher
because the second glob is not considered negated by micormatch/picomatch. Instead it is considerednegatedExtglob
. Unfortunatelly thescan()
API of micromatch does not expose this detail. There is a PR for adding it (micromatch/picomatch#79).The reason why I completely exchanged
micromatch
withpicomatch
is that picomatch has the option to return the parse-state, which makesscan
completely unnecessary and shaving off a little bit of work. To visualize it:So basically right now
scan()
scans for features in the glob and then parse has to do the same thing again for parsing. With the PR the state from parsing is used to figure out if the glob is negated.So to conclude:
There are two options:
negatedExtglob
to thescan
API of micromatch and use this then similar to how it is used in this PR.negatedExtglob
and also makesscan
obsolete.Not sure what you prefer?
Also micromatch was updated to 4.0.4 in devDepedencies because the negated extglob problem was fixed in this version in
micromatch()
(micromatch/picomatch#78, micromatch/micromatch#213).Test plan
Added unit tests.
Missing