@webpod/ps 0.1.2 → 0.1.4

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.2",
3
+ "version": "0.1.4",
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": "^1.0.0",
45
- "zurk": "^0.11.3"
44
+ "@webpod/ingrid": "^1.1.1",
45
+ "zurk": "^0.11.4"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^24.0.4",
48
+ "@types/node": "^24.0.13",
49
49
  "c8": "^10.1.3",
50
50
  "concurrently": "^9.2.0",
51
- "esbuild": "^0.25.5",
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,7 +58,7 @@
58
58
  "mocha": "^10.8.2",
59
59
  "sinon": "^18.0.1",
60
60
  "ts-node": "^10.9.2",
61
- "typedoc": "^0.28.6",
61
+ "typedoc": "^0.28.7",
62
62
  "typescript": "^5.8.3"
63
63
  },
64
64
  "repository": {
@@ -66,13 +66,19 @@ var import_node_os = require("node:os");
66
66
  var import_ingrid = require("@webpod/ingrid");
67
67
  var import_spawn = require("zurk/spawn");
68
68
  var IS_WIN = import_node_process.default.platform === "win32";
69
- var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine" + import_node_os.EOL;
69
+ var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine";
70
70
  var isBin = (f) => {
71
71
  if (f === "") return false;
72
- if (!f.includes("/")) return true;
73
- if (!import_node_fs.default.existsSync(f)) return false;
74
- const stat = import_node_fs.default.lstatSync(f);
75
- return stat.isFile() || stat.isSymbolicLink();
72
+ if (!f.includes("/") && !f.includes("\\")) return true;
73
+ if (f.length > 3 && f[0] === '"')
74
+ return f[f.length - 1] === '"' ? isBin(f.slice(1, -1)) : false;
75
+ try {
76
+ if (!import_node_fs.default.existsSync(f)) return false;
77
+ const stat = import_node_fs.default.lstatSync(f);
78
+ return stat.isFile() || stat.isSymbolicLink();
79
+ } catch (e) {
80
+ return false;
81
+ }
76
82
  };
77
83
  var lookup = (query = {}, cb = noop) => _lookup({ query, cb, sync: false });
78
84
  var lookupSync = (query = {}, cb = noop) => _lookup({ query, cb, sync: true });
@@ -99,8 +105,8 @@ var _lookup = ({
99
105
  cb(null, result);
100
106
  };
101
107
  const ctx = IS_WIN ? {
102
- cmd: "cmd",
103
- input: `wmic process get ProcessId,ParentProcessId,CommandLine${import_node_os.EOL}`,
108
+ cmd: WMIC_INPUT,
109
+ args: [],
104
110
  callback,
105
111
  sync,
106
112
  run(cb2) {
@@ -119,7 +125,7 @@ var _lookup = ({
119
125
  return Object.assign(promise, result);
120
126
  };
121
127
  var parseProcessList = (output, query = {}) => {
122
- const processList = parseGrid(output.trim());
128
+ const processList = parseGrid(output);
123
129
  const pidList = (query.pid === void 0 ? [] : [query.pid].flat(1)).map((v) => v + "");
124
130
  const filters = [
125
131
  (p) => query.command ? new RegExp(query.command, "i").test(p.command) : true,
@@ -131,9 +137,9 @@ var parseProcessList = (output, query = {}) => {
131
137
  );
132
138
  };
133
139
  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();
140
+ const s = stdout.indexOf(WMIC_INPUT + import_node_os.EOL);
141
+ const e = stdout.includes(">") ? stdout.trimEnd().lastIndexOf(import_node_os.EOL) : stdout.length;
142
+ return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trimStart();
137
143
  };
138
144
  var pickTree = (list, pid, recursive = false) => {
139
145
  const children = list.filter((p) => p.ppid === pid + "");
@@ -232,11 +238,12 @@ var formatOutput = (data) => data.reduce((m, d) => {
232
238
  var _a, _b, _c, _d;
233
239
  const pid = ((_a = d.PID) == null ? void 0 : _a[0]) || ((_b = d.ProcessId) == null ? void 0 : _b[0]);
234
240
  const ppid = ((_c = d.PPID) == null ? void 0 : _c[0]) || ((_d = d.ParentProcessId) == null ? void 0 : _d[0]);
235
- const cmd = d.CMD || d.CommandLine || d.COMMAND || [];
241
+ const _cmd = d.CMD || d.CommandLine || d.COMMAND || [];
242
+ const cmd = _cmd.length === 1 ? _cmd[0].split(/\s+/) : _cmd;
236
243
  if (pid && cmd.length > 0) {
237
244
  const c = cmd.findIndex((_v, i) => isBin(cmd.slice(0, i).join(" ")));
238
- const command = cmd.slice(0, c).join(" ");
239
- const args = cmd.length > 1 ? cmd.slice(c) : [];
245
+ const command = (c === -1 ? cmd : cmd.slice(0, c)).join(" ");
246
+ const args = c === -1 ? [] : cmd.slice(c);
240
247
  m.push({
241
248
  pid,
242
249
  ppid,
@@ -5,13 +5,19 @@ import { EOL as SystemEOL } from "node:os";
5
5
  import { parse } from "@webpod/ingrid";
6
6
  import { exec } from "zurk/spawn";
7
7
  var IS_WIN = process.platform === "win32";
8
- var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine" + SystemEOL;
8
+ var WMIC_INPUT = "wmic process get ProcessId,ParentProcessId,CommandLine";
9
9
  var isBin = (f) => {
10
10
  if (f === "") return false;
11
- if (!f.includes("/")) return true;
12
- if (!fs.existsSync(f)) return false;
13
- const stat = fs.lstatSync(f);
14
- return stat.isFile() || stat.isSymbolicLink();
11
+ if (!f.includes("/") && !f.includes("\\")) return true;
12
+ if (f.length > 3 && f[0] === '"')
13
+ return f[f.length - 1] === '"' ? isBin(f.slice(1, -1)) : false;
14
+ try {
15
+ if (!fs.existsSync(f)) return false;
16
+ const stat = fs.lstatSync(f);
17
+ return stat.isFile() || stat.isSymbolicLink();
18
+ } catch {
19
+ return false;
20
+ }
15
21
  };
16
22
  var lookup = (query = {}, cb = noop) => _lookup({ query, cb, sync: false });
17
23
  var lookupSync = (query = {}, cb = noop) => _lookup({ query, cb, sync: true });
@@ -38,8 +44,8 @@ var _lookup = ({
38
44
  cb(null, result);
39
45
  };
40
46
  const ctx = IS_WIN ? {
41
- cmd: "cmd",
42
- input: `wmic process get ProcessId,ParentProcessId,CommandLine${SystemEOL}`,
47
+ cmd: WMIC_INPUT,
48
+ args: [],
43
49
  callback,
44
50
  sync,
45
51
  run(cb2) {
@@ -58,7 +64,7 @@ var _lookup = ({
58
64
  return Object.assign(promise, result);
59
65
  };
60
66
  var parseProcessList = (output, query = {}) => {
61
- const processList = parseGrid(output.trim());
67
+ const processList = parseGrid(output);
62
68
  const pidList = (query.pid === void 0 ? [] : [query.pid].flat(1)).map((v) => v + "");
63
69
  const filters = [
64
70
  (p) => query.command ? new RegExp(query.command, "i").test(p.command) : true,
@@ -70,9 +76,9 @@ var parseProcessList = (output, query = {}) => {
70
76
  );
71
77
  };
72
78
  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();
79
+ const s = stdout.indexOf(WMIC_INPUT + SystemEOL);
80
+ const e = stdout.includes(">") ? stdout.trimEnd().lastIndexOf(SystemEOL) : stdout.length;
81
+ return (s > 0 ? stdout.slice(s + WMIC_INPUT.length, e) : stdout.slice(0, e)).trimStart();
76
82
  };
77
83
  var pickTree = (list, pid, recursive = false) => {
78
84
  const children = list.filter((p) => p.ppid === pid + "");
@@ -168,11 +174,12 @@ var parseGrid = (output) => output ? formatOutput(parse(output, { format: IS_WIN
168
174
  var formatOutput = (data) => data.reduce((m, d) => {
169
175
  const pid = d.PID?.[0] || d.ProcessId?.[0];
170
176
  const ppid = d.PPID?.[0] || d.ParentProcessId?.[0];
171
- const cmd = d.CMD || d.CommandLine || d.COMMAND || [];
177
+ const _cmd = d.CMD || d.CommandLine || d.COMMAND || [];
178
+ const cmd = _cmd.length === 1 ? _cmd[0].split(/\s+/) : _cmd;
172
179
  if (pid && cmd.length > 0) {
173
180
  const c = cmd.findIndex((_v, i) => isBin(cmd.slice(0, i).join(" ")));
174
- const command = cmd.slice(0, c).join(" ");
175
- const args = cmd.length > 1 ? cmd.slice(c) : [];
181
+ const command = (c === -1 ? cmd : cmd.slice(0, c)).join(" ");
182
+ const args = c === -1 ? [] : cmd.slice(c);
176
183
  m.push({
177
184
  pid,
178
185
  ppid,