diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 4c6f5582b0..7cbe3ae99e 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -405,11 +405,19 @@ module Rails end def run_webpack - if webpack_install? - rails_command "webpacker:install" - if options[:webpack] && options[:webpack] != "webpack" - rails_command "webpacker:install:#{options[:webpack]}" - end + return unless webpack_install? + + unless bundle_install? + say <<~EXPLAIN + Skipping `rails webpacker:install` because `bundle install` was skipped. + To complete setup, you must run `bundle install` followed by `rails webpacker:install`. + EXPLAIN + return + end + + rails_command "webpacker:install" + if options[:webpack] && options[:webpack] != "webpack" + rails_command "webpacker:install:#{options[:webpack]}" end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f560b8ea1c..1317e76b51 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -107,12 +107,22 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_skip_bundle - generator([destination_root], skip_bundle: true, skip_webpack_install: true) - run_generator_instance + generator([destination_root], skip_bundle: true) + output = run_generator_instance assert_empty @bundle_commands # skip_bundle is only about running bundle install so ensure the Gemfile is still generated assert_file "Gemfile" + assert_webpack_installation_skipped(output) + end + + def test_skip_gemfile + generator([destination_root], skip_gemfile: true) + output = run_generator_instance + + assert_empty @bundle_commands + assert_no_file "Gemfile" + assert_webpack_installation_skipped(output) end def test_assets @@ -1264,4 +1274,22 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/^\s*# config\.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content) end end + + def assert_webpack_installation_skipped(output) + assert_match(/^Skipping `rails webpacker:install`/, output) + + %w( + .browserslistrc + babel.config.js + bin/webpack + bin/webpack-dev-server + config/webpack + config/webpack/development.js + config/webpack/environment.js + config/webpack/production.js + config/webpack/test.js + config/webpacker.yml + postcss.config.js + ).each { |f| assert_no_file(f) } + end end