未验证 提交 2e37fb65 编写于 作者: B bogdanvlviv

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.
上级 dc676159
......@@ -21,7 +21,7 @@ def app_generator
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)
......
......@@ -31,9 +31,6 @@ def self.add_shared_options_for(name)
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"
......
......@@ -95,7 +95,7 @@ def bin
def bin_when_updating
bin
if options[:skip_yarn]
if options[:skip_javascript]
remove_file "bin/yarn"
end
end
......@@ -274,7 +274,7 @@ def initialize(*args)
# 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 @@ def create_root_files
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 @@ def delete_new_framework_defaults
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
......
......@@ -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? -%>
......
......@@ -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? -%>
......
......@@ -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 -%>
......
......@@ -88,7 +88,7 @@ def 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)
......
......@@ -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 -%>
......
......@@ -300,10 +300,10 @@ def test_app_update_does_not_remove_rack_cors_if_already_present
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) }
......
......@@ -336,13 +336,14 @@ def test_generator_if_skip_sprockets_is_given
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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册