Skip to content

Commit

Permalink
Update bin/yarn template
Browse files Browse the repository at this point in the history
Prevent script from looping onto itself
  • Loading branch information
vaporyhumo committed Nov 27, 2020
1 parent f755468 commit ca81d23
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion railties/lib/rails/generators/rails/app/templates/bin/yarn.tt
@@ -1,6 +1,14 @@
require 'pathname'

APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
exec "yarn", *ARGV
executable_path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |path|
normalized_path = File.expand_path(path)

normalized_path != __dir__ && File.executable?(Pathname.new(normalized_path).join('yarn'))
end

exec File.expand_path(Pathname.new(executable_path).join('yarn')), *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
Expand Down

0 comments on commit ca81d23

Please sign in to comment.