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

Conversation

jamesmengo
Copy link
Contributor

WHY are these changes introduced?

Fixes https://github.com/Shopify/develop-advanced-edits/issues/339
Fixes #4470

WHAT is this pull request doing?

  • Add a fallback to calculate size when files are empty

How to test your changes?

  • Add an empty file to your theme via admin
  • Run shopify theme pull -t <THEME>

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@jamesmengo jamesmengo self-assigned this Sep 18, 2024

This comment has been minimized.

@jamesmengo jamesmengo added the #gsd:40767 Fortify local development experience for Liquid themes label Sep 18, 2024
Copy link
Contributor

github-actions bot commented Sep 18, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
73% (+0% 🔼)
8389/11491
🟡 Branches
69.55% (+0.01% 🔼)
4091/5882
🟡 Functions 71.75% 2179/3037
🟡 Lines
73.35% (+0% 🔼)
7938/10822
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / context.ts
91.67% (-0.03% 🔻)
87.28% 88.57%
92.62% (-0.03% 🔻)
🟡
... / factories.ts
57.89%
40% (-2.86% 🔻)
80% 68.75%

Test suite run success

1889 tests passing in 857 suites.

Report generated by 🧪jest coverage report action from 3756ce8

@@ -52,7 +52,9 @@ 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.

Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, @jamesmengo! Great stuff :)

@@ -52,7 +52,9 @@ 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.

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

Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/themes/factories.d.ts
@@ -10,7 +10,7 @@ interface RemoteThemeResponse {
 interface RemoteAssetResponse {
     key: string;
     checksum: string;
-    attachment: string;
+    attachment: string | undefined;
     value: string;
 }
 export interface RemoteBulkUploadResponse {

@jamesmengo jamesmengo added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit d71bca9 Sep 19, 2024
@jamesmengo jamesmengo deleted the jm/fixpull branch September 19, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#gsd:40767 Fortify local development experience for Liquid themes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Can't pull theme anymore
3 participants