Skip to content

Commit 7e9102b

Browse files
Move Spring machinery back to bin files
Follow-up to rails#39746. This shifts the responsibility of loading Spring from `config/boot.rb` back to the relevant bin files. Fixes rails#40518. Closes rails#40521. (cherry picked from commit acc837e)
1 parent 87f3f12 commit 7e9102b

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<% if spring_install? -%>
2+
load File.expand_path("spring", __dir__)
3+
<% end -%>
14
APP_PATH = File.expand_path('../config/application', __dir__)
25
require_relative "../config/boot"
36
require "rails/commands"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<% if spring_install? -%>
2+
load File.expand_path("spring", __dir__)
3+
<% end -%>
14
require_relative "../config/boot"
25
require "rake"
36
Rake.application.run
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Load Spring without loading other gems in the Gemfile, for speed.
2-
require "bundler"
3-
Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
4-
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
5-
gem "spring", spring.version
6-
require "spring/binstub"
1+
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
2+
# Load Spring without loading other gems in the Gemfile, for speed.
3+
require "bundler"
4+
Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
5+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
6+
gem "spring", spring.version
7+
require "spring/binstub"
8+
end
79
end

railties/lib/rails/generators/rails/app/templates/config/boot.rb.tt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2-
<% if spring_install? -%>
3-
4-
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
5-
load File.expand_path("../bin/spring", __dir__)
6-
end
7-
<% end -%>
82

93
require "bundler/setup" # Set up gems listed in the Gemfile.
104
<% if depend_on_bootsnap? -%>

railties/test/generators/app_generator_test.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ def test_spring
862862

863863
assert_gem "spring"
864864
assert_file "bin/spring", %r{^\s*require "spring/binstub"}
865-
assert_file "config/boot.rb", %r{^\s*load .+\bbin/spring"}
865+
assert_file "bin/rails", %r{^\s*load .+"spring"}
866+
assert_file "bin/rake", %r{^\s*load .+"spring"}
866867
assert_file("config/environments/test.rb") do |contents|
867868
assert_match("config.cache_classes = false", contents)
868869
assert_match("config.action_view.cache_template_loading = true", contents)
@@ -893,7 +894,10 @@ def test_skip_spring
893894
assert_file("config/environments/test.rb") do |contents|
894895
assert_match("config.cache_classes = true", contents)
895896
end
896-
assert_file "config/boot.rb" do |contents|
897+
assert_file "bin/rails" do |contents|
898+
assert_no_match %r{spring}, contents
899+
end
900+
assert_file "bin/rake" do |contents|
897901
assert_no_match %r{spring}, contents
898902
end
899903
end

railties/test/isolation/abstract_unit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def self.sh(cmd)
510510
FileUtils.rm_rf(app_template_path)
511511
FileUtils.mkdir_p(app_template_path)
512512

513-
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install --quiet"
513+
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-spring --skip-listen --no-rc --skip-webpack-install --quiet"
514514
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
515515
f.puts 'require "rails/all"'
516516
end

0 commit comments

Comments
 (0)