Skip to content

[Refactor] Use partition helper in filterRegexValues - #8598

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor-maintenance-35547738595
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
refactor-maintenance-35547738595

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

filterRegexValues in packages/theme/src/cli/utilities/asset-ignore.ts hand-rolled a split of ignore patterns into negated (!-prefixed) and normal ones. It walked the list three times — filter for the negated patterns, map to strip the !, then a second filter with the inverted predicate — and shadowed the regexList parameter name in each callback, so the predicate read as regexList.startsWith('!') on what is actually a single pattern.

@shopify/cli-kit/common/collection already exports a partition helper for exactly this, and it is already used elsewhere in the repo (packages/app/src/cli/services/deploy/upload.ts).

WHAT is this pull request doing?

Replaces the three-pass split with a single partition call, and renames the callback parameter to pattern so it describes the element rather than the list.

The return type is now an explicit [string[], string[]] tuple. That makes the = [] destructuring defaults at the three call sites provably unreachable, so they are removed — the array-literal return could never have produced undefined elements, and the defaults only obscured that.

Behavior is unchanged: partition keeps the truthy group first, so the negated group is destructured first and then has its ! prefix stripped, preserving the original [normalPatterns, negatedPatterns] return order and relative ordering within each group.

How to manually test your changes?

In a theme directory with a .shopifyignore containing a mix of normal and negated (!-prefixed) patterns:

shopify theme push --dry-run
shopify theme pull --only "templates/*.json"
shopify theme push --ignore "assets/*" --ignore "!assets/keep.css"

Files matching a negated pattern should still be included, exactly as before.

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing — I've identified the correct bump type (patch for bug fixes · minor for new features · major for breaking changes) and added a changeset with pnpm changeset add

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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants