From 995b810e9f2e69eb07a4971e5d8a00d1070a7f7a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 00:36:47 +0000 Subject: [PATCH] [Refactor] Use partition helper in filterRegexValues Replace the three-pass filter/map/filter in filterRegexValues with the existing partition helper from @shopify/cli-kit/common/collection, which splits the list in a single pass. Typing the return as a [string[], string[]] tuple also lets the call sites drop their unreachable `= []` destructuring defaults. Co-Authored-By: Claude Opus 4.8 --- packages/theme/src/cli/utilities/asset-ignore.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/theme/src/cli/utilities/asset-ignore.ts b/packages/theme/src/cli/utilities/asset-ignore.ts index 1dd557ab387..5a05880f84e 100644 --- a/packages/theme/src/cli/utilities/asset-ignore.ts +++ b/packages/theme/src/cli/utilities/asset-ignore.ts @@ -1,4 +1,5 @@ import {uniqBy} from '@shopify/cli-kit/common/array' +import {partition} from '@shopify/cli-kit/common/collection' import {fileExists, readFile, matchGlob as originalMatchGlob} from '@shopify/cli-kit/node/fs' import {outputDebug} from '@shopify/cli-kit/node/output' import {joinPath} from '@shopify/cli-kit/node/path' @@ -16,9 +17,9 @@ export function applyIgnoreFilters( const ignoreOptions = options.ignore ?? [] const onlyOptions = options.only ?? [] - const [normalShopifyPatterns = [], negatedShopifyPatterns = []] = filterRegexValues(shopifyIgnore) - const [normalIgnorePatterns = [], negatedIgnorePatterns = []] = filterRegexValues(ignoreOptions) - const [normalOnlyPatterns = [], negatedOnlyPatterns = []] = filterRegexValues(onlyOptions) + const [normalShopifyPatterns, negatedShopifyPatterns] = filterRegexValues(shopifyIgnore) + const [normalIgnorePatterns, negatedIgnorePatterns] = filterRegexValues(ignoreOptions) + const [normalOnlyPatterns, negatedOnlyPatterns] = filterRegexValues(onlyOptions) let filteredFiles = files.filter(filterBy(normalShopifyPatterns, '.shopifyignore')) filteredFiles = filteredFiles.filter(filterBy(normalIgnorePatterns, '--ignore')) @@ -70,13 +71,10 @@ export async function getPatternsFromShopifyIgnore(root: string) { .filter((line) => line && !line.startsWith('#')) } -function filterRegexValues(regexList: string[]) { - const negatedPatterns = regexList - .filter((regexList) => regexList.startsWith('!')) - .map((regexList) => regexList.slice(1)) - const normalPatterns = regexList.filter((regexList) => !regexList.startsWith('!')) +function filterRegexValues(regexList: string[]): [string[], string[]] { + const [negatedPatterns, normalPatterns] = partition(regexList, (pattern) => pattern.startsWith('!')) - return [normalPatterns, negatedPatterns] + return [normalPatterns, negatedPatterns.map((pattern) => pattern.slice(1))] } function matchGlob(key: string, pattern: string) {