Advertisement
Superloup10

Untitled

May 25th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fork = require("child_process").fork;
  2.  
  3. let debugArg = process.execArgv.find(args => /^--(debug|inspect)/.test(args));
  4.  
  5. const debugging = !!debugArg;
  6.  
  7. debugArg = debugArg ? debugArg.replace('-brk', '').split('=') : ['--debug', 5859];
  8. let lastAddress = parseInt(debugArg[1], 10);
  9.  
  10. function debugFork(modulePath, args, options) {
  11.     let execArgv = [];
  12.     if (global.v8debug || debugging) {
  13.         lastAddress += 1;
  14.         execArgv = [debugArg[0] + '=' + lastAddress, '--nolazy'];
  15.     }
  16.     if (!Array.isArray(args)) {
  17.         options = args;
  18.         args = [];
  19.     }
  20.  
  21.     options = options || {};
  22.     options = Object.assign({}, options, {execArgv});
  23.  
  24.     return fork(modulePath, args, options);
  25. }
  26. debugFork.debugging = debugging;
  27.  
  28. module.exports = debugFork;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement