@webpod/ps 0.0.0-beta.0 → 0.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/package.json +15 -14
- package/target/cjs/index.cjs +63 -25
- package/target/dts/index.d.ts +13 -5
- package/target/dts/ps.d.ts +25 -13
- package/target/esm/index.mjs +58 -24
- package/target/dts/foo.d.ts +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* [x] CJS and ESM package entry points
|
|
8
8
|
* [x] `table-parser` replaced with `@webpod/ingrid` to handle some issues: [neekey/ps#76](https://github.com/neekey/ps/issues/76), [neekey/ps#62](https://github.com/neekey/ps/issues/62), [neekey/table-parser#11](https://github.com/neekey/table-parser/issues/11), [neekey/table-parser#18](https://github.com/neekey/table-parser/issues/18)
|
|
9
9
|
* [x] Provides promisified responses
|
|
10
|
-
* [
|
|
10
|
+
* [x] Brings sync API
|
|
11
11
|
* [x] Builds a process tree
|
|
12
12
|
|
|
13
13
|
## Install
|
|
@@ -44,6 +44,9 @@ lookup({pid: 12345}, (err, list) => {
|
|
|
44
44
|
console.log('No such process found!')
|
|
45
45
|
}
|
|
46
46
|
})
|
|
47
|
+
|
|
48
|
+
// or syncronously
|
|
49
|
+
const _list = lookup.sync({pid: 12345})
|
|
47
50
|
```
|
|
48
51
|
|
|
49
52
|
Define a query opts to filter the results by `command` and/or `arguments` predicates:
|
|
@@ -109,6 +112,9 @@ const children = await tree({pid: 123, recursive: true})
|
|
|
109
112
|
{pid: 130, ppid: 125},
|
|
110
113
|
]
|
|
111
114
|
*/
|
|
115
|
+
|
|
116
|
+
// or syncronously
|
|
117
|
+
const list = tree.sync({pid: 123, recursive: true})
|
|
112
118
|
```
|
|
113
119
|
|
|
114
120
|
### kill()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpod/ps",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.10",
|
|
4
4
|
"description": "A process lookup utility",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"test": "concurrently 'npm:test:*'",
|
|
25
25
|
"test:lint": "eslint -c src/test/lint/.eslintrc.json src",
|
|
26
26
|
"test:unit": "c8 -r lcov -r text -o target/coverage -x src/scripts -x src/test -x target node --loader ts-node/esm --experimental-specifier-resolution=node src/scripts/test.mjs",
|
|
27
|
-
"test:legacy": "node ./node_modules/mocha/bin/mocha -t 0 -R spec src/test/legacy/test.cjs"
|
|
27
|
+
"test:legacy": "node ./node_modules/mocha/bin/mocha -t 0 -R spec src/test/legacy/test.cjs",
|
|
28
|
+
"publish:draft": "npm run build && npm publish --no-git-tag-version"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"target/cjs",
|
|
@@ -38,25 +39,25 @@
|
|
|
38
39
|
"pid"
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@webpod/ingrid": "^0.0.0-beta.
|
|
42
|
-
"zurk": "^0.0
|
|
42
|
+
"@webpod/ingrid": "^0.0.0-beta.3",
|
|
43
|
+
"zurk": "^0.6.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^
|
|
46
|
-
"c8": "^
|
|
47
|
-
"concurrently": "^
|
|
48
|
-
"esbuild": "^0.
|
|
49
|
-
"esbuild-node-externals": "^1.
|
|
50
|
-
"esbuild-plugin-entry-chunks": "^0.1.
|
|
46
|
+
"@types/node": "^22.7.6",
|
|
47
|
+
"c8": "^10.1.2",
|
|
48
|
+
"concurrently": "^9.0.1",
|
|
49
|
+
"esbuild": "^0.24.0",
|
|
50
|
+
"esbuild-node-externals": "^1.15.0",
|
|
51
|
+
"esbuild-plugin-entry-chunks": "^0.1.15",
|
|
51
52
|
"eslint": "^8.57.0",
|
|
52
53
|
"eslint-config-qiwi": "^2.1.3",
|
|
53
54
|
"fast-glob": "^3.3.2",
|
|
54
55
|
"minimist": "^1.2.8",
|
|
55
|
-
"mocha": "^10.3
|
|
56
|
-
"sinon": "^
|
|
56
|
+
"mocha": "^10.7.3",
|
|
57
|
+
"sinon": "^18.0.1",
|
|
57
58
|
"ts-node": "^10.9.2",
|
|
58
|
-
"typedoc": "^0.
|
|
59
|
-
"typescript": "^5.
|
|
59
|
+
"typedoc": "^0.26.10",
|
|
60
|
+
"typescript": "^5.6.3"
|
|
60
61
|
},
|
|
61
62
|
"repository": {
|
|
62
63
|
"type": "git",
|
package/target/cjs/index.cjs
CHANGED
|
@@ -53,47 +53,56 @@ __export(ts_exports, {
|
|
|
53
53
|
default: () => ts_default,
|
|
54
54
|
kill: () => kill,
|
|
55
55
|
lookup: () => lookup,
|
|
56
|
-
|
|
56
|
+
lookupSync: () => lookupSync,
|
|
57
|
+
tree: () => tree,
|
|
58
|
+
treeSync: () => treeSync
|
|
57
59
|
});
|
|
58
60
|
module.exports = __toCommonJS(ts_exports);
|
|
59
61
|
|
|
60
62
|
// src/main/ts/ps.ts
|
|
61
63
|
var import_node_process = __toESM(require("node:process"), 1);
|
|
62
64
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
65
|
+
var import_node_os = require("node:os");
|
|
63
66
|
var import_ingrid = require("@webpod/ingrid");
|
|
64
67
|
var import_spawn = require("zurk/spawn");
|
|
65
|
-
var import_node_os = require("node:os");
|
|
66
68
|
var EOL = /(\r\n)|(\n\r)|\n|\r/;
|
|
67
69
|
var IS_WIN = import_node_process.default.platform === "win32";
|
|
68
70
|
var isBin = (f) => {
|
|
69
|
-
if (f === "")
|
|
70
|
-
|
|
71
|
-
if (!
|
|
72
|
-
return true;
|
|
73
|
-
if (!import_node_fs.default.existsSync(f))
|
|
74
|
-
return false;
|
|
71
|
+
if (f === "") return false;
|
|
72
|
+
if (!f.includes("/")) return true;
|
|
73
|
+
if (!import_node_fs.default.existsSync(f)) return false;
|
|
75
74
|
const stat = import_node_fs.default.lstatSync(f);
|
|
76
75
|
return stat.isFile() || stat.isSymbolicLink();
|
|
77
76
|
};
|
|
78
|
-
var lookup = (query = {}, cb = noop) => {
|
|
79
|
-
|
|
77
|
+
var lookup = (query = {}, cb = noop) => _lookup({ query, cb, sync: false });
|
|
78
|
+
var lookupSync = (query = {}, cb = noop) => _lookup({ query, cb, sync: true });
|
|
79
|
+
lookup.sync = lookupSync;
|
|
80
|
+
var _lookup = ({
|
|
81
|
+
query = {},
|
|
82
|
+
cb = noop,
|
|
83
|
+
sync = false
|
|
84
|
+
}) => {
|
|
85
|
+
const pFactory = sync ? makePseudoDeferred.bind(null, []) : makeDeferred;
|
|
86
|
+
const { promise, resolve, reject } = pFactory();
|
|
80
87
|
const { psargs = ["-lx"] } = query;
|
|
81
|
-
const args =
|
|
88
|
+
const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
|
|
82
89
|
const extract = IS_WIN ? extractWmic : identity;
|
|
90
|
+
let result = [];
|
|
83
91
|
const callback = (err, { stdout }) => {
|
|
84
92
|
if (err) {
|
|
85
93
|
reject(err);
|
|
86
94
|
cb(err);
|
|
87
95
|
return;
|
|
88
96
|
}
|
|
89
|
-
|
|
90
|
-
resolve(
|
|
91
|
-
cb(null,
|
|
97
|
+
result = parseProcessList(extract(stdout), query);
|
|
98
|
+
resolve(result);
|
|
99
|
+
cb(null, result);
|
|
92
100
|
};
|
|
93
101
|
const ctx = IS_WIN ? {
|
|
94
102
|
cmd: "cmd",
|
|
95
103
|
input: "wmic process get ProcessId,ParentProcessId,CommandLine \n",
|
|
96
104
|
callback,
|
|
105
|
+
sync,
|
|
97
106
|
run(cb2) {
|
|
98
107
|
cb2();
|
|
99
108
|
}
|
|
@@ -103,10 +112,11 @@ var lookup = (query = {}, cb = noop) => {
|
|
|
103
112
|
run(cb2) {
|
|
104
113
|
cb2();
|
|
105
114
|
},
|
|
115
|
+
sync,
|
|
106
116
|
callback
|
|
107
117
|
};
|
|
108
118
|
(0, import_spawn.exec)(ctx);
|
|
109
|
-
return promise;
|
|
119
|
+
return Object.assign(promise, result);
|
|
110
120
|
};
|
|
111
121
|
var parseProcessList = (output, query = {}) => {
|
|
112
122
|
const processList = parseGrid(output.trim());
|
|
@@ -134,20 +144,38 @@ var pickTree = (list, pid, recursive = false) => {
|
|
|
134
144
|
...children.flatMap((p) => recursive ? pickTree(list, p.pid, true) : [])
|
|
135
145
|
];
|
|
136
146
|
};
|
|
137
|
-
var
|
|
147
|
+
var _tree = ({
|
|
148
|
+
cb = noop,
|
|
149
|
+
opts,
|
|
150
|
+
sync = false
|
|
151
|
+
}) => {
|
|
138
152
|
if (typeof opts === "string" || typeof opts === "number") {
|
|
139
|
-
return
|
|
153
|
+
return _tree({ opts: { pid: opts }, cb, sync });
|
|
140
154
|
}
|
|
141
|
-
|
|
155
|
+
const onError = (err) => cb(err);
|
|
156
|
+
const onData = (all) => {
|
|
157
|
+
if (opts === void 0) return all;
|
|
142
158
|
const { pid, recursive = false } = opts;
|
|
143
|
-
const list = pickTree(
|
|
159
|
+
const list = pickTree(all, pid, recursive);
|
|
144
160
|
cb(null, list);
|
|
145
161
|
return list;
|
|
162
|
+
};
|
|
163
|
+
try {
|
|
164
|
+
const all = _lookup({ sync });
|
|
165
|
+
return sync ? onData(all) : all.then(onData, (err) => {
|
|
166
|
+
onError(err);
|
|
167
|
+
throw err;
|
|
168
|
+
});
|
|
146
169
|
} catch (err) {
|
|
147
|
-
|
|
148
|
-
|
|
170
|
+
onError(err);
|
|
171
|
+
return Promise.reject(err);
|
|
149
172
|
}
|
|
173
|
+
};
|
|
174
|
+
var tree = (opts, cb) => __async(void 0, null, function* () {
|
|
175
|
+
return _tree({ opts, cb });
|
|
150
176
|
});
|
|
177
|
+
var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
|
|
178
|
+
tree.sync = treeSync;
|
|
151
179
|
var kill = (pid, opts, next) => {
|
|
152
180
|
if (typeof opts == "function") {
|
|
153
181
|
return kill(pid, void 0, opts);
|
|
@@ -171,8 +199,7 @@ var kill = (pid, opts, next) => {
|
|
|
171
199
|
let checkTimeoutTimer;
|
|
172
200
|
let checkIsTimeout = false;
|
|
173
201
|
const checkKilled = (finishCallback) => lookup({ pid }, (err, list = []) => {
|
|
174
|
-
if (checkIsTimeout)
|
|
175
|
-
return;
|
|
202
|
+
if (checkIsTimeout) return;
|
|
176
203
|
if (err) {
|
|
177
204
|
clearTimeout(checkTimeoutTimer);
|
|
178
205
|
reject(err);
|
|
@@ -230,15 +257,26 @@ var makeDeferred = () => {
|
|
|
230
257
|
});
|
|
231
258
|
return { resolve, reject, promise };
|
|
232
259
|
};
|
|
260
|
+
var makePseudoDeferred = (r = {}) => {
|
|
261
|
+
return {
|
|
262
|
+
promise: r,
|
|
263
|
+
resolve: identity,
|
|
264
|
+
reject(e) {
|
|
265
|
+
throw e;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
};
|
|
233
269
|
var noop = () => {
|
|
234
270
|
};
|
|
235
271
|
var identity = (v) => v;
|
|
236
272
|
|
|
237
273
|
// src/main/ts/index.ts
|
|
238
|
-
var ts_default = { lookup,
|
|
274
|
+
var ts_default = { kill, lookup, lookupSync, tree, treeSync };
|
|
239
275
|
// Annotate the CommonJS export names for ESM import in node:
|
|
240
276
|
0 && (module.exports = {
|
|
241
277
|
kill,
|
|
242
278
|
lookup,
|
|
243
|
-
|
|
279
|
+
lookupSync,
|
|
280
|
+
tree,
|
|
281
|
+
treeSync
|
|
244
282
|
});
|
package/target/dts/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
export type * from './ps.
|
|
2
|
-
export { kill, lookup, tree } from './ps.
|
|
1
|
+
export type * from './ps.js';
|
|
2
|
+
export { kill, lookup, lookupSync, tree, treeSync } from './ps.js';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
kill: (pid: string | number, opts?: import("./ps.js").TPsNext | import("./ps.js").TPsKillOptions | import("./ps.js").TPsKillOptions["signal"], next?: import("./ps.js").TPsNext) => Promise<void>;
|
|
5
|
+
lookup: {
|
|
6
|
+
(query?: import("./ps.js").TPsLookupQuery, cb?: import("./ps.js").TPsLookupCallback): Promise<import("./ps.js").TPsLookupEntry[]>;
|
|
7
|
+
sync: (query?: import("./ps.js").TPsLookupQuery, cb?: import("./ps.js").TPsLookupCallback) => import("./ps.js").TPsLookupEntry[];
|
|
8
|
+
};
|
|
9
|
+
lookupSync: (query?: import("./ps.js").TPsLookupQuery, cb?: import("./ps.js").TPsLookupCallback) => import("./ps.js").TPsLookupEntry[];
|
|
10
|
+
tree: {
|
|
11
|
+
(opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback): Promise<import("./ps.js").TPsLookupEntry[]>;
|
|
12
|
+
sync: (opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback) => import("./ps.js").TPsLookupEntry[];
|
|
13
|
+
};
|
|
14
|
+
treeSync: (opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback) => import("./ps.js").TPsLookupEntry[];
|
|
7
15
|
};
|
|
8
16
|
export default _default;
|
package/target/dts/ps.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { TIngridResponse } from '@webpod/ingrid';
|
|
3
2
|
export type TPsLookupCallback = (err: any, processList?: TPsLookupEntry[]) => void;
|
|
4
3
|
export type TPsLookupEntry = {
|
|
@@ -26,12 +25,28 @@ export type TPsNext = (err?: any, data?: any) => void;
|
|
|
26
25
|
* @param {String} query.command RegExp String
|
|
27
26
|
* @param {String} query.arguments RegExp String
|
|
28
27
|
* @param {String|String[]} query.psargs
|
|
29
|
-
* @param {Function} cb
|
|
28
|
+
* @param {Function} [cb]
|
|
29
|
+
* @param {Object=null} cb.err
|
|
30
|
+
* @param {TPsLookupEntry[]} cb.processList
|
|
31
|
+
* @return {Promise<TPsLookupEntry[]>}
|
|
32
|
+
*/
|
|
33
|
+
export declare const lookup: {
|
|
34
|
+
(query?: TPsLookupQuery, cb?: TPsLookupCallback): Promise<TPsLookupEntry[]>;
|
|
35
|
+
sync: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => TPsLookupEntry[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Looks up the process list synchronously
|
|
39
|
+
* @param query
|
|
40
|
+
* @param {String|String[]} query.pid
|
|
41
|
+
* @param {String} query.command RegExp String
|
|
42
|
+
* @param {String} query.arguments RegExp String
|
|
43
|
+
* @param {String|String[]} query.psargs
|
|
44
|
+
* @param {Function} [cb]
|
|
30
45
|
* @param {Object=null} cb.err
|
|
31
46
|
* @param {Object[]} cb.processList
|
|
32
|
-
* @return {
|
|
47
|
+
* @return {TPsLookupEntry[]}
|
|
33
48
|
*/
|
|
34
|
-
export declare const
|
|
49
|
+
export declare const lookupSync: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => TPsLookupEntry[];
|
|
35
50
|
export declare const parseProcessList: (output: string, query?: TPsLookupQuery) => TPsLookupEntry[];
|
|
36
51
|
export declare const extractWmic: (stdout: string) => string;
|
|
37
52
|
export type TPsTreeOpts = {
|
|
@@ -39,7 +54,11 @@ export type TPsTreeOpts = {
|
|
|
39
54
|
recursive?: boolean;
|
|
40
55
|
};
|
|
41
56
|
export declare const pickTree: (list: TPsLookupEntry[], pid: string | number, recursive?: boolean) => TPsLookupEntry[];
|
|
42
|
-
export declare const tree:
|
|
57
|
+
export declare const tree: {
|
|
58
|
+
(opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback): Promise<TPsLookupEntry[]>;
|
|
59
|
+
sync: (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback) => TPsLookupEntry[];
|
|
60
|
+
};
|
|
61
|
+
export declare const treeSync: (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback) => TPsLookupEntry[];
|
|
43
62
|
/**
|
|
44
63
|
* Kill process
|
|
45
64
|
* @param pid
|
|
@@ -48,14 +67,7 @@ export declare const tree: (opts: string | number | TPsTreeOpts, cb?: TPsLookupC
|
|
|
48
67
|
* @param {number} opts.timeout
|
|
49
68
|
* @param next
|
|
50
69
|
*/
|
|
51
|
-
export declare const kill: (pid: string | number, opts?: TPsNext | TPsKillOptions | TPsKillOptions[
|
|
70
|
+
export declare const kill: (pid: string | number, opts?: TPsNext | TPsKillOptions | TPsKillOptions["signal"], next?: TPsNext) => Promise<void>;
|
|
52
71
|
export declare const parseGrid: (output: string) => TPsLookupEntry[];
|
|
53
72
|
export declare const formatOutput: (data: TIngridResponse) => TPsLookupEntry[];
|
|
54
73
|
export type PromiseResolve<T = any> = (value?: T | PromiseLike<T>) => void;
|
|
55
|
-
export declare const makeDeferred: <T = any, E = any>() => {
|
|
56
|
-
promise: Promise<T>;
|
|
57
|
-
resolve: PromiseResolve<T>;
|
|
58
|
-
reject: PromiseResolve<E>;
|
|
59
|
-
};
|
|
60
|
-
export declare const noop: () => void;
|
|
61
|
-
export declare const identity: <T>(v: T) => T;
|
package/target/esm/index.mjs
CHANGED
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
// src/main/ts/ps.ts
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import { EOL as SystemEOL } from "node:os";
|
|
4
5
|
import { parse } from "@webpod/ingrid";
|
|
5
6
|
import { exec } from "zurk/spawn";
|
|
6
|
-
import { EOL as SystemEOL } from "node:os";
|
|
7
7
|
var EOL = /(\r\n)|(\n\r)|\n|\r/;
|
|
8
8
|
var IS_WIN = process.platform === "win32";
|
|
9
9
|
var isBin = (f) => {
|
|
10
|
-
if (f === "")
|
|
11
|
-
|
|
12
|
-
if (!
|
|
13
|
-
return true;
|
|
14
|
-
if (!fs.existsSync(f))
|
|
15
|
-
return false;
|
|
10
|
+
if (f === "") return false;
|
|
11
|
+
if (!f.includes("/")) return true;
|
|
12
|
+
if (!fs.existsSync(f)) return false;
|
|
16
13
|
const stat = fs.lstatSync(f);
|
|
17
14
|
return stat.isFile() || stat.isSymbolicLink();
|
|
18
15
|
};
|
|
19
|
-
var lookup = (query = {}, cb = noop) => {
|
|
20
|
-
|
|
16
|
+
var lookup = (query = {}, cb = noop) => _lookup({ query, cb, sync: false });
|
|
17
|
+
var lookupSync = (query = {}, cb = noop) => _lookup({ query, cb, sync: true });
|
|
18
|
+
lookup.sync = lookupSync;
|
|
19
|
+
var _lookup = ({
|
|
20
|
+
query = {},
|
|
21
|
+
cb = noop,
|
|
22
|
+
sync = false
|
|
23
|
+
}) => {
|
|
24
|
+
const pFactory = sync ? makePseudoDeferred.bind(null, []) : makeDeferred;
|
|
25
|
+
const { promise, resolve, reject } = pFactory();
|
|
21
26
|
const { psargs = ["-lx"] } = query;
|
|
22
|
-
const args =
|
|
27
|
+
const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
|
|
23
28
|
const extract = IS_WIN ? extractWmic : identity;
|
|
29
|
+
let result = [];
|
|
24
30
|
const callback = (err, { stdout }) => {
|
|
25
31
|
if (err) {
|
|
26
32
|
reject(err);
|
|
27
33
|
cb(err);
|
|
28
34
|
return;
|
|
29
35
|
}
|
|
30
|
-
|
|
31
|
-
resolve(
|
|
32
|
-
cb(null,
|
|
36
|
+
result = parseProcessList(extract(stdout), query);
|
|
37
|
+
resolve(result);
|
|
38
|
+
cb(null, result);
|
|
33
39
|
};
|
|
34
40
|
const ctx = IS_WIN ? {
|
|
35
41
|
cmd: "cmd",
|
|
36
42
|
input: "wmic process get ProcessId,ParentProcessId,CommandLine \n",
|
|
37
43
|
callback,
|
|
44
|
+
sync,
|
|
38
45
|
run(cb2) {
|
|
39
46
|
cb2();
|
|
40
47
|
}
|
|
@@ -44,10 +51,11 @@ var lookup = (query = {}, cb = noop) => {
|
|
|
44
51
|
run(cb2) {
|
|
45
52
|
cb2();
|
|
46
53
|
},
|
|
54
|
+
sync,
|
|
47
55
|
callback
|
|
48
56
|
};
|
|
49
57
|
exec(ctx);
|
|
50
|
-
return promise;
|
|
58
|
+
return Object.assign(promise, result);
|
|
51
59
|
};
|
|
52
60
|
var parseProcessList = (output, query = {}) => {
|
|
53
61
|
const processList = parseGrid(output.trim());
|
|
@@ -75,20 +83,36 @@ var pickTree = (list, pid, recursive = false) => {
|
|
|
75
83
|
...children.flatMap((p) => recursive ? pickTree(list, p.pid, true) : [])
|
|
76
84
|
];
|
|
77
85
|
};
|
|
78
|
-
var
|
|
86
|
+
var _tree = ({
|
|
87
|
+
cb = noop,
|
|
88
|
+
opts,
|
|
89
|
+
sync = false
|
|
90
|
+
}) => {
|
|
79
91
|
if (typeof opts === "string" || typeof opts === "number") {
|
|
80
|
-
return
|
|
92
|
+
return _tree({ opts: { pid: opts }, cb, sync });
|
|
81
93
|
}
|
|
82
|
-
|
|
94
|
+
const onError = (err) => cb(err);
|
|
95
|
+
const onData = (all) => {
|
|
96
|
+
if (opts === void 0) return all;
|
|
83
97
|
const { pid, recursive = false } = opts;
|
|
84
|
-
const list = pickTree(
|
|
98
|
+
const list = pickTree(all, pid, recursive);
|
|
85
99
|
cb(null, list);
|
|
86
100
|
return list;
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const all = _lookup({ sync });
|
|
104
|
+
return sync ? onData(all) : all.then(onData, (err) => {
|
|
105
|
+
onError(err);
|
|
106
|
+
throw err;
|
|
107
|
+
});
|
|
87
108
|
} catch (err) {
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
onError(err);
|
|
110
|
+
return Promise.reject(err);
|
|
90
111
|
}
|
|
91
112
|
};
|
|
113
|
+
var tree = async (opts, cb) => _tree({ opts, cb });
|
|
114
|
+
var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
|
|
115
|
+
tree.sync = treeSync;
|
|
92
116
|
var kill = (pid, opts, next) => {
|
|
93
117
|
if (typeof opts == "function") {
|
|
94
118
|
return kill(pid, void 0, opts);
|
|
@@ -112,8 +136,7 @@ var kill = (pid, opts, next) => {
|
|
|
112
136
|
let checkTimeoutTimer;
|
|
113
137
|
let checkIsTimeout = false;
|
|
114
138
|
const checkKilled = (finishCallback) => lookup({ pid }, (err, list = []) => {
|
|
115
|
-
if (checkIsTimeout)
|
|
116
|
-
return;
|
|
139
|
+
if (checkIsTimeout) return;
|
|
117
140
|
if (err) {
|
|
118
141
|
clearTimeout(checkTimeoutTimer);
|
|
119
142
|
reject(err);
|
|
@@ -170,15 +193,26 @@ var makeDeferred = () => {
|
|
|
170
193
|
});
|
|
171
194
|
return { resolve, reject, promise };
|
|
172
195
|
};
|
|
196
|
+
var makePseudoDeferred = (r = {}) => {
|
|
197
|
+
return {
|
|
198
|
+
promise: r,
|
|
199
|
+
resolve: identity,
|
|
200
|
+
reject(e) {
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
173
205
|
var noop = () => {
|
|
174
206
|
};
|
|
175
207
|
var identity = (v) => v;
|
|
176
208
|
|
|
177
209
|
// src/main/ts/index.ts
|
|
178
|
-
var ts_default = { lookup,
|
|
210
|
+
var ts_default = { kill, lookup, lookupSync, tree, treeSync };
|
|
179
211
|
export {
|
|
180
212
|
ts_default as default,
|
|
181
213
|
kill,
|
|
182
214
|
lookup,
|
|
183
|
-
|
|
215
|
+
lookupSync,
|
|
216
|
+
tree,
|
|
217
|
+
treeSync
|
|
184
218
|
};
|
package/target/dts/foo.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const foo: () => undefined;
|