Skip to content

Commit ed772e8

Browse files
committed
When resolving sourcemap URL, ignore leading directory
These may be outputted by esbuild when using its `--public-path` option
1 parent 85e8ff6 commit ed772e8

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

lib/propshaft/compiler/source_mapping_urls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "propshaft/compiler"
44

55
class Propshaft::Compiler::SourceMappingUrls < Propshaft::Compiler
6-
SOURCE_MAPPING_PATTERN = %r{^(//|/\*)# sourceMappingURL=(.+\.map)}
6+
SOURCE_MAPPING_PATTERN = %r{^(//|/\*)# sourceMappingURL=(?:.*\/)?(.*\.map)}
77

88
def compile(logical_path, input)
99
input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset_path($2, logical_path), $1) }

test/fixtures/assets/mapped/prefixed-source.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/assets/mapped/prefixed-source.js.map

Whitespace-only changes.

test/propshaft/compiler/source_mapping_urls_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
2525
compile_asset(find_asset("nested/another-source.js", fixture_path: "mapped"))
2626
end
2727

28+
test "resolves prefix on source map filename" do
29+
assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{40}\.map},
30+
compile_asset(find_asset("prefixed-source.js", fixture_path: "mapped"))
31+
end
32+
2833
test "missing source map" do
2934
assert_no_match %r{sourceMappingURL},
3035
compile_asset(find_asset("sourceless.js", fixture_path: "mapped"))

0 commit comments

Comments
 (0)