Sha256: b174583a78c8e60db395e54848cb6d0224e3ad5548b7e318c71210b4cee1b6f0

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

# 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 `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
        "--no-progress --frozen-lockfile"
      else
        "--immutable"
      end

    system({ "NODE_ENV" => node_env }, "#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}")
  rescue Errno::ENOENT
    $stderr.puts "bin/yarn was not found."
    $stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
    exit 1
  end
end

# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn"))
  Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
railties-6.1.7.10 lib/rails/tasks/yarn.rake
railties-6.1.7.9 lib/rails/tasks/yarn.rake
railties-6.1.7.8 lib/rails/tasks/yarn.rake
railties-6.1.7.7 lib/rails/tasks/yarn.rake
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/railties-6.1.6.1/lib/rails/tasks/yarn.rake
railties-6.1.7.6 lib/rails/tasks/yarn.rake
railties-6.1.7.5 lib/rails/tasks/yarn.rake
railties-6.1.7.4 lib/rails/tasks/yarn.rake
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/railties-6.1.6.1/lib/rails/tasks/yarn.rake
railties-6.1.7.3 lib/rails/tasks/yarn.rake
railties-6.1.7.2 lib/rails/tasks/yarn.rake
railties-6.1.7.1 lib/rails/tasks/yarn.rake
railties-6.1.7 lib/rails/tasks/yarn.rake
railties-6.1.6.1 lib/rails/tasks/yarn.rake
railties-6.1.6 lib/rails/tasks/yarn.rake
railties-6.1.5.1 lib/rails/tasks/yarn.rake
railties-6.1.5 lib/rails/tasks/yarn.rake
railties-6.1.4.7 lib/rails/tasks/yarn.rake
railties-6.1.4.6 lib/rails/tasks/yarn.rake
railties-6.1.4.5 lib/rails/tasks/yarn.rake