From 2c4681844598d0fb22cc628975e9560628c00703 Mon Sep 17 00:00:00 2001 From: Curtis J Schofield Date: Mon, 18 Dec 2017 14:44:39 -0800 Subject: [PATCH 1/3] modifications to avoid polluting output with stdout from node --- lib/execjs.ex | 2 +- priv/node_runner.js.eex | 41 +++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/execjs.ex b/lib/execjs.ex index 252f2d4..9242230 100644 --- a/lib/execjs.ex +++ b/lib/execjs.ex @@ -35,7 +35,7 @@ defmodule Execjs do try do port = Port.open({ :spawn_executable, command }, - [:stream, :in, :binary, :eof, :hide, { :args, [tmpfile] }]) + [:stream, :in, :binary,:nouse_stdio, :eof, :hide, { :args, [tmpfile] }]) extract_result(loop(port)) after diff --git a/priv/node_runner.js.eex b/priv/node_runner.js.eex index 2b46b58..919a508 100644 --- a/priv/node_runner.js.eex +++ b/priv/node_runner.js.eex @@ -1,19 +1,24 @@ -(function(program, runner) { runner(program); })(function() { - return <%= source %>; -}, function(program) { - var result; - try { - result = program(); - try { - if (result === undefined) { - process.stdout.write('["ok"]'); - } else { - process.stdout.write(JSON.stringify(['ok', result])); - } - } catch (err) { - process.stdout.write('["err"]'); +const fs = require('fs'); +(function(program, runner) { + runner(program); +})( + function() { + return <%= source %>; } - } catch (err) { - process.stdout.write(JSON.stringify(['err', '' + err])); - } -}); + , async function(program) { + let result; + try { + result = await program(); + try { + if (result === undefined) { + fs.writeSync(4,'["ok"]'); + } else { + fs.writeSync(4,JSON.stringify(['ok', result])); + } + } catch (err) { + fs.writeSync(4, '["err"]'); + } + } catch (err) { + fs.writeSync(4,JSON.stringify(['err', '' + err])); + } + }); From 95d9d129d8db2640266b51c8655566efc706a783 Mon Sep 17 00:00:00 2001 From: Curtis J Schofield Date: Mon, 18 Dec 2017 14:49:28 -0800 Subject: [PATCH 2/3] update readme with doc about runtime --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index db7abcb..70997d8 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,23 @@ best runtime available on the system. Use the application environment (application key: `:execjs`, key: `:runtime`) to set the runtime `Execjs` uses. Alternatively, the `EXECJS_RUNTIME` environment variable can also be used to set the runtime. +### Additional Runtimes + +It is possible to define a custom runtime to specify an exact path +to your runtime command: + +```elixir +defmodule ServeElmWeb.Runtime do + import Execjs.Runtime + + defruntime Node8, + command: "/Users/o_o/.nvm/versions/node/v8.9.3/bin/node", + runner: "node_runner.js.eex" +end + +``` + + ## Usage From 22af10e3bd5188a08003ab984f720696d91941d3 Mon Sep 17 00:00:00 2001 From: Curtis J Schofield <178963+robotarmy@users.noreply.github.com> Date: Mon, 18 Dec 2017 14:50:31 -0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70997d8..d42b8ff 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ It is possible to define a custom runtime to specify an exact path to your runtime command: ```elixir -defmodule ServeElmWeb.Runtime do +defmodule MyModule.Runtime do import Execjs.Runtime defruntime Node8,