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]
@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

View file

@ -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,