1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/tasks/yarn.rake
zarqman 3e2f74c186
Call yarn directly (#43641)
* Remove the assets:precompile dependency on yarn:install

Since yarn isn't required for Rails 7, assets:precompile should
not depend on it by default. Instead, tasks for webpacker,
jsbundling-rails, cssbundling-rails, etc should depend on
yarn:install on their own.

* In yarn:install, call `yarn` instead of `bin/yarn`

Change to calling `yarn` directly (via PATH) as `bin/yarn` is no longer
a part of Rails 7.
2021-11-15 09:53:12 +01:00

29 lines
805 B
Ruby

# frozen_string_literal: true
namespace :yarn do
desc "Install all JavaScript dependencies as specified via Yarn"
task :install do
# Install only production deps when for not usual envs.
valid_node_envs = %w[test development production]
node_env = ENV.fetch("NODE_ENV") do
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
end
yarn_flags =
if `yarn --version`.start_with?("1")
"--no-progress --frozen-lockfile"
else
"--immutable"
end
system(
{ "NODE_ENV" => node_env },
"yarn install #{yarn_flags}",
exception: true
)
rescue Errno::ENOENT
$stderr.puts "yarn install failed to execute."
$stderr.puts "Ensure yarn is installed and `yarn --version` runs without errors."
exit 1
end
end