Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 8e1a9d1

Browse files
committed
Refactor @jonhyman's fix a bit
1 parent e7c73b8 commit 8e1a9d1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/tasks/requirejs-rails_tasks.rake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace :requirejs do
3232
end
3333

3434
requirejs = ActiveSupport::OrderedOptions.new
35+
path_extension_pattern = Regexp.new("\\.(\\w+)\\z")
3536

3637
task clean: ["requirejs:setup"] do
3738
FileUtils.remove_entry_secure(requirejs.config.source_dir, true)
@@ -161,9 +162,10 @@ OS X Homebrew users can use 'brew install node'.
161162

162163
built_asset_path = requirejs.config.build_dir.join(asset_name)
163164

165+
# Compute the digest based on the contents of the compiled file, *not* on the contents of the RequireJS module.
164166
file_digest = ::Rails.application.assets.file_digest(built_asset_path)
165167
hex_digest = Sprockets::DigestUtils.pack_hexdigest(file_digest)
166-
digest_name = asset.logical_path.sub(/\.(\w+)$/) { |ext| "-#{hex_digest}#{ext}" }
168+
digest_name = asset.logical_path.gsub(path_extension_pattern) { |ext| "-#{hex_digest}#{ext}" }
167169

168170
digest_asset_path = requirejs.config.target_dir + digest_name
169171

0 commit comments

Comments
 (0)