Skip to content

Commit c9b32dc

Browse files
tagCincydhh
authored andcommitted
Handle sourceMappingURL already prefixed with asset path (#170)
1 parent c598290 commit c9b32dc

8 files changed

+17
-0
lines changed

lib/propshaft/compiler/source_mapping_urls.rb

Lines changed: 2 additions & 0 deletions
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
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=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js.map

test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ 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+
63+
test "sourceMapURL is already prefixed with an incorrect url_prefix" do
64+
refute_match %r{//# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js-[a-z0-9]{40}\.map},
65+
compile_asset(find_asset("sourceMappingURL-already-prefixed-invalid.js", fixture_path: "mapped"))
66+
end
67+
5668
test "relative url root" do
5769
@options.relative_url_root = "/url-root"
5870

0 commit comments

Comments
 (0)