Skip to content

Commit

Permalink
Support sourcemap files in digested paths
Browse files Browse the repository at this point in the history
The regular expression for generating digested paths in propshaft is updated to accommodate sourcemap files too.  This will ensure the digested sourcemaps end `-sha.ext.map` instead of `ext-sha.map`. Services like Datadog that allow sourcemap uploads look specifically for files ending with `.js.map`, so this change allows compatibility. A corresponding test has been added in asset_test.rb, verifying that sourcemap files are correctly digesting their paths.
  • Loading branch information
tagCincy committed Dec 12, 2023
1 parent 0237135 commit 8542c1f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/propshaft/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def digested_path
if already_digested?
logical_path
else
logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
logical_path.sub(/\.(\w+(\.map)?)$/) { |ext| "-#{digest}#{ext}" }
end
end

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/propshaft/asset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Propshaft::AssetTest < ActiveSupport::TestCase

assert_equal "file-not.digested-e206c34fe404c8e2f25d60dd8303f61c02b8d381.css",
find_asset("file-not.digested.css").digested_path.to_s

assert_equal "file-is-a-sourcemap-da39a3ee5e6b4b0d3255bfef95601890afd80709.js.map",
find_asset("file-is-a-sourcemap.js.map").digested_path.to_s
end

test "value object equality" do
Expand Down

0 comments on commit 8542c1f

Please sign in to comment.