improve CLI interoperability (#5762)

This commit is contained in:
Alex Lam S.L
2022-12-11 07:25:06 +02:00
committed by GitHub
parent 78242ff21d
commit 797184f587
2 changed files with 13 additions and 3 deletions

View File

@@ -301,9 +301,19 @@ if (specified["in-situ"]) {
process.stdin.setEncoding("utf8"); process.stdin.setEncoding("utf8");
process.stdin.once("data", function() { process.stdin.once("data", function() {
clearTimeout(timerId); clearTimeout(timerId);
}).on("data", function(chunk) { }).on("data", process.stdin.isTTY ? function(chunk) {
// emulate console input termination via Ctrl+D / Ctrl+Z
var match = /[\x04\x1a]\r?\n?$/.exec(chunk);
if (match) {
chunks.push(chunk.slice(0, -match[0].length));
process.stdin.pause();
process.stdin.emit("end");
} else {
chunks.push(chunk);
}
} : function(chunk) {
chunks.push(chunk); chunks.push(chunk);
}).on("end", function() { }).once("end", function() {
files = { STDIN: chunks.join("") }; files = { STDIN: chunks.join("") };
run(); run();
}); });

View File

@@ -6,7 +6,7 @@ try {
} catch (e) { } catch (e) {
// ensure output buffers are flushed before process termination // ensure output buffers are flushed before process termination
var exit = process.exit; var exit = process.exit;
process.exit = function() { if ("bufferSize" in process.stdout) process.exit = function() {
var args = [].slice.call(arguments); var args = [].slice.call(arguments);
process.once("uncaughtException", function() { process.once("uncaughtException", function() {
(function callback() { (function callback() {