From dd54925e992a03233c1103399e96881a396c6de4 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 30 Oct 2023 13:58:30 -0400 Subject: [PATCH 1/2] Fix engine loading for Rails 7.2 Rails 7.2 changed `eager_load_paths` for `all_eager_load_paths` in this https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664 --- lib/tapioca/loaders/loader.rb | 19 +++++++++++++++++-- lib/tapioca/static/symbol_loader.rb | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/tapioca/loaders/loader.rb b/lib/tapioca/loaders/loader.rb index a44dbe224..ff56f07a6 100644 --- a/lib/tapioca/loaders/loader.rb +++ b/lib/tapioca/loaders/loader.rb @@ -80,6 +80,8 @@ def load_rails_application(environment_load: false, eager_load: false, app_root: def load_rails_engines return if engines.empty? + normalize_eager_load_paths_configuration! + with_rails_application do run_initializers @@ -110,7 +112,7 @@ def load_engines_in_zeitwerk_mode autoloader = Zeitwerk::Loader.new engines.each do |engine| - engine.config.eager_load_paths.each do |path| + engine.config.all_eager_load_paths.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. @@ -131,7 +133,7 @@ def load_engines_in_classic_mode # 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.eager_load_paths.each do |load_path| + engine.config.all_eager_load_paths.each do |load_path| Dir.glob("#{load_path}/**/*.rb").sort.each do |file| require_dependency file end @@ -179,6 +181,19 @@ def engines .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 doens'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 diff --git a/lib/tapioca/static/symbol_loader.rb b/lib/tapioca/static/symbol_loader.rb index ea0fa004e..0a872635c 100644 --- a/lib/tapioca/static/symbol_loader.rb +++ b/lib/tapioca/static/symbol_loader.rb @@ -27,7 +27,7 @@ def engine_symbols(gem) return Set.new unless gem_engine - paths = gem_engine.config.eager_load_paths.flat_map do |load_path| + paths = gem_engine.config.all_eager_load_paths.flat_map do |load_path| Pathname.glob("#{load_path}/**/*.rb") end From 700f431c63939d8903d5ff8bba21941dcf4aeb14 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 31 Oct 2023 13:47:44 -0400 Subject: [PATCH 2/2] Fix typo Co-authored-by: Andy Waite <13400+andyw8@users.noreply.github.com> --- lib/tapioca/loaders/loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tapioca/loaders/loader.rb b/lib/tapioca/loaders/loader.rb index ff56f07a6..f495385bc 100644 --- a/lib/tapioca/loaders/loader.rb +++ b/lib/tapioca/loaders/loader.rb @@ -182,7 +182,7 @@ def engines 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 doens't return all paths anymore and causes Tapioca to miss some + # 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 #