pidtree
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -8,15 +8,21 @@ #!/usr/bin/env node | ||
// The method startsWith is not defined on string objects in node 0.10 | ||
// eslint-disable-next-line no-extend-native | ||
String.prototype.startsWith = function(suffix) { | ||
return this.substring(0, suffix.length) === suffix; | ||
}; | ||
function help() { | ||
var help = ` Usage | ||
$ pidtree <ppid> | ||
Options | ||
--list To print the pids as a list. | ||
Examples | ||
$ pidtree | ||
$ pidtree --list | ||
$ pidtree 1 | ||
$ pidtree 1 --list | ||
`; | ||
var help = | ||
' Usage\n' + | ||
' $ pidtree <ppid>\n' + | ||
'\n' + | ||
'Options\n' + | ||
' --list To print the pids as a list.\n' + | ||
'\n' + | ||
'Examples\n' + | ||
' $ pidtree\n' + | ||
' $ pidtree --list\n' + | ||
' $ pidtree 1\n' + | ||
' $ pidtree 1 --list\n'; | ||
console.log(help); | ||
@@ -31,2 +37,3 @@ } | ||
} | ||
console.log(list.join(os.EOL)); | ||
@@ -46,19 +53,25 @@ }); | ||
while (list.length > 0) { | ||
var e = list.pop(); | ||
if (tree[e.ppid]) { | ||
tree[e.ppid].push(e.pid); | ||
var element = list.pop(); | ||
if (tree[element.ppid]) { | ||
tree[element.ppid].push(element.pid); | ||
} else { | ||
tree[e.ppid] = [e.pid]; | ||
tree[element.ppid] = [element.pid]; | ||
} | ||
if (ppid === -1) { | ||
parents[e.pid] = e.ppid; | ||
parents[element.pid] = element.ppid; | ||
} | ||
} | ||
var roots = [ppid]; | ||
if (ppid === -1) { | ||
// Get all the roots | ||
roots = Object.keys(tree).filter(node => parents[node] === undefined); | ||
roots = Object.keys(tree).filter(function(node) { | ||
return parents[node] === undefined; | ||
}); | ||
} | ||
roots.forEach(root => print(tree, root)); | ||
roots.forEach(function(root) { | ||
print(tree, root); | ||
}); | ||
}); | ||
@@ -68,6 +81,6 @@ | ||
function printBranch(node, branch) { | ||
const isGraphHead = branch.length === 0; | ||
const children = tree[node] || []; | ||
var isGraphHead = branch.length === 0; | ||
var children = tree[node] || []; | ||
let branchHead = ''; | ||
var branchHead = ''; | ||
if (!isGraphHead) { | ||
@@ -77,13 +90,13 @@ branchHead = children.length > 0 ? '┬ ' : '─ '; | ||
console.log(`${branch}${branchHead}${node}`); | ||
console.log(branch + branchHead + node); | ||
var baseBranch = branch; | ||
if (!isGraphHead) { | ||
const isChildOfLastBranch = branch.slice(-2) === '└─'; | ||
var isChildOfLastBranch = branch.slice(-2) === '└─'; | ||
baseBranch = branch.slice(0, -2) + (isChildOfLastBranch ? ' ' : '| '); | ||
} | ||
const nextBranch = baseBranch + '├─'; | ||
const lastBranch = baseBranch + '└─'; | ||
children.forEach((child, index) => { | ||
var nextBranch = baseBranch + '├─'; | ||
var lastBranch = baseBranch + '└─'; | ||
children.forEach(function(child, index) { | ||
printBranch( | ||
@@ -110,2 +123,3 @@ child, | ||
} | ||
if (ppid === undefined) { | ||
@@ -112,0 +126,0 @@ ppid = -1; |
10
index.js
@@ -12,2 +12,8 @@ 'use strict'; | ||
// The method startsWith is not defined on string objects in node 0.10 | ||
// eslint-disable-next-line no-extend-native | ||
String.prototype.startsWith = function(suffix) { | ||
return this.substring(0, suffix.length) === suffix; | ||
}; | ||
var pidtree = require('./lib/pidtree'); | ||
@@ -18,3 +24,3 @@ | ||
* @public | ||
* @param {Number|String} PID A PID. If -1 will return all the pids. | ||
* @param {Number|String} pid A PID. If -1 will return all the pids. | ||
* @param {Object} [options] Optional options object. | ||
@@ -33,2 +39,3 @@ * @param {Boolean} [options.root=false] Include the provided PID in the list. | ||
} | ||
if (typeof callback === 'function') { | ||
@@ -38,2 +45,3 @@ pidtree(pid, options, callback); | ||
} | ||
return pify(pidtree, pid, options); | ||
@@ -40,0 +48,0 @@ } |
@@ -7,4 +7,5 @@ 'use strict'; | ||
* Spawn a binary and read its stdout. | ||
* @param {String} cmd | ||
* @param {String[]} args | ||
* @param {String} cmd The name of the binary to spawn. | ||
* @param {String[]} args The arguments for the binary. | ||
* @param {Object} [options] Optional option for the spawn function. | ||
* @param {Function} done(err, stdout) | ||
@@ -11,0 +12,0 @@ */ |
@@ -12,3 +12,3 @@ 'use strict'; | ||
linux: 'ps', | ||
aix: 'ps', | ||
aix: 'ps' | ||
}; | ||
@@ -20,2 +20,3 @@ | ||
} | ||
var file = platformToMethod[platform]; | ||
@@ -29,3 +30,3 @@ | ||
if (file === undefined) { | ||
return callback( | ||
callback( | ||
new Error( | ||
@@ -32,0 +33,0 @@ os.platform() + |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable complexity */ | ||
'use strict'; | ||
@@ -13,3 +12,3 @@ | ||
* format {pid: X, ppid: Y}. | ||
* @param {pidCallback} callback Called when the list is ready. | ||
* @param {Function} callback(err, list) Called when the list is ready. | ||
*/ | ||
@@ -21,2 +20,3 @@ function list(PID, options, callback) { | ||
} | ||
if (typeof options !== 'object') { | ||
@@ -45,2 +45,3 @@ options = {}; | ||
} | ||
callback(null, list); | ||
@@ -56,2 +57,3 @@ return; | ||
} | ||
if (list[l][0] === PID) { | ||
@@ -61,2 +63,3 @@ root = options.advanced ? {pid: PID} : PID; // Special pids like 0 on *nix | ||
} | ||
if (!root) { | ||
@@ -70,7 +73,7 @@ callback(new Error('No maching pid found')); | ||
while (list.length > 0) { | ||
var e = list.pop(); | ||
if (tree[e[0]]) { | ||
tree[e[0]].push(e[1]); | ||
var element = list.pop(); | ||
if (tree[element[0]]) { | ||
tree[element[0]].push(element[1]); | ||
} else { | ||
tree[e[0]] = [e[1]]; | ||
tree[element[0]] = [element[1]]; | ||
} | ||
@@ -87,4 +90,4 @@ } | ||
if (!tree[curpid]) continue; | ||
var len = tree[curpid].length; | ||
for (var j = 0; j < len; j++) { | ||
var length = tree[curpid].length; | ||
for (var j = 0; j < length; j++) { | ||
pids.push( | ||
@@ -96,2 +99,3 @@ options.advanced | ||
} | ||
delete tree[curpid]; | ||
@@ -103,2 +107,3 @@ } | ||
} | ||
callback(null, pids); | ||
@@ -105,0 +110,0 @@ }); |
@@ -39,5 +39,6 @@ 'use strict'; | ||
} | ||
callback(null, list); | ||
} catch (err) { | ||
callback(err); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
@@ -44,0 +45,0 @@ }); |
@@ -18,2 +18,3 @@ 'use strict'; | ||
} | ||
if (code !== 0) { | ||
@@ -41,5 +42,6 @@ callback(new Error('pidtree wmic command exited with code ' + code)); | ||
} | ||
callback(null, list); | ||
} catch (err) { | ||
callback(err); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
@@ -46,0 +48,0 @@ }); |
{ | ||
"name": "pidtree", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Cross platform children list of a PID", | ||
@@ -47,3 +47,3 @@ "license": "MIT", | ||
"lint": "xo", | ||
"test": "npm run lint&& nyc ava -m \"!*benchmark*\"", | ||
"test": "nyc ava -m \"!*benchmark*\"", | ||
"bench": "ava -m \"*benchmark*\"", | ||
@@ -53,8 +53,8 @@ "coverage": "codecov" | ||
"devDependencies": { | ||
"ava": "*", | ||
"codecov": "*", | ||
"ava": "~0.25.0", | ||
"codecov": "^3.6.5", | ||
"mockery": "^2.1.0", | ||
"np": "*", | ||
"npm-check": "*", | ||
"nyc": "*", | ||
"np": "^2.20.1", | ||
"npm-check": "^5.9.2", | ||
"nyc": "^11.6.0", | ||
"pify": "^3.0.0", | ||
@@ -65,3 +65,3 @@ "string-to-stream": "^1.1.0", | ||
"tree-kill": "^1.1.0", | ||
"xo": "*" | ||
"xo": "~0.20.3" | ||
}, | ||
@@ -81,7 +81,11 @@ "ava": { | ||
"rules": { | ||
"prefer-destructuring": 0, | ||
"prefer-arrow-callback": 0, | ||
"no-var": 0, | ||
"object-shorthand": 0 | ||
"object-shorthand": 0, | ||
"unicorn/no-for-loop": 0, | ||
"unicorn/prefer-string-slice": 0, | ||
"unicorn/string-content": 0 | ||
} | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19837
386
1