@webpod/ps 0.1.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpod/ps",
3
- "version": "0.1.2",
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": "^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,10 +66,13 @@ 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
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();
@@ -99,8 +102,8 @@ var _lookup = ({
99
102
  cb(null, result);
100
103
  };
101
104
  const ctx = IS_WIN ? {
102
- cmd: "cmd",
103
- input: `wmic process get ProcessId,ParentProcessId,CommandLine${import_node_os.EOL}`,
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.trim());
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,
@@ -131,9 +134,9 @@ var parseProcessList = (output, query = {}) => {
131
134
  );
132
135
  };
133
136
  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
+ 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 + "");
@@ -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 cmd = d.CMD || d.CommandLine || d.COMMAND || [];
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(" ");
@@ -5,10 +5,13 @@ 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
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();
@@ -38,8 +41,8 @@ var _lookup = ({
38
41
  cb(null, result);
39
42
  };
40
43
  const ctx = IS_WIN ? {
41
- cmd: "cmd",
42
- input: `wmic process get ProcessId,ParentProcessId,CommandLine${SystemEOL}`,
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.trim());
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,
@@ -70,9 +73,9 @@ var parseProcessList = (output, query = {}) => {
70
73
  );
71
74
  };
72
75
  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
+ 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 cmd = d.CMD || d.CommandLine || d.COMMAND || [];
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(" ");