Skip to content

Commit

Permalink
Handle sourceMappingURL already prefixed with asset path (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
tagCincy committed Jan 22, 2024
1 parent e7cdbcd commit a043d16
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/propshaft/compiler/source_mapping_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def compile(logical_path, input)

private
def asset_path(source_mapping_url, logical_path)
source_mapping_url.gsub!(/^(.+\/)?#{url_prefix}\//, "")

if logical_path.dirname.to_s == "."
source_mapping_url
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var fun; //# sourceMappingURL=/assets/sourceMappingURL-already-prefixed-nested.js.map
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var fun; //# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js.map
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var fun; //# sourceMappingURL=/assets/sourceMappingURL-already-prefixed.js.map
Empty file.
12 changes: 12 additions & 0 deletions test/propshaft/compiler/source_mapping_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
compile_asset(find_asset("sourceMappingURL-outside-comment.css", fixture_path: "mapped"))
end

test "sourceMapURL is already prefixed with url_prefix" do
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-already-prefixed.js-[a-z0-9]{40}\.map},
compile_asset(find_asset("sourceMappingURL-already-prefixed.js", fixture_path: "mapped"))
assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested.js-[a-z0-9]{40}\.map},
compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped"))
end

test "sourceMapURL is already prefixed with an incorrect url_prefix" do
refute_match %r{//# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js-[a-z0-9]{40}\.map},
compile_asset(find_asset("sourceMappingURL-already-prefixed-invalid.js", fixture_path: "mapped"))
end

test "relative url root" do
@options.relative_url_root = "/url-root"

Expand Down

0 comments on commit a043d16

Please sign in to comment.