Skip to content

Commit e67e5a0

Browse files
author
Jared Jenkins
committed
Use capture3 instead of pop3
More idiomatic way to capture stdout and stderr from a command. If you have a large buffer of compilation errors, you'll block the node command from closing. See: https://bugs.ruby-lang.org/issues/9082
1 parent e56d0e4 commit e67e5a0

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/typescript-node.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ def tsc_version
1313
TypeScript::Src.version
1414
end
1515

16-
1716
def tsc(*args)
1817
cmd = [node, Src.tsc_path.to_s, *args]
19-
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
20-
stdin.close
21-
[wait_thr.value, stdout.read, stderr.read]
22-
end
18+
Open3.capture3(*cmd)
2319
end
2420

2521
# Compile TypeScript source file.
@@ -28,14 +24,14 @@ def tsc(*args)
2824
def compile_file(source_file, *tsc_options)
2925
Dir.mktmpdir do |output_dir|
3026
output_file = File.join(output_dir, "out.js")
31-
exit_status, stdout, stderr = tsc(*tsc_options, '--out', output_file, source_file)
27+
stdout, stderr, exit_status = tsc(*tsc_options, '--out', output_file, source_file)
3228

3329
output_js = File.exists?(output_file) ? File.read(output_file) : nil
3430
CompileResult.new(
35-
output_js,
36-
exit_status,
37-
stdout,
38-
stderr,
31+
output_js,
32+
exit_status,
33+
stdout,
34+
stderr,
3935
)
4036
end
4137
end

0 commit comments

Comments
 (0)