From ca81d23c2ca21d90ecae513fbcf2077f79eec796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Andr=C3=A9s=20Contreras=20Vilina?= Date: Fri, 27 Nov 2020 11:51:15 -0300 Subject: [PATCH] Update bin/yarn template Prevent script from looping onto itself --- .../rails/generators/rails/app/templates/bin/yarn.tt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/rails/app/templates/bin/yarn.tt b/railties/lib/rails/generators/rails/app/templates/bin/yarn.tt index 915aac34da..2c5013bde6 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/yarn.tt +++ b/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"