From 5cce03a1614a9477ea5c079b336be80206ee013f Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 16 Sep 2023 18:56:31 +0200 Subject: [PATCH] Handle Bun priting loaded env variables on STDERR Fix: https://github.com/rails/execjs/issues/130 --- lib/execjs/external_runtime.rb | 4 ++-- test/test_execjs.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 798d809..a0325f4 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -194,7 +194,7 @@ def shell_escape(*args) require 'shellwords' def exec_runtime(filename) - command = "#{Shellwords.join(binary.split(' ') << filename)} 2>&1" + command = "#{Shellwords.join(binary.split(' ') << filename)}" io = IO.popen(command, **@popen_options) output = io.read io.close @@ -207,7 +207,7 @@ def exec_runtime(filename) end else def exec_runtime(filename) - io = IO.popen(binary.split(' ') << filename, **(@popen_options.merge({err: [:child, :out]}))) + io = IO.popen(binary.split(' ') << filename, **@popen_options) output = io.read io.close diff --git a/test/test_execjs.rb b/test/test_execjs.rb index a2b698d..4b0976f 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -56,6 +56,16 @@ def test_call_with_complex_properties assert_equal 2, context.call("(function(bar) { return foo + bar })", 1) end + def test_call_with_env_file + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + # Bun prints on STDOUT when loading .env files + File.write(".env", "FOO=BAR") + assert_equal 2, ExecJS.eval("1 + 1") + end + end + end + def test_call_with_this # Known bug: https://github.com/cowboyd/therubyrhino/issues/39 skip if ExecJS.runtime.is_a?(ExecJS::RubyRhinoRuntime)