Permalink
Browse files

Support "nodejs" binary name

  • Loading branch information...
1 parent 8955c7c commit c00ee391d2051ea675c0c8e8e796502d453b40e4 @josh josh committed Feb 7, 2011
Showing with 16 additions and 12 deletions.
  1. +15 −11 lib/execjs/external_runtime.rb
  2. +1 −1 lib/execjs/runtimes.rb
@@ -8,6 +8,7 @@ def initialize(options)
@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 @@ def exec(source)
end
def available?
- command = @command.split(/\s+/).first
- binary = `which #{command}`.strip
- if $? == 0
- if @test_args
- output = `#{binary} #{@test_args} 2>&1`
- output.match(@test_match)
- else
- true
- end
- end
+ @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`
+ binary if output.match(@test_match)
+ else
+ binary
+ end
+ end
+ end
+
def compile(source)
runner_source.sub('#{source}', source)
end
@@ -54,7 +58,7 @@ def compile_to_tempfile(source)
end
def exec_runtime(filename)
- output = `#{@command} #{filename} 2>&1`
+ output = `#{@binary} #{filename} 2>&1`
if $?.success?
output
else
View
@@ -28,7 +28,7 @@ def self.runner_path(path)
:runner_path => runner_path("basic.js")
define_runtime :Node,
- :command => "node",
+ :command => ["nodejs", "node"],
:runner_path => runner_path("node.js")
define_runtime :JSC,

0 comments on commit c00ee39

Please sign in to comment.