Stop trying to configure listen by default on compatible platforms (#42985)

* Stop trying to configure listen by default on compatible platforms

Modern computers with SSDs don't see much/any benefit from having an evented file update watcher. Remove complexity by taking this spinning-drive concession out.

* Actually need listen for testing the opt-in

* Test no longer relevant
This commit is contained in:
David Heinemeier Hansson 2021-08-11 15:18:43 +02:00 committed by GitHub
parent ea2c5ec0b9
commit e34300a921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 3 additions and 101 deletions

View File

@ -294,7 +294,7 @@ GEM
mustache
nokogiri
libxml-ruby (3.2.1)
listen (3.5.1)
listen (3.6.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.10.0)

View File

@ -63,8 +63,4 @@ Rails.application.configure do
# Annotate rendered view with file names
# config.action_view.annotate_rendered_view_with_filenames = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

View File

@ -63,8 +63,4 @@ Rails.application.configure do
# Annotate rendered view with file names
# config.action_view.annotate_rendered_view_with_filenames = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

View File

@ -48,8 +48,4 @@ Rails.application.configure do
# Annotate rendered view with file names
# config.action_view.annotate_rendered_view_with_filenames = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

View File

@ -105,7 +105,6 @@ If you wish to skip some files or components from being generated, you can appen
| `--skip-action-cable` | Skip Action Cable files |
| `--skip-sprockets` | Skip Sprockets files |
| `--skip-spring` | Don't install Spring application preloader |
| `--skip-listen` | Don't generate configuration that depends on the listen gem |
| `--skip-javascript` | Skip JavaScript files |
| `--skip-turbolinks` | Skip turbolinks gem |
| `--skip-test` | Skip test files |

View File

@ -184,8 +184,7 @@ install the gem dependencies that are already mentioned in `Gemfile` using
NOTE: If you're using Windows Subsystem for Linux then there are currently some
limitations on file system notifications that mean you should disable the `spring`
and `listen` gems which you can do by running `rails new blog --skip-spring --skip-listen`
instead.
gem which you can do by running `rails new blog --skip-spring` instead.
TIP: You can see all of the command line options that the Rails application
generator accepts by running `rails new --help`.

View File

@ -70,9 +70,6 @@ module Rails
class_option :skip_spring, type: :boolean, default: false,
desc: "Don't install Spring application preloader"
class_option :skip_listen, type: :boolean, default: false,
desc: "Don't generate configuration that depends on the listen gem"
class_option :skip_javascript, type: :boolean, aliases: "-J", default: name == "plugin",
desc: "Skip JavaScript files"
@ -417,18 +414,10 @@ module Rails
!(options[:skip_system_test] || options[:skip_test] || options[:api])
end
def depend_on_listen?
!options[:skip_listen] && os_supports_listen_out_of_the_box?
end
def depend_on_bootsnap?
!options[:skip_bootsnap] && !options[:dev] && !defined?(JRUBY_VERSION)
end
def os_supports_listen_out_of_the_box?
/darwin|linux/.match?(RbConfig::CONFIG["host_os"])
end
def run_bundle
bundle_command("install", "BUNDLE_IGNORE_MESSAGES" => "1") if bundle_install?
end

View File

@ -55,9 +55,6 @@ group :development do
# Note: Interferes with etag cache testing. Can be configured to work on production: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
# gem "rack-mini-profiler", "~> 2.0"
<%- end -%>
<% if depend_on_listen? -%>
gem "listen", "~> 3.3"
<% end -%>
<% if spring_install? -%>
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "spring"

View File

@ -72,10 +72,6 @@ Rails.application.configure do
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
<%= "# " unless depend_on_listen? %>config.file_watcher = ActiveSupport::EventedFileUpdateChecker
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
end

View File

@ -121,7 +121,6 @@ module Rails
opts[:force] = force
opts[:skip_bundle] = true
opts[:skip_spring] = true
opts[:skip_listen] = true
opts[:skip_git] = true
opts[:skip_turbolinks] = true
opts[:skip_webpack_install] = true

View File

@ -744,46 +744,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def test_inclusion_of_listen_related_configuration_by_default
run_generator
if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_listen_related_configuration
else
assert_no_listen_related_configuration
end
end
def test_inclusion_of_listen_related_configuration_on_other_rubies
ruby_engine = Object.send(:remove_const, :RUBY_ENGINE)
Object.const_set(:RUBY_ENGINE, "MyRuby")
run_generator
if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_listen_related_configuration
else
assert_no_listen_related_configuration
end
ensure
Object.send(:remove_const, :RUBY_ENGINE)
Object.const_set(:RUBY_ENGINE, ruby_engine)
end
def test_non_inclusion_of_listen_related_configuration_if_skip_listen
run_generator [destination_root, "--skip-listen"]
assert_no_listen_related_configuration
end
def test_evented_file_update_checker_config
run_generator
assert_file "config/environments/development.rb" do |content|
if /darwin|linux/.match?(RbConfig::CONFIG["host_os"])
assert_match(/^\s*config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
else
assert_match(/^\s*# config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
end
end
end
def test_template_from_dir_pwd
FileUtils.cd(Rails.root)
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))
@ -1311,22 +1271,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
end
def assert_listen_related_configuration
assert_gem "listen"
assert_file "config/environments/development.rb" do |content|
assert_match(/^\s*config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
end
end
def assert_no_listen_related_configuration
assert_no_gem "listen"
assert_file "config/environments/development.rb" do |content|
assert_match(/^\s*# config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
end
end
def assert_webpack_installation_skipped(output)
assert_match(/^Skipping `rails webpacker:install`/, output)

View File

@ -94,7 +94,6 @@ module GeneratorsTestHelper
{
skip_active_storage: true,
depend_on_bootsnap: false,
depend_on_listen: false,
spring_install: false,
depends_on_system_test: false,
options: ActiveSupport::OrderedOptions.new,

View File

@ -627,14 +627,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase
end
end
def test_dummy_application_skip_listen_by_default
run_generator
assert_file "test/dummy/config/environments/development.rb" do |contents|
assert_match(/^\s*# config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, contents)
end
end
def test_ensure_that_gitignore_can_be_generated_from_a_template_for_dummy_path
FileUtils.cd(Rails.root)
run_generator([destination_root, "--dummy_path", "spec/dummy", "--skip-test"])

View File

@ -511,7 +511,7 @@ Module.new do
FileUtils.rm_rf(app_template_path)
FileUtils.mkdir_p(app_template_path)
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"
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-spring --no-rc --skip-webpack-install --quiet"
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
f.puts 'require "rails/all"'
end