Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shopify theme pull --only <value> so it does not delete ignored files #4563

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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