Skip to content

Commit

Permalink
Merge pull request #12 from lowjoel/master
Browse files Browse the repository at this point in the history
Support checking the PATHEXT variable on Windows.
  • Loading branch information
rafaelfranca committed Aug 14, 2015
2 parents 33e51ad + 7df6bf6 commit 1a92790
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/execjs/external_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,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
Expand Down

0 comments on commit 1a92790

Please sign in to comment.