Skip to content

Commit

Permalink
Remove the warning message from the ignore-module because some files …
Browse files Browse the repository at this point in the history
…can only be ignored using backward-compatible patterns
  • Loading branch information
karreiro committed Oct 16, 2024
1 parent 74f8888 commit c75c8e2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-grapes-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Remove the warning message from the ignore-module because some files can only be ignored using backward-compatible patterns
46 changes: 7 additions & 39 deletions packages/theme/src/cli/utilities/asset-ignore.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {applyIgnoreFilters, getPatternsFromShopifyIgnore} from './asset-ignore.js'
import {ReadOptions, fileExists, readFile} from '@shopify/cli-kit/node/fs'
import {outputWarn} from '@shopify/cli-kit/node/output'
import {test, describe, beforeEach, vi, expect} from 'vitest'

vi.mock('@shopify/cli-kit/node/fs', async () => {
Expand Down Expand Up @@ -74,7 +73,7 @@ describe('asset-ignore', () => {
describe('applyIgnoreFilters', () => {
test(`returns entire list of checksums when there's no filter to apply`, async () => {
// Given/When
const actualChecksums = await applyIgnoreFilters(checksums, {})
const actualChecksums = applyIgnoreFilters(checksums, {})

// Then
expect(actualChecksums).toEqual(checksums)
Expand All @@ -94,7 +93,7 @@ describe('asset-ignore', () => {
}

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

// Then
expect(actualChecksums).toEqual([{key: 'assets/basic.css', checksum: '00000000000000000000000000000000'}])
Expand All @@ -105,7 +104,7 @@ describe('asset-ignore', () => {
const options = {ignore: ['config/*', 'templates/*', 'assets/image.png']}

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

// Then
expect(actualChecksums).toEqual([
Expand All @@ -120,7 +119,7 @@ describe('asset-ignore', () => {
const options = {only: ['config/*', 'assets/image.png']}

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

// Then
expect(actualChecksums).toEqual([
Expand All @@ -135,7 +134,7 @@ describe('asset-ignore', () => {
const options = {ignore: ['*.css']}

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

// Then
expect(actualChecksums).toEqual([
Expand All @@ -153,7 +152,7 @@ describe('asset-ignore', () => {
const options = {only: ['templates/*.json']}

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

// Then
expect(actualChecksums).toEqual([
Expand All @@ -167,43 +166,12 @@ describe('asset-ignore', () => {
const options = {only: ['templates/**/*.json']}

// When
const actualChecksums = await applyIgnoreFilters(checksums, options)
const actualChecksums = 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']}
// When
await applyIgnoreFilters(checksums, options)
// Then
expect(vi.mocked(outputWarn)).not.toHaveBeenCalled()
})

test(`outputs warnings when there are glob pattern modifications required for subdirectories`, async () => {
// Given
const options = {only: ['templates/*.json']}

// When
await applyIgnoreFilters(checksums, options)

// Then
expect(vi.mocked(outputWarn)).toHaveBeenCalledTimes(1)
})

test('only outputs a single warning for duplicated glob patterns', async () => {
// Given
const options = {only: ['templates/*.json'], ignore: ['templates/*.json']}

// When
await applyIgnoreFilters(checksums, options)

// Then
expect(vi.mocked(outputWarn)).toHaveBeenCalledTimes(1)
})
})
})
18 changes: 1 addition & 17 deletions packages/theme/src/cli/utilities/asset-ignore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {fileExists, readFile, matchGlob as originalMatchGlob} from '@shopify/cli-kit/node/fs'
import {outputDebug, outputWarn} from '@shopify/cli-kit/node/output'
import {outputDebug} from '@shopify/cli-kit/node/output'
import {joinPath} from '@shopify/cli-kit/node/path'

const SHOPIFY_IGNORE = '.shopifyignore'
Expand All @@ -13,8 +13,6 @@ export function applyIgnoreFilters<T extends {key: string}>(
const ignoreOptions = options.ignore ?? []
const onlyOptions = options.only ?? []

raiseWarningForNonExplicitGlobPatterns([...shopifyIgnore, ...ignoreOptions, ...onlyOptions])

return files
.filter(filterBy(shopifyIgnore, '.shopifyignore'))
.filter(filterBy(ignoreOptions, '--ignore'))
Expand Down Expand Up @@ -73,20 +71,6 @@ function matchGlob(key: string, pattern: string) {
return false
}

export function raiseWarningForNonExplicitGlobPatterns(patterns: string[]) {
const allPatterns = new Set(patterns)
allPatterns.forEach((pattern) => {
if (shouldReplaceGlobPattern(pattern)) {
outputWarn(
`Warning: The pattern '${pattern}' does not include subdirectories. To maintain backwards compatibility, we have modified your pattern to ${pattern.replace(
templatesRegex,
'templates/**/*$1',
)} to explicitly include subdirectories.`,
)
}
})
}

function shouldReplaceGlobPattern(pattern: string): boolean {
return templatesRegex.test(pattern)
}
Expand Down
7 changes: 1 addition & 6 deletions packages/theme/src/cli/utilities/theme-fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
partitionThemeFiles,
readThemeFile,
} from './theme-fs.js'
import {
getPatternsFromShopifyIgnore,
applyIgnoreFilters,
raiseWarningForNonExplicitGlobPatterns,
} from './asset-ignore.js'
import {getPatternsFromShopifyIgnore, applyIgnoreFilters} from './asset-ignore.js'
import {removeFile, writeFile} from '@shopify/cli-kit/node/fs'
import {test, describe, expect, vi, beforeEach} from 'vitest'
import chokidar from 'chokidar'
Expand Down Expand Up @@ -279,7 +275,6 @@ describe('theme-fs', () => {
const themeFileSystem = mountThemeFileSystem(root, options)
await themeFileSystem.ready()

expect(raiseWarningForNonExplicitGlobPatterns).toHaveBeenCalledOnce()
expect(getPatternsFromShopifyIgnore).toHaveBeenCalledWith(root)
expect(themeFileSystem.applyIgnoreFilters(files)).toEqual([{key: 'assets/file.json'}])
expect(applyIgnoreFilters).toHaveBeenCalledWith(files, {
Expand Down
11 changes: 1 addition & 10 deletions packages/theme/src/cli/utilities/theme-fs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {calculateChecksum} from './asset-checksum.js'
import {
applyIgnoreFilters,
raiseWarningForNonExplicitGlobPatterns,
getPatternsFromShopifyIgnore,
} from './asset-ignore.js'
import {applyIgnoreFilters, getPatternsFromShopifyIgnore} from './asset-ignore.js'
import {Notifier} from './notifier.js'
import {createSyncingCatchError} from './errors.js'
import {DEFAULT_IGNORE_PATTERNS, timestampDateFormat} from '../constants.js'
Expand Down Expand Up @@ -86,11 +82,6 @@ export function mountThemeFileSystem(root: string, options?: ThemeFileSystemOpti
.then((filesPaths) => Promise.all([getPatternsFromShopifyIgnore(root), ...filesPaths.map(read)]))
.then(([ignoredPatterns]) => {
filterPatterns.ignoreFromFile.push(...ignoredPatterns)
raiseWarningForNonExplicitGlobPatterns([
...filterPatterns.ignoreFromFile,
...filterPatterns.ignore,
...filterPatterns.only,
])
})

const getKey = (filePath: string) => relativePath(root, filePath)
Expand Down

0 comments on commit c75c8e2

Please sign in to comment.