Skip to content

Commit 797184f

Browse files
authored
improve CLI interoperability (#5762)
1 parent 78242ff commit 797184f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

bin/uglifyjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,19 @@ if (specified["in-situ"]) {
301301
process.stdin.setEncoding("utf8");
302302
process.stdin.once("data", function() {
303303
clearTimeout(timerId);
304-
}).on("data", function(chunk) {
304+
}).on("data", process.stdin.isTTY ? function(chunk) {
305+
// emulate console input termination via Ctrl+D / Ctrl+Z
306+
var match = /[\x04\x1a]\r?\n?$/.exec(chunk);
307+
if (match) {
308+
chunks.push(chunk.slice(0, -match[0].length));
309+
process.stdin.pause();
310+
process.stdin.emit("end");
311+
} else {
312+
chunks.push(chunk);
313+
}
314+
} : function(chunk) {
305315
chunks.push(chunk);
306-
}).on("end", function() {
316+
}).once("end", function() {
307317
files = { STDIN: chunks.join("") };
308318
run();
309319
});

tools/tty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ try {
66
} catch (e) {
77
// ensure output buffers are flushed before process termination
88
var exit = process.exit;
9-
process.exit = function() {
9+
if ("bufferSize" in process.stdout) process.exit = function() {
1010
var args = [].slice.call(arguments);
1111
process.once("uncaughtException", function() {
1212
(function callback() {

0 commit comments

Comments
 (0)