Skip to content

Commit dae5cdd

Browse files
committed
handle sourcemap urls that have already been prefixed with asset path
test cases
1 parent 0237135 commit dae5cdd

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed

lib/propshaft/compiler/source_mapping_urls.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def compile(logical_path, input)
1111

1212
private
1313
def asset_path(source_mapping_url, logical_path)
14+
source_mapping_url.gsub!(/^\/?#{url_prefix}\//, "")
15+
1416
if logical_path.dirname.to_s == "."
1517
source_mapping_url
1618
else
@@ -19,7 +21,7 @@ def asset_path(source_mapping_url, logical_path)
1921
end
2022

2123
def source_mapping_url(resolved_path, comment_start, comment_end)
22-
if asset = assembly.load_path.find(resolved_path)
24+
if (asset = assembly.load_path.find(resolved_path))
2325
"#{comment_start}# sourceMappingURL=#{url_prefix}/#{asset.digested_path}#{comment_end}"
2426
else
2527
Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{resolved_path}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var fun; //# sourceMappingURL=/assets/sourceMappingURL-already-prefixed-nested.js.map

test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested.js.map

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var fun; //# sourceMappingURL=/assets/sourceMappingURL-already-prefixed.js.map

test/fixtures/assets/mapped/sourceMappingURL-already-prefixed.js.map

Whitespace-only changes.

test/propshaft/compiler/source_mapping_urls_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
5353
compile_asset(find_asset("sourceMappingURL-outside-comment.css", fixture_path: "mapped"))
5454
end
5555

56+
test "sourceMapURL is already prefixed with url_prefix" do
57+
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-already-prefixed.js-[a-z0-9]{40}\.map},
58+
compile_asset(find_asset("sourceMappingURL-already-prefixed.js", fixture_path: "mapped"))
59+
assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested.js-[a-z0-9]{40}\.map},
60+
compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped"))
61+
end
62+
5663
test "relative url root" do
5764
@options.relative_url_root = "/url-root"
5865

0 commit comments

Comments
 (0)