Skip to content

Commit

Permalink
Merge #171
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 15, 2024
2 parents d75d9d8 + b00039b commit ee55138
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
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-e206c34f.css",
find_asset("file-not.digested.css").digested_path.to_s

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

test "value object equality" do
Expand Down
16 changes: 8 additions & 8 deletions test/propshaft/compiler/source_mapping_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
end

test "matching source map" do
assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/assets/source-[a-z0-9]{8}\.js.map},
compile_asset(find_asset("source.js", fixture_path: "mapped"))
assert_match %r{/\*# sourceMappingURL=/assets/source.css-[a-z0-9]{8}\.map},
assert_match %r{/\*# sourceMappingURL=/assets/source-[a-z0-9]{8}\.css.map},
compile_asset(find_asset("source.css", fixture_path: "mapped"))
end

test "matching nested source map" do
assert_match %r{//# sourceMappingURL=/assets/nested/another-source.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/assets/nested/another-source-[a-z0-9]{8}\.js.map},
compile_asset(find_asset("nested/another-source.js", fixture_path: "mapped"))
end

Expand All @@ -38,9 +38,9 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
end

test "sourceMappingURL not at the beginning of the line, but at end of file, is processed" do
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-not-at-start.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-not-at-start-[a-z0-9]{8}\.js.map},
compile_asset(find_asset("sourceMappingURL-not-at-start.js", fixture_path: "mapped"))
assert_match %r{/\*# sourceMappingURL=/assets/sourceMappingURL-not-at-start.css-[a-z0-9]{8}\.map \*/},
assert_match %r{/\*# sourceMappingURL=/assets/sourceMappingURL-not-at-start-[a-z0-9]{8}\.css.map \*/},
compile_asset(find_asset("sourceMappingURL-not-at-start.css", fixture_path: "mapped"))
end

Expand All @@ -54,9 +54,9 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
end

test "sourceMapURL is already prefixed with url_prefix" do
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-already-prefixed.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/assets/sourceMappingURL-already-prefixed-[a-z0-9]{8}\.js\.map},
compile_asset(find_asset("sourceMappingURL-already-prefixed.js", fixture_path: "mapped"))
assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested-[a-z0-9]{8}\.js\.map},
compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped"))
end

Expand All @@ -68,7 +68,7 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
test "relative url root" do
@options.relative_url_root = "/url-root"

assert_match %r{//# sourceMappingURL=/url-root/assets/source.js-[a-z0-9]{8}\.map},
assert_match %r{//# sourceMappingURL=/url-root/assets/source-[a-z0-9]{8}\.js.map},
compile_asset(find_asset("source.js", fixture_path: "mapped"))
end

Expand Down

0 comments on commit ee55138

Please sign in to comment.