Skip to content

Commit

Permalink
improve CLI interoperability (#5762)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 11, 2022
1 parent 78242ff commit 797184f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions bin/uglifyjs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,19 @@ if (specified["in-situ"]) {
process.stdin.setEncoding("utf8");
process.stdin.once("data", function() {
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);
}).on("end", function() {
}).once("end", function() {
files = { STDIN: chunks.join("") };
run();
});
Expand Down
2 changes: 1 addition & 1 deletion tools/tty.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ try {
} catch (e) {
// ensure output buffers are flushed before process termination
var exit = process.exit;
process.exit = function() {
if ("bufferSize" in process.stdout) process.exit = function() {
var args = [].slice.call(arguments);
process.once("uncaughtException", function() {
(function callback() {
Expand Down

0 comments on commit 797184f

Please sign in to comment.