fix: no more need to hijack process.stdout on Win32 (#25765)

This commit is contained in:
Cheng Zhao 2020-10-06 02:10:38 +09:00 committed by GitHub
parent 9717dff4fa
commit 57dc170e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 9 additions and 63 deletions

View file

@ -1,9 +1,6 @@
import { Buffer } from 'buffer';
import { EventEmitter } from 'events';
import * as fs from 'fs';
import { Socket } from 'net';
import * as path from 'path';
import * as util from 'util';
const Module = require('module');
@ -19,28 +16,6 @@ require('@electron/internal/common/init');
process._linkedBinding('electron_browser_event_emitter').setEventEmitterPrototype(EventEmitter.prototype);
if (process.platform === 'win32') {
// Redirect node's console to use our own implementations, since node can not
// handle console output when running as GUI program.
const consoleLog = (...args: any[]) => {
// @ts-ignore this typing is incorrect; 'format' is an optional parameter
// See https://nodejs.org/api/util.html#util_util_format_format_args
return process.log(util.format(...args) + '\n');
};
const streamWrite: Socket['write'] = function (chunk: Buffer | string, encoding?: any, callback?: Function) {
if (Buffer.isBuffer(chunk)) {
chunk = chunk.toString(encoding);
}
process.log(chunk);
if (callback) {
callback();
}
return true;
};
console.log = console.error = console.warn = consoleLog;
process.stdout.write = process.stderr.write = streamWrite;
}
// Don't quit on fatal error.
process.on('uncaughtException', function (error) {
// Do nothing if the user has a custom uncaught exception handler.