From e34300a921a910c60cd4064038b0817fe0e0ab18 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 11 Aug 2021 15:18:43 +0200 Subject: [PATCH] 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 --- Gemfile.lock | 2 +- .../dummy/config/environments/development.rb | 4 -- .../dummy/config/environments/development.rb | 4 -- .../dummy/config/environments/development.rb | 4 -- guides/source/command_line.md | 1 - guides/source/getting_started.md | 3 +- railties/lib/rails/generators/app_base.rb | 11 ---- .../generators/rails/app/templates/Gemfile.tt | 3 - .../config/environments/development.rb.tt | 4 -- .../rails/plugin/plugin_generator.rb | 1 - .../test/generators/app_generator_test.rb | 56 ------------------- .../test/generators/generators_test_helper.rb | 1 - .../test/generators/plugin_generator_test.rb | 8 --- railties/test/isolation/abstract_unit.rb | 2 +- 14 files changed, 3 insertions(+), 101 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6957f16071..b482f0c26a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/actionmailbox/test/dummy/config/environments/development.rb b/actionmailbox/test/dummy/config/environments/development.rb index 20da35c498..04c55af609 100644 --- a/actionmailbox/test/dummy/config/environments/development.rb +++ b/actionmailbox/test/dummy/config/environments/development.rb @@ -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 diff --git a/actiontext/test/dummy/config/environments/development.rb b/actiontext/test/dummy/config/environments/development.rb index 20da35c498..04c55af609 100644 --- a/actiontext/test/dummy/config/environments/development.rb +++ b/actiontext/test/dummy/config/environments/development.rb @@ -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 diff --git a/activestorage/test/dummy/config/environments/development.rb b/activestorage/test/dummy/config/environments/development.rb index 5b02e2b5bf..b8d68da1e6 100644 --- a/activestorage/test/dummy/config/environments/development.rb +++ b/activestorage/test/dummy/config/environments/development.rb @@ -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 diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 22cc154cd8..a4de92d4da 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -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 | diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index efee840111..d352815c4a 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -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`. diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 688868af31..12737c52fc 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -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 diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt index 9fe05e5fa2..1fd86cc190 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt @@ -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" diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 7500eea492..623070be48 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -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 diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 569889e6b8..bc7665d73f 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -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 diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 7831c3f8f1..5be3ae60a0 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -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) diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 2d56b90a80..7a45836142 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -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, diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 2907fe30f1..3a3a9ece2e 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -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"]) diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 850b685772..af34dfd703 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -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