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

Commit e8ae7cb

Browse files
committed
Fix a corner case where modules could appear in the build config's paths
1 parent 1201570 commit e8ae7cb

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/tasks/requirejs-rails_tasks.rake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ OS X Homebrew users can use 'brew install node'.
9898
original_cache = requirejs.env.cache
9999
requirejs.env.cache = nil
100100

101-
if ::Sprockets::VERSION.split(".", -1)[0].to_i >= 3
102-
js_ext = requirejs.env.mime_types["application/javascript"][:extensions].first
103-
else
104-
js_ext = requirejs.env.extension_for_mime_type("application/javascript")
105-
end
106-
107101
requirejs.env.each_logical_path(requirejs.config.logical_path_patterns) do |logical_path|
108102
m = ::Requirejs::Rails::Config::BOWER_PATH_PATTERN.match(logical_path)
109103

@@ -116,7 +110,7 @@ OS X Homebrew users can use 'brew install node'.
116110
asset.write_to(file)
117111
end
118112
else
119-
bower_logical_path = Pathname.new(logical_path).dirname.sub_ext(js_ext).to_s
113+
bower_logical_path = Pathname.new(logical_path).dirname.sub_ext(".js").to_s
120114
asset = requirejs.env.find_asset(bower_logical_path)
121115

122116
if asset
@@ -151,8 +145,17 @@ OS X Homebrew users can use 'brew install node'.
151145
# Copy each built asset, identified by a named module in the
152146
# build config, to its Sprockets digestified name.
153147
task digestify_and_compress: ["requirejs:setup"] do
154-
requirejs.config.build_config['modules'].each do |m|
155-
asset_name = "#{requirejs.config.module_name_for(m)}.js"
148+
requirejs.config.build_config["modules"].each do |m|
149+
module_name = requirejs.config.module_name_for(m)
150+
paths = requirejs.config.build_config["paths"] || {}
151+
152+
# Is there a `paths` entry for the module?
153+
if !paths[module_name]
154+
asset_name = Pathname.new(module_name).sub_ext(".js")
155+
else
156+
asset_name = Pathname.new(paths[module_name]).sub_ext(".js")
157+
end
158+
156159
asset = requirejs.env.find_asset(asset_name)
157160

158161
built_asset_path = requirejs.config.build_dir.join(asset_name)

0 commit comments

Comments
 (0)