add process wrapper to handle logs

This commit is contained in:
Jonathan Rainville 2018-05-15 15:56:15 -04:00
parent 18e23ae334
commit 36850895cf
2 changed files with 43 additions and 37 deletions

View File

@ -0,0 +1,41 @@
const constants = require('../constants');
// Override process.chdir so that we have a partial-implementation PWD for Windows
const realChdir = process.chdir;
process.chdir = (...args) => {
if (!process.env.PWD) {
process.env.PWD = process.cwd();
}
realChdir(...args);
};
class ProcessWrapper {
constructor(_options) {
this.interceptLogs();
}
interceptLogs() {
const context = {};
context.console = console;
context.console.log = this.log.bind(this, 'log');
context.console.warn = this.log.bind(this, 'warn');
context.console.info = this.log.bind(this, 'info');
context.console.debug = this.log.bind(this, 'debug');
context.console.trace = this.log.bind(this, 'trace');
context.console.dir = this.log.bind(this, 'dir');
}
log(type, ...messages) {
if (messages[0].indexOf('hard-source')) {
return;
}
process.send({result: constants.pipeline.log, message: messages, type});
}
}
process.on('exit', () => {
process.exit(0);
});
module.exports = ProcessWrapper;

View File

@ -4,42 +4,11 @@ const utils = require('../utils/utils');
const fs = require('../core/fs'); const fs = require('../core/fs');
const constants = require('../constants'); const constants = require('../constants');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const ProcessWrapper = require('../core/processWrapper');
// Override process.chdir so that we have a partial-implementation PWD for Windows
const realChdir = process.chdir;
process.chdir = (...args) => {
if (!process.env.PWD) {
process.env.PWD = process.cwd();
}
realChdir(...args);
};
let webpackProcess; let webpackProcess;
class WebpackProcess { class WebpackProcess extends ProcessWrapper {
constructor(_options) {
this.interceptLogs();
}
interceptLogs() {
const context = {};
context.console = console;
context.console.log = this.log.bind(this, 'log');
context.console.warn = this.log.bind(this, 'warn');
context.console.info = this.log.bind(this, 'info');
context.console.debug = this.log.bind(this, 'debug');
context.console.trace = this.log.bind(this, 'trace');
context.console.dir = this.log.bind(this, 'dir');
}
log(type, ...messages) {
if (messages[0].indexOf('hard-source')) {
return;
}
process.send({result: constants.pipeline.log, message: messages, type});
}
build(file, importsList, callback) { build(file, importsList, callback) {
const self = this; const self = this;
let realCwd; let realCwd;
@ -150,7 +119,3 @@ process.on('message', (msg) => {
}); });
} }
}); });
process.on('exit', () => {
process.exit(0);
});