Skip to content

Fix up how command is executed. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions lib/closure/compiler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'open3'
require 'stringio'
require 'tempfile'

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

begin
redirect_stderr = "2>&1" if !Gem.win_platform?
result = `#{command} #{redirect_stderr}`
rescue Exception
raise Error, "compression failed: #{result}"
unless status == 0
raise Error, stderr
end

unless $?.exitstatus.zero?
raise Error, result
end
# Let them see the warnings.
$stderr.write stderr

yield(StringIO.new(result)) if block_given?
result
yield(StringIO.new(stdout)) if block_given?
stdout
end
alias_method :compile_file, :compile_files

Expand All @@ -86,8 +83,8 @@ def serialize_options(options)
end.flatten
end

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

end
Expand Down