Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source maps caching key #367

Merged
merged 1 commit into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/sprockets/source_map_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def self.call(input)
asset = env.load(uri)
map = asset.metadata[:map] || []

# TODO: Because of the default piplene hack we have to apply dependencies
# from compiled asset to the source map, otherwise the source map cache
# will never detect the changes from directives
dependencies = Set.new(input[:metadata][:dependencies])
dependencies.merge(asset.metadata[:dependencies])

map.map { |m| m[:source] }.uniq.compact.each do |source|
# TODO: Resolve should expect fingerprints
fingerprint = source[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
Expand All @@ -35,7 +41,7 @@ def self.call(input)

json = env.encode_json_source_map(map, filename: asset.logical_path)

{ data: json, links: links }
{ data: json, links: links, dependencies: dependencies }
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/source-maps/dynamic/application.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#= require dynamic/unstable

document.on 'dom:loaded', ->
console.log("Hi")
21 changes: 21 additions & 0 deletions test/test_source_maps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ def setup
], map.map { |m| m[:source] }.uniq.compact
end

test "rebuilds a source map when related dependency has changed" do
filename = fixture_path('source-maps/dynamic/unstable.js')
sandbox filename do
write(filename, "magic_number = 42", 1421000000)
map_1 = JSON.parse(@env['dynamic/application.js.map'].source)

write(filename, "number_of_the_beast = 666", 1422000000)
map_2 = JSON.parse(@env['dynamic/application.js.map'].source)

assert_equal([
"dynamic/unstable.source-43b85c2116b8c894a292c17a6845aa1c9b1491f7dc6bddf764c384668457d55a.js",
"dynamic/application.source-5cc94f82fada13ee8ef969d4cef2018e52ce42f9e1c8ccb6f8333cdc0dd5d3b5.coffee"
], map_1["sources"])

assert_equal([
"dynamic/unstable.source-2ae6f42425799bc9f718842df81be58c5f011dc93a00ca4da17be8877bdb02b3.js",
"dynamic/application.source-5cc94f82fada13ee8ef969d4cef2018e52ce42f9e1c8ccb6f8333cdc0dd5d3b5.coffee"
], map_2["sources"])
end
end

test "compile coffeescript source map" do
assert asset = @env.find_asset("coffee/main.js")
assert_equal fixture_path('source-maps/coffee/main.coffee'), asset.filename
Expand Down