diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 2 | ||||
-rw-r--r-- | railties/lib/rails/app_updater.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 21 |
4 files changed, 25 insertions, 3 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index cf780940d1..83a57a8c6a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -4,6 +4,8 @@ Skip `config/spring.rb` when spring isn't loaded. + Skip yarn's contents when yarn integration isn't used. + *Tsukuru Tanimichi* * Make the master.key file read-only for the owner upon generation on diff --git a/railties/lib/rails/app_updater.rb b/railties/lib/rails/app_updater.rb index e37839bf11..a243968a39 100644 --- a/railties/lib/rails/app_updater.rb +++ b/railties/lib/rails/app_updater.rb @@ -21,6 +21,7 @@ module Rails private def generator_options options = { api: !!Rails.application.config.api_only, update: true } + options[:skip_yarn] = !File.exist?(Rails.root.join("bin", "yarn")) options[:skip_active_record] = !defined?(ActiveRecord::Railtie) options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie) options[:skip_action_mailer] = !defined?(ActionMailer::Railtie) diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 0d2766c1ca..34067240d7 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -95,11 +95,9 @@ module Rails end def bin_when_updating - bin_yarn_exist = File.exist?("bin/yarn") - bin - if options[:api] && !bin_yarn_exist + if options[:skip_yarn] remove_file "bin/yarn" end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f73747208b..3cb7d66bbb 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -296,6 +296,27 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_app_update_does_not_generate_yarn_contents_when_bin_yarn_is_not_used + app_root = File.join(destination_root, "myapp") + run_generator [app_root, "--skip-yarn"] + + stub_rails_application(app_root) do + generator = Rails::Generators::AppGenerator.new ["rails"], { update: true, skip_yarn: true }, { destination_root: app_root, shell: @shell } + generator.send(:app_const) + quietly { generator.send(:update_bin_files) } + + assert_no_file "#{app_root}/bin/yarn" + + assert_file "#{app_root}/bin/setup" do |content| + assert_no_match(/system\('bin\/yarn'\)/, content) + end + + assert_file "#{app_root}/bin/update" do |content| + assert_no_match(/system\('bin\/yarn'\)/, content) + end + end + end + def test_app_update_does_not_generate_assets_initializer_when_skip_sprockets_is_given app_root = File.join(destination_root, "myapp") run_generator [app_root, "--skip-sprockets"] |