diff --git a/.changeset/witty-insects-study.md b/.changeset/witty-insects-study.md new file mode 100644 index 00000000000..be233818522 --- /dev/null +++ b/.changeset/witty-insects-study.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Fix `shopify theme pull --only ` so it does not delete ignored files diff --git a/packages/theme/src/cli/utilities/theme-downloader.test.ts b/packages/theme/src/cli/utilities/theme-downloader.test.ts index d42cc8a8af7..e35c9d5118c 100644 --- a/packages/theme/src/cli/utilities/theme-downloader.test.ts +++ b/packages/theme/src/cli/utilities/theme-downloader.test.ts @@ -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([ + ['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} diff --git a/packages/theme/src/cli/utilities/theme-downloader.ts b/packages/theme/src/cli/utilities/theme-downloader.ts index cb4e2e0a63a..85f082fc8a1 100644 --- a/packages/theme/src/cli/utilities/theme-downloader.ts +++ b/packages/theme/src/cli/utilities/theme-downloader.ts @@ -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) => {