Skip to content

Commit

Permalink
Merge pull request #131 from rails/bun-env-file
Browse files Browse the repository at this point in the history
Handle Bun priting loaded env variables on STDERR
  • Loading branch information
byroot committed Sep 16, 2023
2 parents 6c1c228 + 5cce03a commit daf5b2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/execjs/external_runtime.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/test_execjs.rb
Expand Up @@ -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)
Expand Down

0 comments on commit daf5b2b

Please sign in to comment.