lib/tapioca/loaders/loader.rb in tapioca-0.11.10 vs lib/tapioca/loaders/loader.rb in tapioca-0.11.11
- old
+ new
@@ -78,12 +78,10 @@
sig { void }
def load_rails_engines
return if engines.empty?
- normalize_eager_load_paths_configuration!
-
with_rails_application do
run_initializers
if zeitwerk_mode?
load_engines_in_zeitwerk_mode
@@ -110,11 +108,11 @@
# We use a fresh loader to load the engine directories, so that we don't interfere with
# any of the existing loaders.
autoloader = Zeitwerk::Loader.new
engines.each do |engine|
- engine.config.all_eager_load_paths.each do |path|
+ eager_load_paths(engine).each do |path|
# Zeitwerk only accepts existing directories in `push_dir`.
next unless File.directory?(path)
# We should not add directories that are already managed by a Zeitwerk loader.
next if managed_dirs.member?(path)
@@ -131,11 +129,11 @@
# https://github.com/rails/rails/blob/d9e188dbab81b412f73dfb7763318d52f360af49/railties/lib/rails/engine.rb#L489-L495
#
# We can't use `Rails::Engine#eager_load!` directly because it will raise as soon as it encounters
# an error, which is not what we want. We want to try to load as much as we can.
engines.each do |engine|
- engine.config.all_eager_load_paths.each do |load_path|
+ eager_load_paths(engine).each do |load_path|
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file
end
rescue ScriptError, StandardError
nil
@@ -179,23 +177,10 @@
.descendants
.reject(&:abstract_railtie?)
.reject { |engine| gem_in_app_dir?(project_path, engine.config.root.to_path) }
end
- # Rails 7.2 renamed `eager_load_paths` to `all_eager_load_paths`, which maintains the same original functionality.
- # The `eager_load_paths` method still exists, but doesn't return all paths anymore and causes Tapioca to miss some
- # engine paths. The following commit is the change:
- # https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
- #
- # Here we make sure that the new `all_eager_load_paths` is always defined for every Rails version below 7.2, so
- # that we can use it everywhere
- def normalize_eager_load_paths_configuration!
- return if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2
-
- engines.each { |e| e.config.all_eager_load_paths = e.config.eager_load_paths }
- end
-
sig { params(path: String).void }
def safe_require(path)
require path
rescue LoadError
nil
@@ -236,9 +221,20 @@
file = File.absolute_path(file)
return unless File.exist?(file)
require(file)
+ end
+
+ # Rails 7.2 renamed `eager_load_paths` to `all_eager_load_paths`, which maintains the same original functionality.
+ # The `eager_load_paths` method still exists, but doesn't return all paths anymore and causes Tapioca to miss some
+ # engine paths. The following commit is the change:
+ # https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
+ sig { params(engine: T.class_of(Rails::Engine)).returns(T::Array[String]) }
+ def eager_load_paths(engine)
+ config = engine.config
+
+ (config.respond_to?(:all_eager_load_paths) && config.all_eager_load_paths) || config.eager_load_paths
end
end
end
end