diff --git a/README.md b/README.md index da2522d..d9091aa 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -# child-process-debug # +# child_process_inspect # -Convenience methods for debugging child processes in Node.JS. Child processes will be started with `--debug` if the -parent was started with `--debug` and the children will each get their own increasing port number based off the -parent's port number. The default port is 5858. If you add `--debug-brk` that will also get passed to the children. +Convenience methods for debugging child processes in Node.JS. Child processes will be started with `--inspect` if the +parent was started with `--inspect` and the children will each get their own increasing port number based off the +parent's port number. The default port is 5858. If you add `--inspect-brk` that will also get passed to the children. ## Example ## ```JS -var childProcessDebug = require('child-process-debug'); +var childProcessDebug = require('child_process_inspect'); for (var i = 0; i < 4; i++) { - //if this script wasn't run with --debug this will spawn node example.js [0-3] - //if this script was run with --debug, this will spawn node --debug=[5859-5862] example.js [0-3] + //if this script wasn't run with --inspect this will spawn node example.js [0-3] + //if this script was run with --inspect, this will spawn node --inspect=[5859-5862] example.js [0-3] childProcessDebug.spawn(['example.js', i]); } ``` @@ -18,7 +18,7 @@ for (var i = 0; i < 4; i++) { ## Methods ## ### spawn([command][, args][, options]) ### -This takes the exact same arguments as `child_process.spawn` and if the parent had debugging turned on (via --debug), +This takes the exact same arguments as `child_process.spawn` and if the parent had debugging turned on (via --inspect), it'll turn on debugging for the spawned child. `command` is also optional (unlike `child_process.spawn`) and defaults to `process.execPath`. @@ -26,13 +26,13 @@ The ChildProcess returned from spawn will have a property called `debugPort` ind child or undefined. ### fork(modulePath [, args][, options]) ### -This takes the exact same arguments as `child_process.fork` and if the parent had debugging turned on (via --debug), +This takes the exact same arguments as `child_process.fork` and if the parent had debugging turned on (via --inspect), it'll turn on debugging for the spawned child. Return is the same as `spawn` above. ### nextPort() ### Returns the next debug port that comes after the current process's debug port. If the current process doesn't have debug turned on then this will return undefined. This is useful if you're not using `spawn` and want to specify the -`--debug=port` argument yourself. +`--inspect=port` argument yourself. ### exitWithParent(child) ### Kill's the spawned child when the parent dies. This will not work if the parent is killed with SIGKILL. @@ -41,6 +41,6 @@ Kill's the spawned child when the parent dies. This will not work if the parent Returns the current process's debug port or undefined if debug is not turned on. ### debugBreak() ### -Returns true if the current process has the flag `--debug-brk`. +Returns true if the current process has the flag `--inspect-brk`. -By [James Hartig](https://github.com/fastest963/) +By [ccckblaze based on James Hartig's work](https://github.com/fastest963/) diff --git a/debug.js b/debug.js index 4016e5c..9c36798 100644 --- a/debug.js +++ b/debug.js @@ -25,13 +25,18 @@ function _getDebugPort(argv) { if (typeof argv[i] !== 'string') { continue; } - if (argv[i] === '--debug-brk') { + if (argv[i] === '--inspect-brk') { debugBreak = true; continue; } - if (debugIndex === -1 && argv[i].indexOf('--debug') !== -1) { - port = parseInt(argv[i].substr(8), 10); - if (!port) { + if (debugIndex === -1){ + if(argv[i].indexOf('--inspect') !== -1) { + port = parseInt(argv[i].substr(10), 10); + if (!port) { + port = 5858; + } + } + else{ port = 5858; } debugIndex = i; @@ -59,7 +64,7 @@ function incrementDebugPort(info) { nextPort; if (portAndIndex[0]) { nextPort = portAndIndex[0] + 1; - process.execArgv.splice(portAndIndex[1], 1, '--debug=' + nextPort); + process.execArgv.splice(portAndIndex[1], 1, '--inspect=' + nextPort); if (info !== undefined) { setChildInfo(nextPort, info); } @@ -67,7 +72,7 @@ function incrementDebugPort(info) { return nextPort; } -//shove the --debug at the front of arguments +//shove the --inspect at the front of arguments function wrapSpawnFork(method /*, file , args, options*/) { var argsIndex = 2, file = arguments[1], @@ -87,13 +92,13 @@ function wrapSpawnFork(method /*, file , args, options*/) { argsPortBrk = _getDebugPort(args); debugPort = incrementDebugPort({args: args}); if (debugPort) { - //only add --debug=port when they didn't already add one + //only add --inspect=port when they didn't already add one if (!argsPortBrk[0]) { - args.unshift('--debug=' + debugPort); + args.unshift('--inspect=' + debugPort); argsPortBrk[1] = 0; } if (!argsPortBrk[2] && myDebugBreak) { - args.splice(argsPortBrk[1] + 1, 0, '--debug-brk'); + args.splice(argsPortBrk[1] + 1, 0, '--inspect-brk'); } } //in case they add more params in the future, concat new args on diff --git a/package.json b/package.json index 4a0df01..621cc16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "child-process-debug", - "version": "0.0.7", + "name": "child_process_inspect", + "version": "0.0.9", "description": "Convenience methods for debugging child-process", "main": "debug.js", "directories": { @@ -15,16 +15,18 @@ }, "repository": { "type": "git", - "url": "git://github.com/fastest963/child-process-debug.git" + "url": "git://github.com/ccckblaze/child_process_inspect" }, "keywords": [ "child_process", "child", "process", "debug", - "debugger" + "debugger", + "inspect", + "inspect-brk" ], - "author": "James Hartig ", + "author": "ccckblaze ", "license": "MIT", "readmeFilename": "README.md" }