Skip to content

Commit

Permalink
When resolving sourcemap URL, ignore leading directory
Browse files Browse the repository at this point in the history
These  may be outputted by esbuild when using its `--public-path` option
  • Loading branch information
gjtorikian committed Aug 27, 2023
1 parent 85e8ff6 commit ed772e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/propshaft/compiler/source_mapping_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/assets/mapped/prefixed-source.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
5 changes: 5 additions & 0 deletions test/propshaft/compiler/source_mapping_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit ed772e8

Please sign in to comment.