Skip to content

Commit

Permalink
improve process.exit() workaround (#2741)
Browse files Browse the repository at this point in the history
- use public API
- fix issue with Node.js 0.10 on WIndows
  • Loading branch information
alexlamsl authored Jan 7, 2018
1 parent 1ee8be8 commit 9809567
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 1 addition & 5 deletions bin/uglifyjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

"use strict";

// workaround for tty output truncation upon process.exit()
[process.stdout, process.stderr].forEach(function(stream){
if (stream._handle && stream._handle.setBlocking)
stream._handle.setBlocking(true);
});
require("../tools/exit");

var fs = require("fs");
var info = require("../package.json");
Expand Down
6 changes: 1 addition & 5 deletions test/jetstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

var site = "http://browserbench.org/JetStream";
if (typeof phantom == "undefined") {
// workaround for tty output truncation upon process.exit()
[process.stdout, process.stderr].forEach(function(stream){
if (stream._handle && stream._handle.setBlocking)
stream._handle.setBlocking(true);
});
require("../tools/exit");
var args = process.argv.slice(2);
var debug = args.indexOf("--debug");
if (debug >= 0) {
Expand Down
6 changes: 1 addition & 5 deletions test/ufuzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
// bin/uglifyjs s.js -c && bin/uglifyjs s.js -c passes=3 && bin/uglifyjs s.js -c passes=3 -m
// cat s.js | node && node s.js && bin/uglifyjs s.js -c | node && bin/uglifyjs s.js -c passes=3 | node && bin/uglifyjs s.js -c passes=3 -m | node

// workaround for tty output truncation upon process.exit()
[process.stdout, process.stderr].forEach(function(stream){
if (stream._handle && stream._handle.setBlocking)
stream._handle.setBlocking(true);
});
require("../tools/exit");

var UglifyJS = require("..");
var randomBytes = require("crypto").randomBytes;
Expand Down
15 changes: 15 additions & 0 deletions tools/exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// workaround for tty output truncation upon process.exit()
var exit = process.exit;
process.exit = function() {
var args = [].slice.call(arguments);
process.once("uncaughtException", function() {
(function callback() {
if (process.stdout.bufferSize || process.stderr.bufferSize) {
setImmediate(callback);
} else {
exit.apply(process, args);
}
})();
});
throw exit;
};

0 comments on commit 9809567

Please sign in to comment.