Skip to content

Commit

Permalink
Update the ignore module (--only/--ignore/.shopifyignore) to be…
Browse files Browse the repository at this point in the history
… backward compatible with (Ruby) Shopify CLI 2
  • Loading branch information
karreiro committed Oct 2, 2024
1 parent 027062c commit d9fff2c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-years-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Update the ignore module (`--only`/`--ignore`/`.shopifyignore`) to be backward compatible with (Ruby) Shopify CLI 2
3 changes: 2 additions & 1 deletion packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ export async function findPathUp(

export interface MatchGlobOptions {
matchBase: boolean
noglobstar: boolean
}

/**
Expand All @@ -531,6 +532,6 @@ export interface MatchGlobOptions {
* @param options - The options to refine the matching approach.
* @returns true if the key matches the pattern, false otherwise.
*/
export function matchGlob(key: string, pattern: string, options: MatchGlobOptions = {matchBase: true}): boolean {
export function matchGlob(key: string, pattern: string, options?: MatchGlobOptions): boolean {
return minimatch(key, pattern, options)
}
15 changes: 14 additions & 1 deletion packages/theme/src/cli/utilities/asset-ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('asset-ignore', () => {
])
})

test(`matching is backward compatible with Shopify CLI 2`, async () => {
test(`matching is backward compatible with Shopify CLI 2 with the templates/*.json pattern`, async () => {
// Given
const options = {only: ['templates/*.json']}

Expand All @@ -162,6 +162,19 @@ describe('asset-ignore', () => {
])
})

test(`matching is backward compatible with Shopify CLI 2 with the templates/**/*.json pattern`, async () => {
// Given
const options = {only: ['templates/**/*.json']}

// When
const actualChecksums = await applyIgnoreFilters(checksums, options)

// Then
expect(actualChecksums).toEqual([
{key: 'templates/customers/account.json', checksum: '7777777777777777777777777777777'},
])
})

test(`only outputs glob pattern subdirectory warnings for the templates folder`, async () => {
// Given
const options = {only: ['assets/*.json', 'config/*.json', 'sections/*.json']}
Expand Down
9 changes: 7 additions & 2 deletions packages/theme/src/cli/utilities/asset-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ export async function getPatternsFromShopifyIgnore(root: string) {
}

function matchGlob(key: string, pattern: string) {
const result = originalMatchGlob(key, pattern)
const matchOpts = {
matchBase: true,
noglobstar: true,
}

const result = originalMatchGlob(key, pattern, matchOpts)

if (result) return true

// When the the standard match fails and the pattern includes '/*.', we
// replace '/*.' with '/**/*.' to emulate Shopify CLI 2.x behavior, as it was
// based on 'File.fnmatch'.
if (shouldReplaceGlobPattern(pattern)) {
return originalMatchGlob(key, pattern.replace('/*.', '/**/*.'))
return originalMatchGlob(key, pattern.replace('/*.', '/**/*.'), matchOpts)
}

return false
Expand Down

0 comments on commit d9fff2c

Please sign in to comment.