Sha256: ad73765bbae981419dc0a9f3eaafd9b9345186eee0eb7c258d39511fc819f5db
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
require 'tempfile' require 'open3' class Condenser class NodeProcessor def node_modules_path File.expand_path('../node_modules', __FILE__) end def self.node_modules_path File.expand_path('../node_modules', __FILE__) end def self.setup(environment) end def exec_runtime(script) Tempfile.open(['script', 'js']) do |scriptfile| scriptfile.write(script) scriptfile.flush stdout, stderr, status = Open3.capture3(binary, scriptfile.path) if status.success? puts stderr if !stderr.strip.empty? JSON.parse(stdout) else raise exec_runtime_error(stdout + stderr) end end end def binary(cmd='node') if File.executable? cmd cmd else path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p| full_path = File.join(p, cmd) File.executable?(full_path) && File.file?(full_path) } if path.nil? raise Condenser::CommandNotFoundError, "Could not find executable #{cmd}" end File.expand_path(cmd, path) end end def exec_syntax_error(output, source_file) error = Condenser::SyntaxError.new(output) lines = output.split("\n") lineno = lines[0][/\((\d+):\d+\)$/, 1] if lines[0] lineno ||= 1 error.set_backtrace(["#{source_file}:#{lineno}"] + caller) error end def exec_runtime_error(output) error = RuntimeError.new(output) lines = output.split("\n") lineno = lines[0][/:(\d+)$/, 1] if lines[0] lineno ||= 1 error.set_backtrace(["(node):#{lineno}"] + caller) error end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
condenser-0.3 | lib/condenser/processors/node_processor.rb |