1
0
Fork 0
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:
Joshua Peek 2011-02-07 08:44:02 -06:00
parent 8955c7cae6
commit c00ee391d2
2 changed files with 16 additions and 12 deletions

View file

@ -8,6 +8,7 @@ module ExecJS
@runner_path = options[:runner_path] @runner_path = options[:runner_path]
@test_args = options[:test_args] @test_args = options[:test_args]
@test_match = options[:test_match] @test_match = options[:test_match]
@binary = locate_binary
end end
def eval(source) def eval(source)
@ -23,19 +24,22 @@ module ExecJS
end end
def available? def available?
command = @command.split(/\s+/).first @binary ? true : false
binary = `which #{command}`.strip end
if $? == 0
protected
def locate_binary
@command = @command.join(" ") if @command.is_a?(Array)
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`
output.match(@test_match) binary if output.match(@test_match)
else else
true binary
end end
end end
end end
protected
def compile(source) def compile(source)
runner_source.sub('#{source}', source) runner_source.sub('#{source}', source)
end end
@ -54,7 +58,7 @@ module ExecJS
end end
def exec_runtime(filename) def exec_runtime(filename)
output = `#{@command} #{filename} 2>&1` output = `#{@binary} #{filename} 2>&1`
if $?.success? if $?.success?
output output
else else

View file

@ -28,7 +28,7 @@ module ExecJS
:runner_path => runner_path("basic.js") :runner_path => runner_path("basic.js")
define_runtime :Node, define_runtime :Node,
:command => "node", :command => ["nodejs", "node"],
:runner_path => runner_path("node.js") :runner_path => runner_path("node.js")
define_runtime :JSC, define_runtime :JSC,