diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index 0a32d902..b01b044a 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -3,7 +3,7 @@ require "propshaft/compiler" class Propshaft::Compiler::SourceMappingUrls < Propshaft::Compiler - SOURCE_MAPPING_PATTERN = %r{(//|/\*)# sourceMappingURL=(.+\.map)(\s*?\*\/)?\s*?\Z} + SOURCE_MAPPING_PATTERN = %r{(//|/\*)# sourceMappingURL=(?:.*\/)?(.*\.map)(\s*?\*\/)?\s*?\Z} def compile(logical_path, input) input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset_path($2, logical_path), $1, $3) } diff --git a/test/fixtures/assets/mapped/prefixed-source.js b/test/fixtures/assets/mapped/prefixed-source.js new file mode 100644 index 00000000..b445f4ca --- /dev/null +++ b/test/fixtures/assets/mapped/prefixed-source.js @@ -0,0 +1,2 @@ +var fun; +//# sourceMappingURL=assets/source.js.map diff --git a/test/fixtures/assets/mapped/prefixed-source.js.map b/test/fixtures/assets/mapped/prefixed-source.js.map new file mode 100644 index 00000000..e69de29b diff --git a/test/propshaft/compiler/source_mapping_urls_test.rb b/test/propshaft/compiler/source_mapping_urls_test.rb index 1b10e4bf..0128eb7e 100644 --- a/test/propshaft/compiler/source_mapping_urls_test.rb +++ b/test/propshaft/compiler/source_mapping_urls_test.rb @@ -25,6 +25,11 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase compile_asset(find_asset("nested/another-source.js", fixture_path: "mapped")) end + test "resolves prefix on source map filename" do + assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{40}\.map}, + compile_asset(find_asset("prefixed-source.js", fixture_path: "mapped")) + end + test "missing source map" do assert_no_match %r{sourceMappingURL}, compile_asset(find_asset("sourceless.js", fixture_path: "mapped"))