diff --git a/lib/propshaft/asset.rb b/lib/propshaft/asset.rb index 759523f..c9cc6bd 100644 --- a/lib/propshaft/asset.rb +++ b/lib/propshaft/asset.rb @@ -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 diff --git a/test/fixtures/assets/first_path/file-is-a-sourcemap.js.map b/test/fixtures/assets/first_path/file-is-a-sourcemap.js.map new file mode 100644 index 0000000..e69de29 diff --git a/test/propshaft/asset_test.rb b/test/propshaft/asset_test.rb index 6d27ec1..5c0749c 100644 --- a/test/propshaft/asset_test.rb +++ b/test/propshaft/asset_test.rb @@ -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 diff --git a/test/propshaft/compiler/source_mapping_urls_test.rb b/test/propshaft/compiler/source_mapping_urls_test.rb index dc69f27..ca06d20 100644 --- a/test/propshaft/compiler/source_mapping_urls_test.rb +++ b/test/propshaft/compiler/source_mapping_urls_test.rb @@ -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 @@ -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 @@ -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 @@ -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