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

[Themes] Account for empty assets when calculating theme asset size #4475

Merged
merged 4 commits into from
Sep 19, 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/nervous-sloths-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': patch
---

Fix a bug when building empty theme assets
6 changes: 3 additions & 3 deletions packages/cli-kit/src/public/node/themes/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface RemoteThemeResponse {
interface RemoteAssetResponse {
key: string
checksum: string
attachment: string
attachment: string | undefined
// value is an empty string ('') when the file is empty
value: string
}

Expand Down Expand Up @@ -52,8 +53,7 @@ export function buildThemeAsset(asset?: RemoteAssetResponse): ThemeAsset | undef

const {key, checksum, attachment, value} = asset
// Note: for attachments, this is the size of the base64 string, not the real length of the file
const stats = {size: (value || attachment).length, mtime: Date.now()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought they'd be empty string at this point. You can also just do:

  const stats = {size: (value || attachment || '').length, mtime: Date.now()}

Copy link
Contributor

@frandiox frandiox Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the types suggest these are already strings... I guess we are passing undefined as any directly from what we get from the cloud, thus bypassing TS checks?

In that case, perhaps we should implement the fix in the caller of this function to ensure it sends strings.
In any case, making it more robust here doesn't hurt 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, possibly making value and attachment nullable in the RemoteAssetResponse would represent a bit better their meaning.


const stats = {size: (value || attachment || '').length, mtime: Date.now()}
return {key, checksum, attachment, value, stats}
}

Expand Down