Skip to content

Commit 34fc676

Browse files
authored
Merge pull request #1702 from Shopify/vs/fix_engine_loading_rails_72
Fix engine loading for Rails 7.2
2 parents 7b8a37d + 700f431 commit 34fc676

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/tapioca/loaders/loader.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def load_rails_application(environment_load: false, eager_load: false, app_root:
8080
def load_rails_engines
8181
return if engines.empty?
8282

83+
normalize_eager_load_paths_configuration!
84+
8385
with_rails_application do
8486
run_initializers
8587

@@ -110,7 +112,7 @@ def load_engines_in_zeitwerk_mode
110112
autoloader = Zeitwerk::Loader.new
111113

112114
engines.each do |engine|
113-
engine.config.eager_load_paths.each do |path|
115+
engine.config.all_eager_load_paths.each do |path|
114116
# Zeitwerk only accepts existing directories in `push_dir`.
115117
next unless File.directory?(path)
116118
# We should not add directories that are already managed by a Zeitwerk loader.
@@ -131,7 +133,7 @@ def load_engines_in_classic_mode
131133
# We can't use `Rails::Engine#eager_load!` directly because it will raise as soon as it encounters
132134
# an error, which is not what we want. We want to try to load as much as we can.
133135
engines.each do |engine|
134-
engine.config.eager_load_paths.each do |load_path|
136+
engine.config.all_eager_load_paths.each do |load_path|
135137
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
136138
require_dependency file
137139
end
@@ -179,6 +181,19 @@ def engines
179181
.reject { |engine| gem_in_app_dir?(project_path, engine.config.root.to_path) }
180182
end
181183

184+
# Rails 7.2 renamed `eager_load_paths` to `all_eager_load_paths`, which maintains the same original functionality.
185+
# The `eager_load_paths` method still exists, but doesn't return all paths anymore and causes Tapioca to miss some
186+
# engine paths. The following commit is the change:
187+
# https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
188+
#
189+
# Here we make sure that the new `all_eager_load_paths` is always defined for every Rails version below 7.2, so
190+
# that we can use it everywhere
191+
def normalize_eager_load_paths_configuration!
192+
return if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2
193+
194+
engines.each { |e| e.config.all_eager_load_paths = e.config.eager_load_paths }
195+
end
196+
182197
sig { params(path: String).void }
183198
def safe_require(path)
184199
require path

lib/tapioca/static/symbol_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def engine_symbols(gem)
2727

2828
return Set.new unless gem_engine
2929

30-
paths = gem_engine.config.eager_load_paths.flat_map do |load_path|
30+
paths = gem_engine.config.all_eager_load_paths.flat_map do |load_path|
3131
Pathname.glob("#{load_path}/**/*.rb")
3232
end
3333

0 commit comments

Comments
 (0)