mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Support "nodejs" binary name
This commit is contained in:
parent
8955c7cae6
commit
c00ee391d2
2 changed files with 16 additions and 12 deletions
|
@ -8,6 +8,7 @@ module ExecJS
|
|||
@runner_path = options[:runner_path]
|
||||
@test_args = options[:test_args]
|
||||
@test_match = options[:test_match]
|
||||
@binary = locate_binary
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
|
@ -23,19 +24,22 @@ module ExecJS
|
|||
end
|
||||
|
||||
def available?
|
||||
command = @command.split(/\s+/).first
|
||||
binary = `which #{command}`.strip
|
||||
if $? == 0
|
||||
@binary ? true : false
|
||||
end
|
||||
|
||||
protected
|
||||
def locate_binary
|
||||
@command = @command.join(" ") if @command.is_a?(Array)
|
||||
if binary = `which #{@command}`.split("\n").first
|
||||
if @test_args
|
||||
output = `#{binary} #{@test_args} 2>&1`
|
||||
output.match(@test_match)
|
||||
binary if output.match(@test_match)
|
||||
else
|
||||
true
|
||||
binary
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def compile(source)
|
||||
runner_source.sub('#{source}', source)
|
||||
end
|
||||
|
@ -54,7 +58,7 @@ module ExecJS
|
|||
end
|
||||
|
||||
def exec_runtime(filename)
|
||||
output = `#{@command} #{filename} 2>&1`
|
||||
output = `#{@binary} #{filename} 2>&1`
|
||||
if $?.success?
|
||||
output
|
||||
else
|
||||
|
|
|
@ -28,7 +28,7 @@ module ExecJS
|
|||
:runner_path => runner_path("basic.js")
|
||||
|
||||
define_runtime :Node,
|
||||
:command => "node",
|
||||
:command => ["nodejs", "node"],
|
||||
:runner_path => runner_path("node.js")
|
||||
|
||||
define_runtime :JSC,
|
||||
|
|
Loading…
Reference in a new issue