1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Add which support for Windows

This commit is contained in:
Sam Stephenson 2011-02-07 12:48:15 -06:00
parent 910ba90fb7
commit 3cf772ef19
3 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,5 @@
require "rbconfig"
module ExecJS
class Error < ::StandardError; end
class RuntimeError < Error; end
@ -23,4 +25,8 @@ module ExecJS
def self.root
@root ||= File.expand_path("../execjs", __FILE__)
end
def self.windows?
@windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
end
end

View file

@ -29,8 +29,7 @@ module ExecJS
protected
def locate_binary
@command = @command.join(" ") if @command.is_a?(Array)
if binary = `which #{@command}`.split("\n").first
if binary = which(@command)
if @test_args
output = `#{binary} #{@test_args} 2>&1`
binary if output.match(@test_match)
@ -40,6 +39,17 @@ module ExecJS
end
end
def which(command)
Array(command).find do |name|
result = if ExecJS.windows?
`#{ExecJS.root}/support/which.bat #{name}`
else
`which #{name} 2>&1`
end
result.strip.split("\n").first
end
end
def compile(source)
runner_source.sub('#{source}', source)
end

View file

@ -0,0 +1,2 @@
@rem Taken from http://blogs.msdn.com/b/oldnewthing/archive/2005/01/20/357225.aspx
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" @echo %%~$PATH:i