diff --git a/.changeset/silly-spoons-marry.md b/.changeset/silly-spoons-marry.md new file mode 100644 index 0000000000..c64609ab37 --- /dev/null +++ b/.changeset/silly-spoons-marry.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme': patch +--- + +Avoid loop with static assets when users pass the `--theme-editor-sync` flag diff --git a/packages/cli-kit/assets/cli-ruby/lib/shopify_cli/theme/file.rb b/packages/cli-kit/assets/cli-ruby/lib/shopify_cli/theme/file.rb index 5b6d7b33e6..b9e0980aa2 100644 --- a/packages/cli-kit/assets/cli-ruby/lib/shopify_cli/theme/file.rb +++ b/packages/cli-kit/assets/cli-ruby/lib/shopify_cli/theme/file.rb @@ -70,6 +70,10 @@ def json? path.extname == ".json" end + def static_json? + json? && relative_path.start_with?("assets/") + end + def template? relative_path.start_with?("templates/") end @@ -77,7 +81,7 @@ def template? 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) @@ -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 diff --git a/packages/cli-kit/assets/cli-ruby/test/shopify-cli/theme/file_test.rb b/packages/cli-kit/assets/cli-ruby/test/shopify-cli/theme/file_test.rb index b66689aedb..807ba839b3 100644 --- a/packages/cli-kit/assets/cli-ruby/test/shopify-cli/theme/file_test.rb +++ b/packages/cli-kit/assets/cli-ruby/test/shopify-cli/theme/file_test.rb @@ -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)