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
def generator_options
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_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::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",
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,
desc: "Don't create a Gemfile"

View file

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

View file

@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
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')
<% end -%>
<% unless options.skip_active_record? -%>

View file

@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
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')
<% end -%>
<% 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.
# 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.
Rails.application.config.assets.paths << Rails.root.join('node_modules')
<%- end -%>

View file

@ -88,7 +88,7 @@ task default: :test
PASSTHROUGH_OPTIONS = [
: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)

View file

@ -7,7 +7,7 @@ pkg/
<%= dummy_path %>/db/*.sqlite3-journal
<% end -%>
<%= dummy_path %>/log/*.log
<% unless options[:skip_yarn] -%>
<% unless options[:skip_javascript] -%>
<%= dummy_path %>/node_modules/
<%= dummy_path %>/yarn-error.log
<% 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
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
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)
quietly { generator.send(:update_bin_files) }

View file

@ -336,13 +336,14 @@ module SharedGeneratorTests
end
def test_generator_for_yarn
skip "#34009 disabled JS by default for plugins" if generator_class.name == "Rails::Generators::PluginGenerator"
run_generator
assert_file "#{application_path}/package.json", /dependencies/
assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/
end
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}/bin/yarn"