Skip to content

Commit

Permalink
WIP - if we kept backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilGenius13 committed Jan 22, 2025
1 parent c795653 commit 6955120
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ export async function findPathUp(
export interface MatchGlobOptions {
matchBase: boolean
noglobstar: boolean
dot?: boolean
}

/**
Expand Down
13 changes: 6 additions & 7 deletions packages/theme/src/cli/utilities/asset-ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,16 @@ describe('asset-ignore', () => {
])
})

test(`should return all files in a directory when only option is a directory pattern`, () => {
test(`should return all files in a directory when using proper glob pattern`, () => {
const options = {
only: ['assets/'],
only: ['templates/**/*'],
}

const actualChecksums = applyIgnoreFilters(checksums, options)

expect(actualChecksums).toEqual([
{key: 'assets/basic.css', checksum: '00000000000000000000000000000000'},
{key: 'assets/complex.css', checksum: '11111111111111111111111111111111'},
{key: 'assets/image.png', checksum: '22222222222222222222222222222222'},
{key: 'templates/404.json', checksum: '6666666666666666666666666666666'},
{key: 'templates/customers/account.json', checksum: '7777777777777777777777777777777'},
])
})
})
Expand Down Expand Up @@ -360,9 +359,9 @@ describe('asset-ignore', () => {
])
})

test(`should ignore all files in a directory when ignore option is a directory pattern`, () => {
test(`should ignore all files in a directory when using proper glob pattern`, () => {
const options = {
ignore: ['assets/'],
ignore: ['assets/**/*'],
}

const actualChecksums = applyIgnoreFilters(checksums, options)
Expand Down
25 changes: 23 additions & 2 deletions packages/theme/src/cli/utilities/asset-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {uniqBy} from '@shopify/cli-kit/common/array'
import {fileExists, readFile, matchGlob as originalMatchGlob} from '@shopify/cli-kit/node/fs'
import {outputDebug} from '@shopify/cli-kit/node/output'
import {joinPath} from '@shopify/cli-kit/node/path'
import {renderWarning} from '@shopify/cli-kit/node/ui'

const SHOPIFY_IGNORE = '.shopifyignore'
const templatesRegex = /templates\/\*(\.(json|liquid))?$/
Expand Down Expand Up @@ -89,8 +90,11 @@ function matchGlob(key: string, pattern: string) {
if (result) return true

if (!pattern.includes('*') && pattern.endsWith('/')) {
const directoryPattern = `${pattern}**`
return originalMatchGlob(key, directoryPattern, matchOpts)
renderWarning({
headline: 'Directory pattern not supported.',
body: `Try using ${pattern}**/* instead.`,
})
return false
}

// When the the standard match fails and the pattern includes '/*.', we
Expand All @@ -100,6 +104,23 @@ function matchGlob(key: string, pattern: string) {
return originalMatchGlob(key, pattern.replace(templatesRegex, 'templates/**/*$1'), matchOpts)
}

if (pattern.includes('**/*')) {
if (pattern.startsWith('templates/') && pattern.includes('**/*.')) {
return (
key.split('/').length > 2 &&
originalMatchGlob(key, pattern, {
...matchOpts,
noglobstar: false,
})
)
}

return originalMatchGlob(key, pattern, {
...matchOpts,
noglobstar: false,
})
}

return false
}

Expand Down

0 comments on commit 6955120

Please sign in to comment.