未验证 提交 c6bdfd13 编写于 作者: D David Heinemeier Hansson 提交者: GitHub

Use explicit spring boot loader (#39225)

上级 58bed972
* Use explicit `config/boot_with_spring.rb` boot file for bin/rails and bin/rake, which allows us to restrict Spring loading
to only test and development, and everywhere to be able to skip spring by passing UNSPRUNG=1 as an env variable.
*DHH*
* The `classic` autoloader starts its deprecation cycle.
New Rails projects are strongly discouraged from using `classic`, and we recommend that existing projects running on `classic` switch to `zeitwerk` mode when upgrading. Please check the [_Upgrading Ruby on Rails_](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html) guide for tips.
......
......@@ -429,9 +429,9 @@ def generate_bundler_binstub
end
end
def generate_spring_binstubs
def generate_spring_binstub
if bundle_install? && spring_install?
bundle_command("exec spring binstub --all")
bundle_command("exec spring binstub")
end
end
......
......@@ -347,6 +347,11 @@ def create_boot_file
template "config/boot.rb"
end
def create_boot_with_spring_file
return if options[:skip_spring]
template "config/boot_with_spring.rb"
end
def create_active_record_files
return if options[:skip_active_record]
build(:database_yml)
......@@ -489,7 +494,7 @@ def finish_template
end
public_task :apply_rails_template, :run_bundle
public_task :generate_bundler_binstub, :generate_spring_binstubs
public_task :generate_bundler_binstub, :generate_spring_binstub
public_task :run_webpack
def run_after_bundle_callbacks
......
APP_PATH = File.expand_path('../config/application', __dir__)
<% if options.skip_spring? -%>
require_relative "../config/boot"
<% else -%>
require_relative "../config/boot_with_spring"
<% end -%>
require "rails/commands"
<% if options.skip_spring? -%>
require_relative "../config/boot"
<% else -%>
require_relative "../config/boot_with_spring"
<% end -%>
require "rake"
Rake.application.run
if ENV["UNSPRUNG"].nil? && (ENV["RAILS_ENV"].nil? || ENV["RAILS_ENV"] == "development" || ENV["RAILS_ENV"] == "test")
begin
load File.expand_path("../../bin/spring", __FILE__)
rescue LoadError => e
raise unless e.message.include?("spring")
end
end
require_relative "boot"
......@@ -1066,7 +1066,7 @@ def test_after_bundle_callback
template
end
sequence = ["git init", "install", "binstubs bundler", "exec spring binstub --all", "webpacker:install", "echo ran after_bundle"]
sequence = ["git init", "install", "binstubs bundler", "exec spring binstub", "webpacker:install", "echo ran after_bundle"]
@sequence_step ||= 0
ensure_bundler_first = -> command, options = nil do
assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册