@webpod/ps 0.1.0 → 0.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpod/ps",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A process lookup utility",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -41,15 +41,15 @@
41
41
  "pid"
42
42
  ],
43
43
  "dependencies": {
44
- "@webpod/ingrid": "^0.0.0-beta.3",
45
- "zurk": "^0.10.2"
44
+ "@webpod/ingrid": "^1.0.0",
45
+ "zurk": "^0.11.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^22.12.0",
48
+ "@types/node": "^24.0.4",
49
49
  "c8": "^10.1.3",
50
- "concurrently": "^9.1.2",
51
- "esbuild": "^0.24.2",
52
- "esbuild-node-externals": "^1.16.0",
50
+ "concurrently": "^9.2.0",
51
+ "esbuild": "^0.25.5",
52
+ "esbuild-node-externals": "^1.18.0",
53
53
  "esbuild-plugin-entry-chunks": "^0.1.15",
54
54
  "eslint": "^8.57.0",
55
55
  "eslint-config-qiwi": "^2.1.3",
@@ -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.27.6",
62
- "typescript": "^5.7.3"
61
+ "typedoc": "^0.28.6",
62
+ "typescript": "^5.8.3"
63
63
  },
64
64
  "repository": {
65
65
  "type": "git",
@@ -65,8 +65,8 @@ 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" + import_node_os.EOL;
70
70
  var isBin = (f) => {
71
71
  if (f === "") return false;
72
72
  if (!f.includes("/")) return true;
@@ -86,21 +86,21 @@ var _lookup = ({
86
86
  const { promise, resolve, reject } = pFactory();
87
87
  const { psargs = ["-lx"] } = query;
88
88
  const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
89
- const extract = IS_WIN ? extractWmic : identity;
90
- let result = [];
89
+ const result = [];
90
+ const extract = IS_WIN ? removeWmicPrefix : identity;
91
91
  const callback = (err, { stdout }) => {
92
92
  if (err) {
93
93
  reject(err);
94
94
  cb(err);
95
95
  return;
96
96
  }
97
- result = parseProcessList(extract(stdout), query);
97
+ result.push(...parseProcessList(extract(stdout), query));
98
98
  resolve(result);
99
99
  cb(null, result);
100
100
  };
101
101
  const ctx = IS_WIN ? {
102
102
  cmd: "cmd",
103
- input: "wmic process get ProcessId,ParentProcessId,CommandLine \n",
103
+ input: `wmic process get ProcessId,ParentProcessId,CommandLine${import_node_os.EOL}`,
104
104
  callback,
105
105
  sync,
106
106
  run(cb2) {
@@ -130,10 +130,10 @@ var parseProcessList = (output, query = {}) => {
130
130
  (p) => (pidList.length === 0 || pidList.includes(p.pid)) && filters.every((f) => f(p))
131
131
  );
132
132
  };
133
- var extractWmic = (stdout) => {
134
- const _stdout = stdout.split(EOL);
135
- const beginRow = _stdout.findIndex((out) => out.startsWith("CommandLine"));
136
- return _stdout.slice(beginRow + 1, -1).join(import_node_os.EOL);
133
+ var removeWmicPrefix = (stdout) => {
134
+ const s = stdout.indexOf(WMIC_INPUT);
135
+ const e = stdout.lastIndexOf(import_node_os.EOL);
136
+ return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trim();
137
137
  };
138
138
  var pickTree = (list, pid, recursive = false) => {
139
139
  const children = list.filter((p) => p.ppid === pid + "");
@@ -169,7 +169,7 @@ var _tree = ({
169
169
  return Promise.reject(err);
170
170
  }
171
171
  };
172
- var tree = (opts, cb) => __async(void 0, null, function* () {
172
+ var tree = (opts, cb) => __async(null, null, function* () {
173
173
  return _tree({ opts, cb });
174
174
  });
175
175
  var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
@@ -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 {Function} [cb]
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 {Function} [cb]
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 extractWmic: (stdout: string) => string;
47
+ export declare const removeWmicPrefix: (stdout: string) => string;
52
48
  export type TPsTreeOpts = {
53
49
  pid: string | number;
54
50
  recursive?: boolean;
@@ -4,8 +4,8 @@ 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" + SystemEOL;
9
9
  var isBin = (f) => {
10
10
  if (f === "") return false;
11
11
  if (!f.includes("/")) return true;
@@ -25,21 +25,21 @@ var _lookup = ({
25
25
  const { promise, resolve, reject } = pFactory();
26
26
  const { psargs = ["-lx"] } = query;
27
27
  const args = Array.isArray(psargs) ? psargs : psargs.split(/\s+/);
28
- const extract = IS_WIN ? extractWmic : identity;
29
- let result = [];
28
+ const result = [];
29
+ const extract = IS_WIN ? removeWmicPrefix : identity;
30
30
  const callback = (err, { stdout }) => {
31
31
  if (err) {
32
32
  reject(err);
33
33
  cb(err);
34
34
  return;
35
35
  }
36
- result = parseProcessList(extract(stdout), query);
36
+ result.push(...parseProcessList(extract(stdout), query));
37
37
  resolve(result);
38
38
  cb(null, result);
39
39
  };
40
40
  const ctx = IS_WIN ? {
41
41
  cmd: "cmd",
42
- input: "wmic process get ProcessId,ParentProcessId,CommandLine \n",
42
+ input: `wmic process get ProcessId,ParentProcessId,CommandLine${SystemEOL}`,
43
43
  callback,
44
44
  sync,
45
45
  run(cb2) {
@@ -69,10 +69,10 @@ var parseProcessList = (output, query = {}) => {
69
69
  (p) => (pidList.length === 0 || pidList.includes(p.pid)) && filters.every((f) => f(p))
70
70
  );
71
71
  };
72
- var extractWmic = (stdout) => {
73
- const _stdout = stdout.split(EOL);
74
- const beginRow = _stdout.findIndex((out) => out.startsWith("CommandLine"));
75
- return _stdout.slice(beginRow + 1, -1).join(SystemEOL);
72
+ var removeWmicPrefix = (stdout) => {
73
+ const s = stdout.indexOf(WMIC_INPUT);
74
+ const e = stdout.lastIndexOf(SystemEOL);
75
+ return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trim();
76
76
  };
77
77
  var pickTree = (list, pid, recursive = false) => {
78
78
  const children = list.filter((p) => p.ppid === pid + "");