未验证 提交 1efbc634 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #32900 from ttanimichi/app-update-skip-yarn

Don't generate yarn's contents in `app:update` task if it's skipped
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
Skip `config/spring.rb` when spring isn't loaded. Skip `config/spring.rb` when spring isn't loaded.
Skip yarn's contents when yarn integration isn't used.
*Tsukuru Tanimichi* *Tsukuru Tanimichi*
* Make the master.key file read-only for the owner upon generation on * Make the master.key file read-only for the owner upon generation on
......
...@@ -21,6 +21,7 @@ def app_generator ...@@ -21,6 +21,7 @@ def app_generator
private private
def generator_options def generator_options
options = { api: !!Rails.application.config.api_only, update: true } 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_record] = !defined?(ActiveRecord::Railtie)
options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie) options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie)
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie) options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
......
...@@ -95,11 +95,9 @@ def bin ...@@ -95,11 +95,9 @@ def bin
end end
def bin_when_updating def bin_when_updating
bin_yarn_exist = File.exist?("bin/yarn")
bin bin
if options[:api] && !bin_yarn_exist if options[:skip_yarn]
remove_file "bin/yarn" remove_file "bin/yarn"
end end
end end
......
...@@ -296,6 +296,27 @@ def test_app_update_does_not_remove_rack_cors_if_already_present ...@@ -296,6 +296,27 @@ def test_app_update_does_not_remove_rack_cors_if_already_present
end end
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 def test_app_update_does_not_generate_assets_initializer_when_skip_sprockets_is_given
app_root = File.join(destination_root, "myapp") app_root = File.join(destination_root, "myapp")
run_generator [app_root, "--skip-sprockets"] run_generator [app_root, "--skip-sprockets"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册