diff --git a/.changeset/unlucky-years-look.md b/.changeset/unlucky-years-look.md new file mode 100644 index 0000000000..5cb61fd270 --- /dev/null +++ b/.changeset/unlucky-years-look.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Update the ignore module (`--only`/`--ignore`/`.shopifyignore`) to be backward compatible with (Ruby) Shopify CLI 2 diff --git a/packages/cli-kit/src/public/node/fs.ts b/packages/cli-kit/src/public/node/fs.ts index ea2a985b93..b15482257b 100644 --- a/packages/cli-kit/src/public/node/fs.ts +++ b/packages/cli-kit/src/public/node/fs.ts @@ -522,6 +522,7 @@ export async function findPathUp( export interface MatchGlobOptions { matchBase: boolean + noglobstar: boolean } /** @@ -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) } diff --git a/packages/theme/src/cli/utilities/asset-ignore.test.ts b/packages/theme/src/cli/utilities/asset-ignore.test.ts index fb8d537912..b9aa35d12f 100644 --- a/packages/theme/src/cli/utilities/asset-ignore.test.ts +++ b/packages/theme/src/cli/utilities/asset-ignore.test.ts @@ -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']} @@ -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']} diff --git a/packages/theme/src/cli/utilities/asset-ignore.ts b/packages/theme/src/cli/utilities/asset-ignore.ts index 518f960927..eba1239ac3 100644 --- a/packages/theme/src/cli/utilities/asset-ignore.ts +++ b/packages/theme/src/cli/utilities/asset-ignore.ts @@ -51,7 +51,12 @@ 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 @@ -59,7 +64,7 @@ function matchGlob(key: string, pattern: string) { // 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