@webpod/ps 0.1.1 → 0.1.3
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/package.json +8 -8
- package/target/cjs/index.cjs +17 -13
- package/target/dts/ps.d.ts +3 -7
- package/target/esm/index.mjs +16 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpod/ps",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A process lookup utility",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"pid"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@webpod/ingrid": "^
|
|
45
|
-
"zurk": "^0.11.
|
|
44
|
+
"@webpod/ingrid": "^1.1.1",
|
|
45
|
+
"zurk": "^0.11.4"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^
|
|
48
|
+
"@types/node": "^24.0.13",
|
|
49
49
|
"c8": "^10.1.3",
|
|
50
|
-
"concurrently": "^9.
|
|
51
|
-
"esbuild": "^0.25.
|
|
50
|
+
"concurrently": "^9.2.0",
|
|
51
|
+
"esbuild": "^0.25.6",
|
|
52
52
|
"esbuild-node-externals": "^1.18.0",
|
|
53
53
|
"esbuild-plugin-entry-chunks": "^0.1.15",
|
|
54
54
|
"eslint": "^8.57.0",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"mocha": "^10.8.2",
|
|
59
59
|
"sinon": "^18.0.1",
|
|
60
60
|
"ts-node": "^10.9.2",
|
|
61
|
-
"typedoc": "^0.28.
|
|
62
|
-
"typescript": "^5.8.
|
|
61
|
+
"typedoc": "^0.28.7",
|
|
62
|
+
"typescript": "^5.8.3"
|
|
63
63
|
},
|
|
64
64
|
"repository": {
|
|
65
65
|
"type": "git",
|
package/target/cjs/index.cjs
CHANGED
|
@@ -65,11 +65,14 @@ var import_node_fs = __toESM(require("node:fs"), 1);
|
|
|
65
65
|
var import_node_os = require("node:os");
|
|
66
66
|
var import_ingrid = require("@webpod/ingrid");
|
|
67
67
|
var import_spawn = require("zurk/spawn");
|
|
68
|
-
var EOL = /\n\r?|\r\n?/;
|
|
69
68
|
var IS_WIN = import_node_process.default.platform === "win32";
|
|
69
|
+
var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine";
|
|
70
70
|
var isBin = (f) => {
|
|
71
71
|
if (f === "") return false;
|
|
72
72
|
if (!f.includes("/")) return true;
|
|
73
|
+
if (!f.includes("\\")) return true;
|
|
74
|
+
if (f.length > 3 && f[0] === '"')
|
|
75
|
+
return f[f.length - 1] === '"' ? isBin(f.slice(1, -1)) : false;
|
|
73
76
|
if (!import_node_fs.default.existsSync(f)) return false;
|
|
74
77
|
const stat = import_node_fs.default.lstatSync(f);
|
|
75
78
|
return stat.isFile() || stat.isSymbolicLink();
|
|
@@ -86,21 +89,21 @@ var _lookup = ({
|
|
|
86
89
|
const { promise, resolve, reject } = pFactory();
|
|
87
90
|
const { psargs = ["-lx"] } = query;
|
|
88
91
|
const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
|
|
89
|
-
const
|
|
90
|
-
|
|
92
|
+
const result = [];
|
|
93
|
+
const extract = IS_WIN ? removeWmicPrefix : identity;
|
|
91
94
|
const callback = (err, { stdout }) => {
|
|
92
95
|
if (err) {
|
|
93
96
|
reject(err);
|
|
94
97
|
cb(err);
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
|
-
result
|
|
100
|
+
result.push(...parseProcessList(extract(stdout), query));
|
|
98
101
|
resolve(result);
|
|
99
102
|
cb(null, result);
|
|
100
103
|
};
|
|
101
104
|
const ctx = IS_WIN ? {
|
|
102
|
-
cmd:
|
|
103
|
-
|
|
105
|
+
cmd: WMIC_INPUT,
|
|
106
|
+
args: [],
|
|
104
107
|
callback,
|
|
105
108
|
sync,
|
|
106
109
|
run(cb2) {
|
|
@@ -119,7 +122,7 @@ var _lookup = ({
|
|
|
119
122
|
return Object.assign(promise, result);
|
|
120
123
|
};
|
|
121
124
|
var parseProcessList = (output, query = {}) => {
|
|
122
|
-
const processList = parseGrid(output
|
|
125
|
+
const processList = parseGrid(output);
|
|
123
126
|
const pidList = (query.pid === void 0 ? [] : [query.pid].flat(1)).map((v) => v + "");
|
|
124
127
|
const filters = [
|
|
125
128
|
(p) => query.command ? new RegExp(query.command, "i").test(p.command) : true,
|
|
@@ -130,10 +133,10 @@ var parseProcessList = (output, query = {}) => {
|
|
|
130
133
|
(p) => (pidList.length === 0 || pidList.includes(p.pid)) && filters.every((f) => f(p))
|
|
131
134
|
);
|
|
132
135
|
};
|
|
133
|
-
var
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
return
|
|
136
|
+
var removeWmicPrefix = (stdout) => {
|
|
137
|
+
const s = stdout.indexOf(WMIC_INPUT + import_node_os.EOL);
|
|
138
|
+
const e = stdout.includes(">") ? stdout.trimEnd().lastIndexOf(import_node_os.EOL) : stdout.length;
|
|
139
|
+
return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trimStart();
|
|
137
140
|
};
|
|
138
141
|
var pickTree = (list, pid, recursive = false) => {
|
|
139
142
|
const children = list.filter((p) => p.ppid === pid + "");
|
|
@@ -169,7 +172,7 @@ var _tree = ({
|
|
|
169
172
|
return Promise.reject(err);
|
|
170
173
|
}
|
|
171
174
|
};
|
|
172
|
-
var tree = (opts, cb) => __async(
|
|
175
|
+
var tree = (opts, cb) => __async(null, null, function* () {
|
|
173
176
|
return _tree({ opts, cb });
|
|
174
177
|
});
|
|
175
178
|
var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
|
|
@@ -232,7 +235,8 @@ var formatOutput = (data) => data.reduce((m, d) => {
|
|
|
232
235
|
var _a, _b, _c, _d;
|
|
233
236
|
const pid = ((_a = d.PID) == null ? void 0 : _a[0]) || ((_b = d.ProcessId) == null ? void 0 : _b[0]);
|
|
234
237
|
const ppid = ((_c = d.PPID) == null ? void 0 : _c[0]) || ((_d = d.ParentProcessId) == null ? void 0 : _d[0]);
|
|
235
|
-
const
|
|
238
|
+
const _cmd = d.CMD || d.CommandLine || d.COMMAND || [];
|
|
239
|
+
const cmd = _cmd.length === 1 ? _cmd[0].split(/\s+/) : _cmd;
|
|
236
240
|
if (pid && cmd.length > 0) {
|
|
237
241
|
const c = cmd.findIndex((_v, i) => isBin(cmd.slice(0, i).join(" ")));
|
|
238
242
|
const command = cmd.slice(0, c).join(" ");
|
package/target/dts/ps.d.ts
CHANGED
|
@@ -25,9 +25,7 @@ export type TPsNext = (err?: any, data?: any) => void;
|
|
|
25
25
|
* @param {String} query.command RegExp String
|
|
26
26
|
* @param {String} query.arguments RegExp String
|
|
27
27
|
* @param {String|String[]} query.psargs
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {Object=null} cb.err
|
|
30
|
-
* @param {TPsLookupEntry[]} cb.processList
|
|
28
|
+
* @param {TPsLookupCallback} cb
|
|
31
29
|
* @return {Promise<TPsLookupEntry[]>}
|
|
32
30
|
*/
|
|
33
31
|
export declare const lookup: {
|
|
@@ -41,14 +39,12 @@ export declare const lookup: {
|
|
|
41
39
|
* @param {String} query.command RegExp String
|
|
42
40
|
* @param {String} query.arguments RegExp String
|
|
43
41
|
* @param {String|String[]} query.psargs
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {Object=null} cb.err
|
|
46
|
-
* @param {Object[]} cb.processList
|
|
42
|
+
* @param {TPsLookupCallback} cb
|
|
47
43
|
* @return {TPsLookupEntry[]}
|
|
48
44
|
*/
|
|
49
45
|
export declare const lookupSync: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => TPsLookupEntry[];
|
|
50
46
|
export declare const parseProcessList: (output: string, query?: TPsLookupQuery) => TPsLookupEntry[];
|
|
51
|
-
export declare const
|
|
47
|
+
export declare const removeWmicPrefix: (stdout: string) => string;
|
|
52
48
|
export type TPsTreeOpts = {
|
|
53
49
|
pid: string | number;
|
|
54
50
|
recursive?: boolean;
|
package/target/esm/index.mjs
CHANGED
|
@@ -4,11 +4,14 @@ import fs from "node:fs";
|
|
|
4
4
|
import { EOL as SystemEOL } from "node:os";
|
|
5
5
|
import { parse } from "@webpod/ingrid";
|
|
6
6
|
import { exec } from "zurk/spawn";
|
|
7
|
-
var EOL = /\n\r?|\r\n?/;
|
|
8
7
|
var IS_WIN = process.platform === "win32";
|
|
8
|
+
var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine";
|
|
9
9
|
var isBin = (f) => {
|
|
10
10
|
if (f === "") return false;
|
|
11
11
|
if (!f.includes("/")) return true;
|
|
12
|
+
if (!f.includes("\\")) return true;
|
|
13
|
+
if (f.length > 3 && f[0] === '"')
|
|
14
|
+
return f[f.length - 1] === '"' ? isBin(f.slice(1, -1)) : false;
|
|
12
15
|
if (!fs.existsSync(f)) return false;
|
|
13
16
|
const stat = fs.lstatSync(f);
|
|
14
17
|
return stat.isFile() || stat.isSymbolicLink();
|
|
@@ -25,21 +28,21 @@ var _lookup = ({
|
|
|
25
28
|
const { promise, resolve, reject } = pFactory();
|
|
26
29
|
const { psargs = ["-lx"] } = query;
|
|
27
30
|
const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
|
|
28
|
-
const
|
|
29
|
-
|
|
31
|
+
const result = [];
|
|
32
|
+
const extract = IS_WIN ? removeWmicPrefix : identity;
|
|
30
33
|
const callback = (err, { stdout }) => {
|
|
31
34
|
if (err) {
|
|
32
35
|
reject(err);
|
|
33
36
|
cb(err);
|
|
34
37
|
return;
|
|
35
38
|
}
|
|
36
|
-
result
|
|
39
|
+
result.push(...parseProcessList(extract(stdout), query));
|
|
37
40
|
resolve(result);
|
|
38
41
|
cb(null, result);
|
|
39
42
|
};
|
|
40
43
|
const ctx = IS_WIN ? {
|
|
41
|
-
cmd:
|
|
42
|
-
|
|
44
|
+
cmd: WMIC_INPUT,
|
|
45
|
+
args: [],
|
|
43
46
|
callback,
|
|
44
47
|
sync,
|
|
45
48
|
run(cb2) {
|
|
@@ -58,7 +61,7 @@ var _lookup = ({
|
|
|
58
61
|
return Object.assign(promise, result);
|
|
59
62
|
};
|
|
60
63
|
var parseProcessList = (output, query = {}) => {
|
|
61
|
-
const processList = parseGrid(output
|
|
64
|
+
const processList = parseGrid(output);
|
|
62
65
|
const pidList = (query.pid === void 0 ? [] : [query.pid].flat(1)).map((v) => v + "");
|
|
63
66
|
const filters = [
|
|
64
67
|
(p) => query.command ? new RegExp(query.command, "i").test(p.command) : true,
|
|
@@ -69,10 +72,10 @@ var parseProcessList = (output, query = {}) => {
|
|
|
69
72
|
(p) => (pidList.length === 0 || pidList.includes(p.pid)) && filters.every((f) => f(p))
|
|
70
73
|
);
|
|
71
74
|
};
|
|
72
|
-
var
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
return
|
|
75
|
+
var removeWmicPrefix = (stdout) => {
|
|
76
|
+
const s = stdout.indexOf(WMIC_INPUT + SystemEOL);
|
|
77
|
+
const e = stdout.includes(">") ? stdout.trimEnd().lastIndexOf(SystemEOL) : stdout.length;
|
|
78
|
+
return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trimStart();
|
|
76
79
|
};
|
|
77
80
|
var pickTree = (list, pid, recursive = false) => {
|
|
78
81
|
const children = list.filter((p) => p.ppid === pid + "");
|
|
@@ -168,7 +171,8 @@ var parseGrid = (output) => output ? formatOutput(parse(output, { format: IS_WIN
|
|
|
168
171
|
var formatOutput = (data) => data.reduce((m, d) => {
|
|
169
172
|
const pid = d.PID?.[0] || d.ProcessId?.[0];
|
|
170
173
|
const ppid = d.PPID?.[0] || d.ParentProcessId?.[0];
|
|
171
|
-
const
|
|
174
|
+
const _cmd = d.CMD || d.CommandLine || d.COMMAND || [];
|
|
175
|
+
const cmd = _cmd.length === 1 ? _cmd[0].split(/\s+/) : _cmd;
|
|
172
176
|
if (pid && cmd.length > 0) {
|
|
173
177
|
const c = cmd.findIndex((_v, i) => isBin(cmd.slice(0, i).join(" ")));
|
|
174
178
|
const command = cmd.slice(0, c).join(" ");
|