1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

depend on Zeitwerk 2

This commit is contained in:
Xavier Noria 2019-04-07 12:30:34 +02:00
parent c9e4c848ee
commit 57c7cbb162
6 changed files with 28 additions and 7 deletions

View file

@ -71,7 +71,7 @@ PATH
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
zeitwerk (~> 1.4, >= 1.4.3) zeitwerk (~> 2.0)
rails (6.0.0.beta3) rails (6.0.0.beta3)
actioncable (= 6.0.0.beta3) actioncable (= 6.0.0.beta3)
actionmailbox (= 6.0.0.beta3) actionmailbox (= 6.0.0.beta3)
@ -526,7 +526,7 @@ GEM
websocket-extensions (0.1.3) websocket-extensions (0.1.3)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
zeitwerk (1.4.3) zeitwerk (2.0.0)
PLATFORMS PLATFORMS
java java

View file

@ -1,3 +1,9 @@
* Depends on Zeitwerk 2, which stores less metadata if reloading is disabled
and hence uses less memory when `config.cache_classes` is `true`, a standard
setup in production.
*Xavier Noria*
* In `:zeitwerk` mode, eager load directories in engines and applications only * In `:zeitwerk` mode, eager load directories in engines and applications only
if present in their respective `config.eager_load_paths`. if present in their respective `config.eager_load_paths`.

View file

@ -34,5 +34,5 @@ Gem::Specification.new do |s|
s.add_dependency "tzinfo", "~> 1.1" s.add_dependency "tzinfo", "~> 1.1"
s.add_dependency "minitest", "~> 5.1" s.add_dependency "minitest", "~> 5.1"
s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2" s.add_dependency "concurrent-ruby", "~> 1.0", ">= 1.0.2"
s.add_dependency "zeitwerk", "~> 1.4", ">= 1.4.3" s.add_dependency "zeitwerk", "~> 2.0"
end end

View file

@ -51,15 +51,15 @@ module ActiveSupport
end end
class << self class << self
def take_over def take_over(enable_reloading:)
setup_autoloaders setup_autoloaders(enable_reloading)
freeze_paths freeze_paths
decorate_dependencies decorate_dependencies
end end
private private
def setup_autoloaders def setup_autoloaders(enable_reloading)
Dependencies.autoload_paths.each do |autoload_path| Dependencies.autoload_paths.each do |autoload_path|
# Zeitwerk only accepts existing directories in `push_dir` to # Zeitwerk only accepts existing directories in `push_dir` to
# prevent misconfigurations. # prevent misconfigurations.
@ -72,6 +72,7 @@ module ActiveSupport
autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path) autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
end end
Rails.autoloaders.main.enable_reloading if enable_reloading
Rails.autoloaders.each(&:setup) Rails.autoloaders.each(&:setup)
end end

View file

@ -24,7 +24,7 @@ module Rails
initializer :let_zeitwerk_take_over do initializer :let_zeitwerk_take_over do
if config.autoloader == :zeitwerk if config.autoloader == :zeitwerk
require "active_support/dependencies/zeitwerk_integration" require "active_support/dependencies/zeitwerk_integration"
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
end end
end end

View file

@ -131,6 +131,20 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase
assert $zeitwerk_integration_test_post assert $zeitwerk_integration_test_post
end end
test "reloading is enabled if config.cache_classes is false" do
boot
assert Rails.autoloaders.main.reloading_enabled?
assert_not Rails.autoloaders.once.reloading_enabled?
end
test "reloading is disabled if config.cache_classes is true" do
boot("production")
assert_not Rails.autoloaders.main.reloading_enabled?
assert_not Rails.autoloaders.once.reloading_enabled?
end
test "eager loading loads code in engines" do test "eager loading loads code in engines" do
$test_blog_engine_eager_loaded = false $test_blog_engine_eager_loaded = false