From dd326636061c37f863044c1bc87b1a112dc1d6ac Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Sat, 2 Sep 2023 18:25:57 -0400 Subject: [PATCH 1/2] Demonstrate test failure w/ source maps generation --- test/fixtures/assets/mapped/prefixed-source.js | 2 ++ test/fixtures/assets/mapped/prefixed-source.js.map | 0 test/propshaft/compiler/source_mapping_urls_test.rb | 5 +++++ 3 files changed, 7 insertions(+) create mode 100644 test/fixtures/assets/mapped/prefixed-source.js create mode 100644 test/fixtures/assets/mapped/prefixed-source.js.map 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 f3dc551e..33daf25a 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")) From 52c06d17527caed703427b35488a21dc5a5b631c Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Sat, 2 Sep 2023 18:27:58 -0400 Subject: [PATCH 2/2] When resolving source maps, ignore leading dirname These may be outputted by esbuild when using its `--public-path` option --- lib/propshaft/compiler/source_mapping_urls.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index de867d81..ebbd227a 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)} + SOURCE_MAPPING_PATTERN = %r{^(//|/\*)# sourceMappingURL=(?:.*\/)?(.*\.map)} def compile(logical_path, input) input.gsub(SOURCE_MAPPING_PATTERN) { source_mapping_url(asset_path($2, logical_path), $1) }