1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove --skip-yarn in favor of --skip-javascript

Since #33079 Webpacker the default JavaScript compiler for Rails.
Webpacker uses `yarn` so seems like it doesn't make sense for Rails to keep
`--skip-yarn` option.
This commit is contained in:
bogdanvlviv 2018-10-21 23:08:43 +03:00
parent dc67615920
commit 2e37fb655d
No known key found for this signature in database
GPG key ID: E4ACD76A6DB6DFDD
10 changed files with 17 additions and 19 deletions

View file

@ -21,7 +21,7 @@ module Rails
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_javascript] = !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)

View file

@ -31,9 +31,6 @@ module Rails
class_option :database, type: :string, aliases: "-d", default: "sqlite3", class_option :database, type: :string, aliases: "-d", default: "sqlite3",
desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})" desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})"
class_option :skip_yarn, type: :boolean, default: false,
desc: "Don't use Yarn for managing JavaScript dependencies"
class_option :skip_gemfile, type: :boolean, default: false, class_option :skip_gemfile, type: :boolean, default: false,
desc: "Don't create a Gemfile" desc: "Don't create a Gemfile"

View file

@ -95,7 +95,7 @@ module Rails
def bin_when_updating def bin_when_updating
bin bin
if options[:skip_yarn] if options[:skip_javascript]
remove_file "bin/yarn" remove_file "bin/yarn"
end end
end end
@ -274,7 +274,7 @@ module Rails
# Force sprockets and yarn to be skipped when generating API only apps. # Force sprockets and yarn to be skipped when generating API only apps.
# Can't modify options hash as it's frozen by default. # Can't modify options hash as it's frozen by default.
if options[:api] if options[:api]
self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze
end end
end end
@ -289,7 +289,7 @@ module Rails
build(:gitignore) unless options[:skip_git] build(:gitignore) unless options[:skip_git]
build(:gemfile) unless options[:skip_gemfile] build(:gemfile) unless options[:skip_gemfile]
build(:version_control) build(:version_control)
build(:package_json) unless options[:skip_yarn] build(:package_json) unless options[:skip_javascript]
end end
def create_app_files def create_app_files
@ -462,8 +462,8 @@ module Rails
end end
end end
def delete_bin_yarn_if_skip_yarn_option def delete_bin_yarn
remove_file "bin/yarn" if options[:skip_yarn] remove_file "bin/yarn" if options[:skip_javascript]
end end
def finish_template def finish_template

View file

@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do
puts '== Installing dependencies ==' puts '== Installing dependencies =='
system! 'gem install bundler --conservative' system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install') system('bundle check') || system!('bundle install')
<% unless options.skip_yarn? -%> <% unless options.skip_javascript? -%>
# Install JavaScript dependencies if using Yarn # Install JavaScript dependencies
# system('bin/yarn') # system('bin/yarn')
<% end -%> <% end -%>
<% unless options.skip_active_record? -%> <% unless options.skip_active_record? -%>

View file

@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do
puts '== Installing dependencies ==' puts '== Installing dependencies =='
system! 'gem install bundler --conservative' system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install') system('bundle check') || system!('bundle install')
<% unless options.skip_yarn? -%> <% unless options.skip_javascript? -%>
# Install JavaScript dependencies if using Yarn # Install JavaScript dependencies
# system('bin/yarn') # system('bin/yarn')
<% end -%> <% end -%>
<% unless options.skip_active_record? -%> <% unless options.skip_active_record? -%>

View file

@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path. # Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path # Rails.application.config.assets.paths << Emoji.images_path
<%- unless options[:skip_yarn] -%> <%- unless options[:skip_javascript] -%>
# Add Yarn node_modules folder to the asset load path. # Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules') Rails.application.config.assets.paths << Rails.root.join('node_modules')
<%- end -%> <%- end -%>

View file

@ -88,7 +88,7 @@ task default: :test
PASSTHROUGH_OPTIONS = [ PASSTHROUGH_OPTIONS = [
:skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database, :skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database,
:skip_yarn, :api, :quiet, :pretend, :skip :api, :quiet, :pretend, :skip
] ]
def generate_test_dummy(force = false) def generate_test_dummy(force = false)

View file

@ -7,7 +7,7 @@ pkg/
<%= dummy_path %>/db/*.sqlite3-journal <%= dummy_path %>/db/*.sqlite3-journal
<% end -%> <% end -%>
<%= dummy_path %>/log/*.log <%= dummy_path %>/log/*.log
<% unless options[:skip_yarn] -%> <% unless options[:skip_javascript] -%>
<%= dummy_path %>/node_modules/ <%= dummy_path %>/node_modules/
<%= dummy_path %>/yarn-error.log <%= dummy_path %>/yarn-error.log
<% end -%> <% end -%>

View file

@ -300,10 +300,10 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_app_update_does_not_generate_yarn_contents_when_bin_yarn_is_not_used def test_app_update_does_not_generate_yarn_contents_when_bin_yarn_is_not_used
app_root = File.join(destination_root, "myapp") app_root = File.join(destination_root, "myapp")
run_generator [app_root, "--skip-yarn"] run_generator [app_root, "--skip-javascript"]
stub_rails_application(app_root) do stub_rails_application(app_root) do
generator = Rails::Generators::AppGenerator.new ["rails"], { update: true, skip_yarn: true }, { destination_root: app_root, shell: @shell } generator = Rails::Generators::AppGenerator.new ["rails"], { update: true, skip_javascript: true }, { destination_root: app_root, shell: @shell }
generator.send(:app_const) generator.send(:app_const)
quietly { generator.send(:update_bin_files) } quietly { generator.send(:update_bin_files) }

View file

@ -336,13 +336,14 @@ module SharedGeneratorTests
end end
def test_generator_for_yarn def test_generator_for_yarn
skip "#34009 disabled JS by default for plugins" if generator_class.name == "Rails::Generators::PluginGenerator"
run_generator run_generator
assert_file "#{application_path}/package.json", /dependencies/ assert_file "#{application_path}/package.json", /dependencies/
assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/ assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/
end end
def test_generator_for_yarn_skipped def test_generator_for_yarn_skipped
run_generator([destination_root, "--skip-yarn"]) run_generator([destination_root, "--skip-javascript"])
assert_no_file "#{application_path}/package.json" assert_no_file "#{application_path}/package.json"
assert_no_file "#{application_path}/bin/yarn" assert_no_file "#{application_path}/bin/yarn"