Skip to content

Commit

Permalink
Theme Upload: Add theme blocks to dependant files
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmengo committed Dec 5, 2024
1 parent a367e70 commit 07ff693
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
30 changes: 19 additions & 11 deletions packages/theme/src/cli/utilities/theme-uploader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ describe('theme-uploader', () => {
['templates/product.json', {key: 'templates/product.json', checksum: '6'}],
['assets/image.png', {key: 'assets/image.png', checksum: '7'}],
['templates/product.context.uk.json', {key: 'templates/product.context.uk.json', checksum: '8'}],
['blocks/block.liquid', {key: 'blocks/block.liquid', checksum: '9'}],
]),
)

Expand All @@ -310,21 +311,17 @@ describe('theme-uploader', () => {
await renderThemeSyncProgress()

// Then
expect(bulkUploadThemeAssets).toHaveBeenCalledTimes(7)
// Mininum theme files start first
expect(bulkUploadThemeAssets).toHaveBeenCalledTimes(8)
// Minimum theme files start first
expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(1, remoteTheme.id, MINIMUM_THEME_ASSETS, adminSession)
// Dependent assets start second
expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(
2,
remoteTheme.id,
[
{
key: 'sections/header.liquid',
},
],
[{key: 'blocks/block.liquid'}],
adminSession,
)
// Independent assets start right before dependent assets start
// Independent assets start right after dependent assets start
expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(
3,
remoteTheme.id,
Expand All @@ -347,17 +344,18 @@ describe('theme-uploader', () => {
remoteTheme.id,
[
{
key: 'sections/header-group.json',
key: 'sections/header.liquid',
},
],
adminSession,
)

expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(
5,
remoteTheme.id,
[
{
key: 'templates/product.json',
key: 'sections/header-group.json',
},
],
adminSession,
Expand All @@ -367,14 +365,24 @@ describe('theme-uploader', () => {
remoteTheme.id,
[
{
key: 'templates/product.context.uk.json',
key: 'templates/product.json',
},
],
adminSession,
)
expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(
7,
remoteTheme.id,
[
{
key: 'templates/product.context.uk.json',
},
],
adminSession,
)
expect(bulkUploadThemeAssets).toHaveBeenNthCalledWith(
8,
remoteTheme.id,
[
{
key: 'config/settings_data.json',
Expand Down
5 changes: 4 additions & 1 deletion packages/theme/src/cli/utilities/theme-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function orderFilesToBeDeleted(files: Checksum[]): Checksum[] {
...fileSets.sectionJsonFiles,
...fileSets.otherJsonFiles,
...fileSets.sectionLiquidFiles,
...fileSets.blockLiquidFiles,
...fileSets.otherLiquidFiles,
...fileSets.configFiles,
...fileSets.staticAssetFiles,
Expand Down Expand Up @@ -237,7 +238,8 @@ function buildUploadJob(
(promise, fileType) => promise.then(() => uploadFileBatches(fileType)),
Promise.resolve(),
)
// Wait for dependent files upload to be started before starting this one:

// Dependant and independant files are uploaded concurrently
const independentFilesUploadPromise = Promise.resolve().then(() => uploadFileBatches(independentFiles.flat()))

const promise = Promise.all([dependentFilesUploadPromise, independentFilesUploadPromise]).then(() => {
Expand Down Expand Up @@ -289,6 +291,7 @@ function orderFilesToBeUploaded(files: ChecksumWithSize[]): {
independentFiles: [fileSets.otherLiquidFiles, fileSets.otherJsonFiles, fileSets.staticAssetFiles],
// Follow order of dependencies:
dependentFiles: [
fileSets.blockLiquidFiles,
fileSets.sectionLiquidFiles,
fileSets.sectionJsonFiles,
fileSets.templateJsonFiles,
Expand Down

0 comments on commit 07ff693

Please sign in to comment.