[Refactor] Use partition helper in filterRegexValues - #8598
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WHY are these changes introduced?
filterRegexValuesinpackages/theme/src/cli/utilities/asset-ignore.tshand-rolled a split of ignore patterns into negated (!-prefixed) and normal ones. It walked the list three times —filterfor the negated patterns,mapto strip the!, then a secondfilterwith the inverted predicate — and shadowed theregexListparameter name in each callback, so the predicate read asregexList.startsWith('!')on what is actually a single pattern.@shopify/cli-kit/common/collectionalready exports apartitionhelper 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
partitioncall, and renames the callback parameter topatternso 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 producedundefinedelements, and the defaults only obscured that.Behavior is unchanged:
partitionkeeps 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
.shopifyignorecontaining a mix of normal and negated (!-prefixed) patterns:Files matching a negated pattern should still be included, exactly as before.
Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add