Skip to content

Commit

Permalink
Merge pull request #4563 from Shopify/fix-4472
Browse files Browse the repository at this point in the history
Fix `shopify theme pull --only <value>` so it does not delete ignored files
  • Loading branch information
karreiro authored Oct 4, 2024
2 parents 327e554 + 51178f2 commit 36a4061
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/witty-insects-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Fix `shopify theme pull --only <value>` so it does not delete ignored files
20 changes: 20 additions & 0 deletions packages/theme/src/cli/utilities/theme-downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ describe('theme-downloader', () => {
expect(spy).toHaveBeenCalledWith('assets/deleteme.css')
})

test('does not delete files when filters are passed', async () => {
// Given
const remote: Checksum[] = []
const files = new Map<string, ThemeAsset>([
['assets/keepme.css', {key: 'assets/keepme.css', checksum: '1', value: 'content'}],
])
const fileSystem = fakeThemeFileSystem(root, files, {
filters: {
only: ['templates/*'],
},
})
const spy = vi.spyOn(fileSystem, 'delete')

// When
await downloadTheme(remoteTheme, adminSession, remote, fileSystem, downloadOptions)

// Then
expect(spy).not.toHaveBeenCalled()
})

test('does not delete files when nodelete is set', async () => {
// Given
const downloadOptions = {nodelete: true}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/src/cli/utilities/theme-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function buildDeleteTasks(remoteChecksums: Checksum[], themeFileSystem: ThemeFil

const remoteKeys = new Set(remoteChecksums.map((checksum) => checksum.key))

const localKeys = Array.from(themeFileSystem.files.keys())
const localKeys = themeFileSystem.applyIgnoreFilters([...themeFileSystem.files.values()]).map(({key}) => key)
const localFilesToBeDeleted = localKeys.filter((key) => !remoteKeys.has(key))

return localFilesToBeDeleted.map((key) => {
Expand Down

0 comments on commit 36a4061

Please sign in to comment.