Commit 72737c03 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'initializers-before-zeitwerk' into 'master'

Add initializers that run before Zeitwerk

See merge request gitlab-org/gitlab!26214
parents a5657a3e 8667e4c2
......@@ -292,6 +292,13 @@ module Gitlab
initializer :move_initializers, before: :load_config_initializers, after: :let_zeitwerk_take_over do
end
# We need this for initializers that need to be run before Zeitwerk is loaded
initializer :before_zeitwerk, before: :let_zeitwerk_take_over, after: :prepend_helpers_path do
Dir[Rails.root.join('config/initializers_before_autoloader/*.rb')].sort.each do |initializer|
load_config_initializer(initializer)
end
end
config.after_initialize do
Rails.application.reload_routes!
......
......@@ -97,6 +97,7 @@ Complementary reads:
- [Issue types vs first-class types](issue_types.md)
- [Application limits](application_limits.md)
- [Redis guidelines](redis.md)
- [Rails initializers](rails_initializers.md)
## Performance guides
......
# Rails initializers
By default, Rails loads Zeitwerk after the initializers in `config/initializers` are loaded.
Autoloading before Zeitwerk is loaded is now deprecated but because we use a lot of autoloaded
constants in our initializers, we had to move the loading of Zeitwerk earlier than these
initializers.
A side-effect of this is that in the initializers, `config.autoload_paths` is already frozen.
To run an initializer before Zeitwerk is loaded, you need put them in `config/initializers_before_autoloader`.
Ruby files in this folder are loaded in alphabetical order just like the default Rails initializers.
Some examples where you would need to do this are:
1. Modifying Rails' `config.autoload_paths`
1. Changing configuration that Zeitwerk uses, e.g. inflections
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment