Skip to content

Commit e5837bf

Browse files
committed
Fix up how command is executed.
- Stop warnings and notices on stderr from appearing in the output. - Fix shell escaping problems. - Stop mutating the global options object (now somewhat threadsafe).
1 parent 4ae4436 commit e5837bf

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/closure/compiler.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'open3'
12
require 'stringio'
23
require 'tempfile'
34

@@ -55,21 +56,17 @@ def compile(io)
5556
# resulting JavaScript as a string or yields an IO object containing the
5657
# response to a block, for streaming.
5758
def compile_files(files)
58-
@options.merge!(:js => files)
59+
stdout, stderr, status = Open3::capture3 *command(js: files)
5960

60-
begin
61-
redirect_stderr = "2>&1" if !Gem.win_platform?
62-
result = `#{command} #{redirect_stderr}`
63-
rescue Exception
64-
raise Error, "compression failed: #{result}"
61+
unless status == 0
62+
raise Error, stderr
6563
end
6664

67-
unless $?.exitstatus.zero?
68-
raise Error, result
69-
end
65+
# Let them see the warnings.
66+
$stderr.puts stderr unless stderr.empty?
7067

71-
yield(StringIO.new(result)) if block_given?
72-
result
68+
yield(StringIO.new(stdout)) if block_given?
69+
stdout
7370
end
7471
alias_method :compile_file, :compile_files
7572

@@ -86,8 +83,8 @@ def serialize_options(options)
8683
end.flatten
8784
end
8885

89-
def command
90-
[@java, '-jar', "\"#{@jar}\"", serialize_options(@options)].flatten.join(' ')
86+
def command(**options)
87+
%W(#@java -jar #@jar) + serialize_options(@options.merge(options))
9188
end
9289

9390
end

0 commit comments

Comments
 (0)