Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-glob-negation-pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
astro: patch
---

Fix glob-loader watcher to correctly handle negation patterns in file watching
8 changes: 7 additions & 1 deletion packages/astro/src/content/loaders/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,14 @@ export function glob(globOptions: GlobOptions & { [secretLegacyFlag]?: boolean }

watcher.add(filePath);

// Use picomatch() to compile patterns into a matcher function.
// picomatch.isMatch() with array patterns containing negation entries (!pattern)
// incorrectly treats each array element independently, causing negation patterns
// to match everything. A compiled matcher correctly handles negation patterns.
// See https://github.com/withastro/astro/issues/16851
const matchGlob = picomatch(globOptions.pattern);
const matchesGlob = (entry: string) =>
!entry.startsWith('../') && picomatch.isMatch(entry, globOptions.pattern);
!entry.startsWith('../') && matchGlob(entry);

const basePath = fileURLToPath(baseDir);

Expand Down
Loading