Skip to content

Commit

Permalink
Avoid loop with static assets when users pass the `--theme-editor-syn…
Browse files Browse the repository at this point in the history
…c` flag
  • Loading branch information
karreiro committed Jul 4, 2024
1 parent 0b90f1b commit 13c246e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-spoons-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Avoid loop with static assets when users pass the `--theme-editor-sync` flag
13 changes: 7 additions & 6 deletions packages/cli-kit/assets/cli-ruby/lib/shopify_cli/theme/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ def json?
path.extname == ".json"
end

def static_json?
json? && relative_path.start_with?("assets/")
end

def template?
relative_path.start_with?("templates/")
end

def checksum
content = read

if mime_type.json? && !settings_schema?
if mime_type.json? && !settings_schema? && !static_json?
# Normalize JSON to match backend
begin
content = normalize_json(content)
Expand Down Expand Up @@ -118,11 +122,8 @@ def settings_schema?
end

def normalize_json(content)
normalized = JSON.generate(JSON.parse(content))

# Backend escapes forward slashes
normalized.gsub!(/\//, "\\/")
normalized
# Backend escapes slashes
JSON.generate(JSON.parse(content), escape_slash: true)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ def test_value_when_it_is_not_a_hash
end
end

def test_checksum_for_static_json_assets
normalized = <<~EOS.rstrip
{
"private": true,
"type": "module",
"version": "0.0.0"
}
EOS

file = fixture_file("assets/package.json")
file.stubs(read: normalized)

assert_equal(Digest::MD5.hexdigest(normalized), file.checksum)
end

private

def fixture_file(file_path)
Expand Down

0 comments on commit 13c246e

Please sign in to comment.