-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
feat: Allow random order of globs #11293
Conversation
BREAKING CHANGE: This changes the behavior of all config options ot not respect the order of the globs similar to how it was in jest 24 and lower.
const isMatch = picomatch(glob, picomatchOptions, true); | ||
const negated = glob.startsWith('!'); | ||
const isMatch = picomatch( | ||
negated ? glob.slice(1) : glob, |
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 glob.slice(1)
is the fix for the "wrong" negation behavior mentioned in the main PR text.
By removing the exclamation mark we do match the ignored path but later know because of the negated
flag that a match means ignore this file.
This is very interesting, thanks for putting it together along with a thorough explanation! I have to say I find /cc @cpojer @jeysal @thymikee thoughts? As a side note, this change in behavior between v3 and v4 should IMO be mentioned in the changelog: https://github.com/micromatch/micromatch/blob/5318752abc2f33153b3ccddf9f1f3b7682000a43/CHANGELOG.md#400---2019-03-20 |
I agree that on the ordering, micromatch 4 makes more sense (and seems strictly more powerful?), I'd like to be able to specify exceptions to a negated glob later on. |
I agree, I would keep the current behavior. |
Okay will create PR for the docs and describe how globs are applied. |
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. |
BREAKING CHANGE: This changes the behavior of all config options with arrays of globs to not respect the order similar to how it was in jest 24 and lower.
Fixes #9464 (one or the other way)
Summary
Some history: micromatch 3 (jest 24 and lower) allowed random order of globs (like
['!foo.js', 'foo.js']
would ignorefoo.js
), whereas micromatch 4 changed this and respects the order (['!foo.js', 'foo.js']
would matchfoo.js
because the second glob runs after the first)Also negations work slightly different, for example
['*/**.js', '!(test)/**/*.js']
in mm 3 would matchfoo.js
, in mm 4 it would not. Both versions are kinda correct because the negated glob alone only matches "any js file in at least one subfolder that is not named test", because of!(test)/
(this is also that way in globs in bash), but combined with the first (positive) glob the behavior is outside of the "specified" scope of globbing and more like up to the libs how the combine and merge multiple globs.Both of these changes also happened in
jest
in version 25 whenmicromatch
was updated to version 4. (e.g.collectCoverageFrom
).Unfortunately, there is no right or wrong here and it's more based on opinion, so treat this PR more like a discussion for now.
So either jest keeps the way it does globs right now (ordered globs) which allows things like:
To accomplish the same with this PR:
Or switch back to the old behavior (jest 24 or lower) where one can do:
Oh and the same can independently be decided for the negated (mis)behavior, although that could actually be considered broken and be fixed, as hardly anyone will be able to take advantage of the current feature. (I will bring this also up in mm/pm itself)
Test plan
Adjusted unit tests and added new unit tests
TODO