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:
parent
910ba90fb7
commit
3cf772ef19
3 changed files with 20 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require "rbconfig"
|
||||||
|
|
||||||
module ExecJS
|
module ExecJS
|
||||||
class Error < ::StandardError; end
|
class Error < ::StandardError; end
|
||||||
class RuntimeError < Error; end
|
class RuntimeError < Error; end
|
||||||
|
@ -23,4 +25,8 @@ module ExecJS
|
||||||
def self.root
|
def self.root
|
||||||
@root ||= File.expand_path("../execjs", __FILE__)
|
@root ||= File.expand_path("../execjs", __FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.windows?
|
||||||
|
@windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,8 +29,7 @@ module ExecJS
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def locate_binary
|
def locate_binary
|
||||||
@command = @command.join(" ") if @command.is_a?(Array)
|
if binary = which(@command)
|
||||||
if binary = `which #{@command}`.split("\n").first
|
|
||||||
if @test_args
|
if @test_args
|
||||||
output = `#{binary} #{@test_args} 2>&1`
|
output = `#{binary} #{@test_args} 2>&1`
|
||||||
binary if output.match(@test_match)
|
binary if output.match(@test_match)
|
||||||
|
@ -40,6 +39,17 @@ module ExecJS
|
||||||
end
|
end
|
||||||
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)
|
def compile(source)
|
||||||
runner_source.sub('#{source}', source)
|
runner_source.sub('#{source}', source)
|
||||||
end
|
end
|
||||||
|
|
2
lib/execjs/support/which.bat
Normal file
2
lib/execjs/support/which.bat
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue