Skip to content

Commit 6bfb582

Browse files
Search for yarn.exe in bin/yarn
Since rails#40646, `bin/yarn` manually searches `PATH` for the `yarn` executable. In Windows environments, executables have an `.exe` file extension, so we must search for `yarn.exe` as well. Fixes rails#40942.
1 parent 7378ffb commit 6bfb582

File tree

1 file changed

+7
-9
lines changed
  • railties/lib/rails/generators/rails/app/templates/bin

1 file changed

+7
-9
lines changed

railties/lib/rails/generators/rails/app/templates/bin/yarn.tt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
require 'pathname'
2-
31
APP_ROOT = File.expand_path('..', __dir__)
42
Dir.chdir(APP_ROOT) do
5-
executable_path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |path|
6-
normalized_path = File.expand_path(path)
7-
8-
normalized_path != __dir__ && File.executable?(Pathname.new(normalized_path).join('yarn'))
9-
end
3+
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
4+
select { |dir| File.expand_path(dir) != __dir__ }.
5+
product(["yarn", "yarn.exe"]).
6+
map { |dir, file| File.expand_path(file, dir) }.
7+
find { |file| File.executable?(file) }
108

11-
if executable_path
12-
exec File.expand_path(Pathname.new(executable_path).join('yarn')), *ARGV
9+
if yarn
10+
exec yarn, *ARGV
1311
else
1412
$stderr.puts "Yarn executable was not detected in the system."
1513
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"

0 commit comments

Comments
 (0)