add jsdoc to processWrapper

This commit is contained in:
Jonathan Rainville 2018-05-16 11:58:18 -04:00
parent d17256dc40
commit 80c382557f
1 changed files with 20 additions and 8 deletions

View File

@ -11,6 +11,15 @@ process.chdir = (...args) => {
};
class ProcessWrapper {
/**
* Class from which process extend. Should not be instantiated alone.
* Manages the log interception so that all console.* get sent back to the parent process
* Also creates an Events instance. To use it, just do `this.event.[on|request]`
*
* @param {Options} _options Nothing for now
* @return {ProcessWrapper} Do not instantiate this alone. Use it to extend
*/
constructor(_options) {
this.interceptLogs();
this.events = new Events();
@ -20,16 +29,19 @@ class ProcessWrapper {
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');
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')) {
_log(type, ...messages) {
const isHardSource = messages.some(message => {
return (typeof message === 'string' && message.indexOf('hard-source') > -1);
});
if (isHardSource) {
return;
}
process.send({result: constants.process.log, message: messages, type});