From 7df6bf6ae1dcc9453227d224985014d9de60f31e Mon Sep 17 00:00:00 2001 From: Joel Low Date: Sat, 14 Mar 2015 08:55:27 +0800 Subject: [PATCH] Support checking the PATHEXT variable on Windows. This allows scripts to be detected as a runtime, for circumstances where the actual binary is not in PATH, but a forwarding script is. --- lib/execjs/external_runtime.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 811dd69..633d406 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -113,20 +113,25 @@ def binary @binary ||= which(@command) end - def locate_executable(cmd) - if ExecJS.windows? && File.extname(cmd) == "" - cmd << ".exe" - end - - if File.executable? cmd - cmd - else - path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| - full_path = File.join(p, cmd) - File.executable?(full_path) && File.file?(full_path) + def locate_executable(command) + commands = Array(command) + if ExecJS.windows? && File.extname(command) == "" + ENV['PATHEXT'].split(File::PATH_SEPARATOR).each { |p| + commands << (command + p) } - path && File.expand_path(cmd, path) end + + commands.find { |cmd| + if File.executable? cmd + cmd + else + path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| + full_path = File.join(p, cmd) + File.executable?(full_path) && File.file?(full_path) + } + path && File.expand_path(cmd, path) + end + } end protected