Skip to content

Commit

Permalink
Adjusted a couple of other spots that were making files relative to t…
Browse files Browse the repository at this point in the history
…he current page instead of the TLD+port
  • Loading branch information
crimson-knight committed Nov 12, 2023
1 parent f34d654 commit 363d14e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions spec/asset_pipeline_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ describe AssetPipeline::FrontLoader do
file_1_hash = Digest::SHA256.new.file("spec/test_js/some_js.js").hexfinal

final_import_map = <<-STRING
<scripttype="importmap">{"imports":{"test":"./some_js-#{file_1_hash}.js"}}</script>
<scripttype="importmap">{"imports":{"test":"/some_js-#{file_1_hash}.js"}}</script>
STRING

file_2_hash = Digest::SHA256.new.file("spec/test_js/sub_folder/second_sub_folder/second_nested_file.js").hexfinal

final_import_map2 = <<-STRING
<scripttype="importmap">{"imports":{"test":"./sub_folder/second_sub_folder/second_nested_file-#{file_2_hash}.js"}}</script>
<scripttype="importmap">{"imports":{"test":"/sub_folder/second_sub_folder/second_nested_file-#{file_2_hash}.js"}}</script>
STRING

# Test both of these, this ensures the overlapping file names are still created correctly.
Expand All @@ -71,7 +71,7 @@ describe AssetPipeline::FrontLoader do
file_hash = Digest::SHA256.new.file("spec/test_js/some_js.js").hexfinal

final_import_map = <<-STRING
<scripttype="importmap">{"imports":{"test":"./some_js-#{file_hash}.js"}}</script>
<scripttype="importmap">{"imports":{"test":"/some_js-#{file_hash}.js"}}</script>
STRING

# Test both of these, this ensures the overlapping file names are still created correctly.
Expand All @@ -95,7 +95,7 @@ describe AssetPipeline::FrontLoader do
digest << file_contents

final_import_map = <<-STRING
<scripttype="importmap"src="./application-#{digest.hexfinal}.json"></script>
<scripttype="importmap"src="/application-#{digest.hexfinal}.json"></script>
STRING

front_loader.render_import_map_as_file.gsub(" ", "").gsub("\n", "").should eq(final_import_map)
Expand Down
4 changes: 2 additions & 2 deletions src/asset_pipeline.cr
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module AssetPipeline
File.write(@js_output_path.join(file_name), file_contents)

<<-STRING
<script type="importmap" src="./#{file_name}"></script>
<script type="importmap" src="/#{file_name}"></script>
#{import_map.preload_module_links}
STRING
end
Expand All @@ -128,7 +128,7 @@ module AssetPipeline
end

first_key = target_import_map.imports[found_index].first_key
target_import_map.imports[found_index][first_key] = cached_file_name.gsub(@js_output_path.to_s, "./")
target_import_map.imports[found_index][first_key] = cached_file_name.gsub(@js_output_path.to_s, "/")
end
end
end
Expand Down

0 comments on commit 363d14e

Please sign in to comment.