fix: handle negation patterns correctly in glob-loader watcher#16937
Closed
godfengliang wants to merge 2 commits into
Closed
fix: handle negation patterns correctly in glob-loader watcher#16937godfengliang wants to merge 2 commits into
godfengliang wants to merge 2 commits into
Conversation
When globOptions.pattern is an array containing negation entries like ['src/content/*.md', '!src/content/README.md'], picomatch.isMatch() treats each array element independently and returns true if ANY pattern matches - including negation patterns themselves. This causes every changed file to be treated as a collection entry, producing schema errors for unrelated files like .astro/data-store.json. The fix uses picomatch() to compile patterns into a matcher function that correctly handles negation patterns within the array. Fixes withastro#16851
🦋 Changeset detectedLatest commit: bef9311 The changes in this PR will be included in the next version bump. This PR includes changesets to release 401 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In , the dev-mode file watcher uses to decide whether a changed file belongs to the collection.
When is an array containing negation entries (e.g. ), treats each array element independently and returns if ANY pattern matches, including the negation entry itself.
This causes every changed file to be treated as a collection entry, producing schema errors for unrelated files like .
Repro from issue
Solution
Replace with a compiled matcher created by . The compiled matcher function correctly handles negation patterns within arrays.
After fix
Fixes #16851