diff --git a/lib/core/processWrapper.js b/lib/core/processWrapper.js new file mode 100644 index 00000000..e8c115f9 --- /dev/null +++ b/lib/core/processWrapper.js @@ -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; diff --git a/lib/pipeline/webpackProcess.js b/lib/pipeline/webpackProcess.js index e6484791..26d557e2 100644 --- a/lib/pipeline/webpackProcess.js +++ b/lib/pipeline/webpackProcess.js @@ -4,42 +4,11 @@ const utils = require('../utils/utils'); const fs = require('../core/fs'); const constants = require('../constants'); const HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); - -// 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); -}; +const ProcessWrapper = require('../core/processWrapper'); let webpackProcess; -class WebpackProcess { - 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}); - } - +class WebpackProcess extends ProcessWrapper { build(file, importsList, callback) { const self = this; let realCwd; @@ -150,7 +119,3 @@ process.on('message', (msg) => { }); } }); - -process.on('exit', () => { - process.exit(0); -});