Skip to content

Commit

Permalink
Merge pull request #670 from zinsbaustein/fix-coffee-processor-caching
Browse files Browse the repository at this point in the history
Fix cache key for coffee script processor
  • Loading branch information
rafaelfranca committed Jun 23, 2022
2 parents 796fb82 + 7111745 commit 881a819
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
- Allow assets already fingerprinted to be served through `Sprockets::Server`
- Do not fingerprint files that already contain a valid digest in their name
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
- Fix cache key for coffee script processor to be dependent on the filename [#670](https://github.com/rails/sprockets/pull/670)

## 4.0.2

Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/coffee_script_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.cache_key
def self.call(input)
data = input[:data]

js, map = input[:cache].fetch([self.cache_key, data]) do
js, map = input[:cache].fetch([self.cache_key, data, input[:filename]]) do
result = Autoload::CoffeeScript.compile(
data,
sourceMap: "v3",
Expand Down
20 changes: 20 additions & 0 deletions test/test_coffee_script_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ def test_compile_coffee_script_template_to_js
assert_equal ["squared.source.coffee"], result[:map]["sources"]
end

def test_changing_map_sources_for_files_with_same_content
input = {
load_path: File.expand_path("../fixtures", __FILE__),
filename: File.expand_path("../fixtures/squared.coffee", __FILE__),
content_type: 'application/javascript',
environment: @env,
data: "square = (n) -> n * n",
name: 'squared',
cache: Sprockets::Cache.new,
metadata: { mapping: [] }
}
result = Sprockets::CoffeeScriptProcessor.call(input)
assert_equal ["squared.source.coffee"], result[:map]["sources"]

input[:filename] = File.expand_path("../fixtures/peterpan.coffee", __FILE__)

result = Sprockets::CoffeeScriptProcessor.call(input)
assert_equal ["peterpan.source.coffee"], result[:map]["sources"]
end

def test_cache_key
assert Sprockets::CoffeeScriptProcessor.cache_key
end
Expand Down

0 comments on commit 881a819

Please sign in to comment.