lib/esbuild/service.rb in esbuild-0.2.0 vs lib/esbuild/service.rb in esbuild-0.2.1
- old
+ new
@@ -19,12 +19,13 @@
@plugin_callbacks = Concurrent::Map.new
@watch_callbacks = Concurrent::Map.new
@serve_callbacks = Concurrent::Map.new
@buffer = String.new(encoding: Encoding::BINARY)
- child_read, child_stdout = IO.pipe
- child_stdin, @child_write = IO.pipe
+ child_read, child_stdout = create_pipes
+ child_stdin, @child_write = create_pipes
+
bin = binary_path
pid = spawn(bin, "--service=#{ESBUILD_VERSION}", "--ping", out: child_stdout, err: :err, in: child_stdin)
child_stdin.close
child_stdout.close
@@ -34,11 +35,10 @@
def build_or_serve(options, serve_options = nil)
key = @build_key
@build_key += 1
opts = Flags.flags_for_build_options(options)
on_rebuild = opts[:watch]&.fetch(:on_rebuild, nil)
-
request = {
"command" => "build",
"key" => key,
"entries" => opts[:entries],
"flags" => opts[:flags],
@@ -249,9 +249,16 @@
@response_callbacks.clear
end
def binary_path
ENV["ESBUILD_BINARY_PATH"] || File.expand_path("../../bin/esbuild", __dir__)
+ end
+
+ def create_pipes
+ r, w = IO.pipe(Encoding::BINARY, Encoding::BINARY, binmode: true)
+ r.set_encoding(Encoding::BINARY)
+ w.set_encoding(Encoding::BINARY)
+ [r, w]
end
end
class BuildFailureError < StandardError
attr_reader :errors