From 07ff58ad565dea3105e8c93ceab61467b67fc684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaras=C5=82a=C5=AD=20Viktor=C4=8Dyk?= Date: Mon, 28 Jul 2025 17:02:08 +0200 Subject: [PATCH] improve glob performance by not ignoring negate --- packages/glob/__tests__/internal-pattern-helper.test.ts | 4 ++-- packages/glob/src/internal-pattern-helper.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/glob/__tests__/internal-pattern-helper.test.ts b/packages/glob/__tests__/internal-pattern-helper.test.ts index 1d60f6b3b4..6e4aea71eb 100644 --- a/packages/glob/__tests__/internal-pattern-helper.test.ts +++ b/packages/glob/__tests__/internal-pattern-helper.test.ts @@ -128,7 +128,7 @@ describe('pattern-helper', () => { ]) }) - it('partialMatch skips negate patterns', () => { + it('partialMatch avoids going deep by respecting negate patterns', () => { const root = IS_WINDOWS ? 'C:\\' : '/' const patterns = [ `${root}search1/foo/**`, @@ -143,7 +143,7 @@ describe('pattern-helper', () => { expect(patternHelper.partialMatch(patterns, `${root}search2`)).toBeTruthy() expect( patternHelper.partialMatch(patterns, `${root}search2/bar`) - ).toBeTruthy() + ).toBeFalsy() expect(patternHelper.partialMatch(patterns, `${root}search3`)).toBeFalsy() expect( patternHelper.partialMatch(patterns, `${root}search3/bar`) diff --git a/packages/glob/src/internal-pattern-helper.ts b/packages/glob/src/internal-pattern-helper.ts index e0cf3a6a39..71f705fd1f 100644 --- a/packages/glob/src/internal-pattern-helper.ts +++ b/packages/glob/src/internal-pattern-helper.ts @@ -77,5 +77,8 @@ export function match(patterns: Pattern[], itemPath: string): MatchKind { * Checks whether to descend further into the directory */ export function partialMatch(patterns: Pattern[], itemPath: string): boolean { - return patterns.some(x => !x.negate && x.partialMatch(itemPath)) + return ( + patterns.some(x => !x.negate && x.partialMatch(itemPath)) && + !patterns.some(x => x.negate && x.match(itemPath)) + ) }