@webpod/ps 0.0.0-beta.4 → 0.0.0-beta.6

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.0.0-beta.4",
3
+ "version": "0.0.0-beta.6",
4
4
  "description": "A process lookup utility",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -53,7 +53,9 @@ __export(ts_exports, {
53
53
  default: () => ts_default,
54
54
  kill: () => kill,
55
55
  lookup: () => lookup,
56
- tree: () => tree
56
+ lookupSync: () => lookupSync,
57
+ tree: () => tree,
58
+ treeSync: () => treeSync
57
59
  });
58
60
  module.exports = __toCommonJS(ts_exports);
59
61
 
@@ -66,16 +68,15 @@ var import_spawn = require("zurk/spawn");
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
- return false;
71
- if (!f.includes("/"))
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
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;
79
80
  var _lookup = ({
80
81
  query = {},
81
82
  cb = noop,
@@ -151,9 +152,9 @@ var _tree = ({
151
152
  if (typeof opts === "string" || typeof opts === "number") {
152
153
  return _tree({ opts: { pid: opts }, cb, sync });
153
154
  }
154
- const handle = (all) => {
155
- if (opts === void 0)
156
- return all;
155
+ const onError = (err) => cb(err);
156
+ const onData = (all) => {
157
+ if (opts === void 0) return all;
157
158
  const { pid, recursive = false } = opts;
158
159
  const list = pickTree(all, pid, recursive);
159
160
  cb(null, list);
@@ -161,15 +162,20 @@ var _tree = ({
161
162
  };
162
163
  try {
163
164
  const all = _lookup({ sync });
164
- return sync ? handle(all) : all.then(handle);
165
+ return sync ? onData(all) : all.then(onData, (err) => {
166
+ onError(err);
167
+ throw err;
168
+ });
165
169
  } catch (err) {
166
- cb(err);
167
- throw err;
170
+ onError(err);
171
+ return Promise.reject(err);
168
172
  }
169
173
  };
170
174
  var tree = (opts, cb) => __async(void 0, null, function* () {
171
175
  return _tree({ opts, cb });
172
176
  });
177
+ var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
178
+ tree.sync = treeSync;
173
179
  var kill = (pid, opts, next) => {
174
180
  if (typeof opts == "function") {
175
181
  return kill(pid, void 0, opts);
@@ -193,8 +199,7 @@ var kill = (pid, opts, next) => {
193
199
  let checkTimeoutTimer;
194
200
  let checkIsTimeout = false;
195
201
  const checkKilled = (finishCallback) => lookup({ pid }, (err, list = []) => {
196
- if (checkIsTimeout)
197
- return;
202
+ if (checkIsTimeout) return;
198
203
  if (err) {
199
204
  clearTimeout(checkTimeoutTimer);
200
205
  reject(err);
@@ -266,10 +271,12 @@ var noop = () => {
266
271
  var identity = (v) => v;
267
272
 
268
273
  // src/main/ts/index.ts
269
- var ts_default = { lookup, kill, tree };
274
+ var ts_default = { kill, lookup, lookupSync, tree, treeSync };
270
275
  // Annotate the CommonJS export names for ESM import in node:
271
276
  0 && (module.exports = {
272
277
  kill,
273
278
  lookup,
274
- tree
279
+ lookupSync,
280
+ tree,
281
+ treeSync
275
282
  });
@@ -1,8 +1,16 @@
1
1
  export type * from './ps.js';
2
- export { kill, lookup, tree } from './ps.js';
2
+ export { kill, lookup, lookupSync, tree, treeSync } from './ps.js';
3
3
  declare const _default: {
4
- lookup: (query?: import("./ps.js").TPsLookupQuery, cb?: import("./ps.js").TPsLookupCallback) => Promise<import("./ps.js").TPsLookupEntry[]>;
5
4
  kill: (pid: string | number, opts?: string | number | import("./ps.js").TPsKillOptions | import("./ps.js").TPsNext | undefined, next?: import("./ps.js").TPsNext | undefined) => Promise<void>;
6
- tree: (opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback | undefined) => Promise<import("./ps.js").TPsLookupEntry[]>;
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 | undefined): Promise<import("./ps.js").TPsLookupEntry[]>;
12
+ sync: (opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback | undefined) => import("./ps.js").TPsLookupEntry[];
13
+ };
14
+ treeSync: (opts?: string | number | import("./ps.js").TPsTreeOpts | undefined, cb?: import("./ps.js").TPsLookupCallback | undefined) => import("./ps.js").TPsLookupEntry[];
7
15
  };
8
16
  export default _default;
@@ -31,7 +31,10 @@ export type TPsNext = (err?: any, data?: any) => void;
31
31
  * @param {TPsLookupEntry[]} cb.processList
32
32
  * @return {Promise<TPsLookupEntry[]>}
33
33
  */
34
- export declare const lookup: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => Promise<TPsLookupEntry[]>;
34
+ export declare const lookup: {
35
+ (query?: TPsLookupQuery, cb?: TPsLookupCallback): Promise<TPsLookupEntry[]>;
36
+ sync: (query?: TPsLookupQuery, cb?: TPsLookupCallback) => TPsLookupEntry[];
37
+ };
35
38
  /**
36
39
  * Looks up the process list synchronously
37
40
  * @param query
@@ -52,7 +55,10 @@ export type TPsTreeOpts = {
52
55
  recursive?: boolean;
53
56
  };
54
57
  export declare const pickTree: (list: TPsLookupEntry[], pid: string | number, recursive?: boolean) => TPsLookupEntry[];
55
- export declare const tree: (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback) => Promise<TPsLookupEntry[]>;
58
+ export declare const tree: {
59
+ (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback): Promise<TPsLookupEntry[]>;
60
+ sync: (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback) => TPsLookupEntry[];
61
+ };
56
62
  export declare const treeSync: (opts?: string | number | TPsTreeOpts | undefined, cb?: TPsLookupCallback) => TPsLookupEntry[];
57
63
  /**
58
64
  * Kill process
@@ -7,16 +7,15 @@ import { exec } from "zurk/spawn";
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
- return false;
12
- if (!f.includes("/"))
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
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;
20
19
  var _lookup = ({
21
20
  query = {},
22
21
  cb = noop,
@@ -92,9 +91,9 @@ var _tree = ({
92
91
  if (typeof opts === "string" || typeof opts === "number") {
93
92
  return _tree({ opts: { pid: opts }, cb, sync });
94
93
  }
95
- const handle = (all) => {
96
- if (opts === void 0)
97
- return all;
94
+ const onError = (err) => cb(err);
95
+ const onData = (all) => {
96
+ if (opts === void 0) return all;
98
97
  const { pid, recursive = false } = opts;
99
98
  const list = pickTree(all, pid, recursive);
100
99
  cb(null, list);
@@ -102,13 +101,18 @@ var _tree = ({
102
101
  };
103
102
  try {
104
103
  const all = _lookup({ sync });
105
- return sync ? handle(all) : all.then(handle);
104
+ return sync ? onData(all) : all.then(onData, (err) => {
105
+ onError(err);
106
+ throw err;
107
+ });
106
108
  } catch (err) {
107
- cb(err);
108
- throw err;
109
+ onError(err);
110
+ return Promise.reject(err);
109
111
  }
110
112
  };
111
113
  var tree = async (opts, cb) => _tree({ opts, cb });
114
+ var treeSync = (opts, cb) => _tree({ opts, cb, sync: true });
115
+ tree.sync = treeSync;
112
116
  var kill = (pid, opts, next) => {
113
117
  if (typeof opts == "function") {
114
118
  return kill(pid, void 0, opts);
@@ -132,8 +136,7 @@ var kill = (pid, opts, next) => {
132
136
  let checkTimeoutTimer;
133
137
  let checkIsTimeout = false;
134
138
  const checkKilled = (finishCallback) => lookup({ pid }, (err, list = []) => {
135
- if (checkIsTimeout)
136
- return;
139
+ if (checkIsTimeout) return;
137
140
  if (err) {
138
141
  clearTimeout(checkTimeoutTimer);
139
142
  reject(err);
@@ -204,10 +207,12 @@ var noop = () => {
204
207
  var identity = (v) => v;
205
208
 
206
209
  // src/main/ts/index.ts
207
- var ts_default = { lookup, kill, tree };
210
+ var ts_default = { kill, lookup, lookupSync, tree, treeSync };
208
211
  export {
209
212
  ts_default as default,
210
213
  kill,
211
214
  lookup,
212
- tree
215
+ lookupSync,
216
+ tree,
217
+ treeSync
213
218
  };