Skip to content

Commit

Permalink
Merge pull request #40785 from Stellenticket/yarn_command_with_spaces
Browse files Browse the repository at this point in the history
Allow spaces in path to Yarn binstub and only run on precompile if needed
  • Loading branch information
rafaelfranca committed Dec 17, 2020
2 parents 4b22899 + 87e9ae0 commit 002e802
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions railties/lib/rails/tasks/yarn.rake
Expand Up @@ -10,17 +10,21 @@ namespace :yarn do
end

yarn_flags =
if `#{Rails.root}/bin/yarn --version`.start_with?("1")
if `"#{Rails.root}/bin/yarn" --version`.start_with?("1")
"--no-progress --frozen-lockfile"
else
"--immutable"
end

system({ "NODE_ENV" => node_env }, "#{Rails.root}/bin/yarn install #{yarn_flags}")
system({ "NODE_ENV" => node_env }, "\"#{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")
if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn"))
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end

0 comments on commit 002e802

Please sign in to comment.