From 8b005ac4dea52391d422d0e4bc6ba3a2c3ae037f Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 21 Oct 2025 09:21:04 +0200 Subject: [PATCH] fix(pluginutils): only normalize/parse patterns once in createFilter When passing patterns to createFilter() it would normalize and parse the patterns on every call to the returned filter function. Just do it once at the start instead. --- packages/pluginutils/src/createFilter.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/pluginutils/src/createFilter.ts b/packages/pluginutils/src/createFilter.ts index 86f9d3be5..08d8208eb 100755 --- a/packages/pluginutils/src/createFilter.ts +++ b/packages/pluginutils/src/createFilter.ts @@ -26,19 +26,16 @@ function getMatcherString(id: string, resolutionBase: string | false | null | un const createFilter: CreateFilter = function createFilter(include?, exclude?, options?) { const resolutionBase = options && options.resolve; - const getMatcher = (id: string | RegExp) => - id instanceof RegExp - ? id - : { - test: (what: string) => { - // this refactor is a tad overly verbose but makes for easy debugging - const pattern = getMatcherString(id, resolutionBase); - const fn = pm(pattern, { dot: true }); - const result = fn(what); - - return result; - } - }; + const getMatcher = (id: string | RegExp) => { + if (id instanceof RegExp) { + return id; + } + const pattern = getMatcherString(id, resolutionBase); + const fn = pm(pattern, { dot: true }); + return { + test: (what: string) => fn(what) + }; + }; const includeMatchers = ensureArray(include).map(getMatcher); const excludeMatchers = ensureArray(exclude).map(getMatcher);