@lvce-editor/process-explorer 2.2.0 → 2.4.0

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.
Files changed (2) hide show
  1. package/dist/index.js +85 -113
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IpcChildWithWebSocket, IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithNodeWorker, IpcChildWithNodeForkedProcess } from '@lvce-editor/ipc';
2
- import { object, number as number$1, string } from '@lvce-editor/assert';
2
+ import { object, number, string } from '@lvce-editor/assert';
3
3
  import { VError } from '@lvce-editor/verror';
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { join } from 'node:path';
@@ -7,97 +7,32 @@ import { execFile as execFile$1 } from 'node:child_process';
7
7
  import { promisify } from 'node:util';
8
8
 
9
9
  const Two = '2.0';
10
- class AssertionError extends Error {
11
- constructor(message) {
12
- super(message);
13
- this.name = 'AssertionError';
14
- }
15
- }
16
- const getType = value => {
17
- switch (typeof value) {
18
- case 'number':
19
- return 'number';
20
- case 'function':
21
- return 'function';
22
- case 'string':
23
- return 'string';
24
- case 'object':
25
- if (value === null) {
26
- return 'null';
27
- }
28
- if (Array.isArray(value)) {
29
- return 'array';
30
- }
31
- return 'object';
32
- case 'boolean':
33
- return 'boolean';
34
- default:
35
- return 'unknown';
36
- }
37
- };
38
- const number = value => {
39
- const type = getType(value);
40
- if (type !== 'number') {
41
- throw new AssertionError('expected value to be of type number');
42
- }
43
- };
44
- const state$1$1 = {
45
- callbacks: Object.create(null)
46
- };
10
+ const callbacks = Object.create(null);
47
11
  const set = (id, fn) => {
48
- state$1$1.callbacks[id] = fn;
12
+ callbacks[id] = fn;
49
13
  };
50
14
  const get = id => {
51
- return state$1$1.callbacks[id];
15
+ return callbacks[id];
52
16
  };
53
17
  const remove = id => {
54
- delete state$1$1.callbacks[id];
55
- };
56
- const state$2 = {
57
- id: 0
18
+ delete callbacks[id];
58
19
  };
20
+ let id = 0;
59
21
  const create$3 = () => {
60
- return ++state$2.id;
61
- };
62
- const warn = (...args) => {
63
- console.warn(...args);
64
- };
65
- const withResolvers$1 = () => {
66
- /**
67
- * @type {any}
68
- */
69
- let _resolve;
70
- const promise = new Promise(resolve => {
71
- _resolve = resolve;
72
- });
73
- return {
74
- resolve: _resolve,
75
- promise
76
- };
22
+ return ++id;
77
23
  };
78
24
  const registerPromise = () => {
79
25
  const id = create$3();
80
26
  const {
81
27
  resolve,
82
28
  promise
83
- } = withResolvers$1();
29
+ } = Promise.withResolvers();
84
30
  set(id, resolve);
85
31
  return {
86
32
  id,
87
33
  promise
88
34
  };
89
35
  };
90
- const resolve = (id, args) => {
91
- number(id);
92
- const fn = get(id);
93
- if (!fn) {
94
- console.log(args);
95
- warn(`callback ${id} may already be disposed`);
96
- return;
97
- }
98
- fn(args);
99
- remove(id);
100
- };
101
36
  const create$2 = (method, params) => {
102
37
  const {
103
38
  id,
@@ -245,14 +180,29 @@ const unwrapJsonRpcResult = responseMessage => {
245
180
  }
246
181
  throw new JsonRpcError('unexpected response message');
247
182
  };
248
- const create$1 = (message, error) => {
249
- return {
250
- jsonrpc: Two,
251
- id: message.id,
252
- error
253
- };
183
+ const warn = (...args) => {
184
+ console.warn(...args);
185
+ };
186
+ const resolve = (id, response) => {
187
+ const fn = get(id);
188
+ if (!fn) {
189
+ console.log(response);
190
+ warn(`callback ${id} may already be disposed`);
191
+ return;
192
+ }
193
+ fn(response);
194
+ remove(id);
254
195
  };
255
196
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
197
+ const getErrorType = prettyError => {
198
+ if (prettyError && prettyError.type) {
199
+ return prettyError.type;
200
+ }
201
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
202
+ return prettyError.constructor.name;
203
+ }
204
+ return undefined;
205
+ };
256
206
  const getErrorProperty = (error, prettyError) => {
257
207
  if (error && error.code === E_COMMAND_NOT_FOUND) {
258
208
  return {
@@ -267,11 +217,19 @@ const getErrorProperty = (error, prettyError) => {
267
217
  data: {
268
218
  stack: prettyError.stack,
269
219
  codeFrame: prettyError.codeFrame,
270
- type: prettyError.type,
271
- code: prettyError.code
220
+ type: getErrorType(prettyError),
221
+ code: prettyError.code,
222
+ name: prettyError.name
272
223
  }
273
224
  };
274
225
  };
226
+ const create$1 = (message, error) => {
227
+ return {
228
+ jsonrpc: Two,
229
+ id: message.id,
230
+ error
231
+ };
232
+ };
275
233
  const getErrorResponse = (message, error, preparePrettyError, logError) => {
276
234
  const prettyError = preparePrettyError(error);
277
235
  logError(error, prettyError);
@@ -307,32 +265,42 @@ const defaultRequiresSocket = () => {
307
265
  return false;
308
266
  };
309
267
  const defaultResolve = resolve;
310
- const handleJsonRpcMessage = async (...args) => {
311
- let message;
312
- let ipc;
313
- let execute;
314
- let preparePrettyError;
315
- let logError;
316
- let resolve;
317
- let requiresSocket;
268
+
269
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
270
+ const normalizeParams = args => {
318
271
  if (args.length === 1) {
319
- const arg = args[0];
320
- message = arg.message;
321
- ipc = arg.ipc;
322
- execute = arg.execute;
323
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
324
- logError = arg.logError || defaultLogError;
325
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
326
- resolve = arg.resolve || defaultResolve;
327
- } else {
328
- ipc = args[0];
329
- message = args[1];
330
- execute = args[2];
331
- resolve = args[3];
332
- preparePrettyError = args[4];
333
- logError = args[5];
334
- requiresSocket = args[6];
272
+ const options = args[0];
273
+ return {
274
+ ipc: options.ipc,
275
+ message: options.message,
276
+ execute: options.execute,
277
+ resolve: options.resolve || defaultResolve,
278
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
279
+ logError: options.logError || defaultLogError,
280
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
281
+ };
335
282
  }
283
+ return {
284
+ ipc: args[0],
285
+ message: args[1],
286
+ execute: args[2],
287
+ resolve: args[3],
288
+ preparePrettyError: args[4],
289
+ logError: args[5],
290
+ requiresSocket: args[6]
291
+ };
292
+ };
293
+ const handleJsonRpcMessage = async (...args) => {
294
+ const options = normalizeParams(args);
295
+ const {
296
+ message,
297
+ ipc,
298
+ execute,
299
+ resolve,
300
+ preparePrettyError,
301
+ logError,
302
+ requiresSocket
303
+ } = options;
336
304
  if ('id' in message) {
337
305
  if ('method' in message) {
338
306
  const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
@@ -353,15 +321,19 @@ const handleJsonRpcMessage = async (...args) => {
353
321
  }
354
322
  throw new JsonRpcError('unexpected message');
355
323
  };
356
- const invoke$1 = async (ipc, method, ...params) => {
324
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
357
325
  const {
358
326
  message,
359
327
  promise
360
328
  } = create$2(method, params);
361
- ipc.send(message);
329
+ {
330
+ ipc.send(message);
331
+ }
362
332
  const responseMessage = await promise;
363
- const result = unwrapJsonRpcResult(responseMessage);
364
- return result;
333
+ return unwrapJsonRpcResult(responseMessage);
334
+ };
335
+ const invoke$1 = (ipc, method, ...params) => {
336
+ return invokeHelper(ipc, method, params);
365
337
  };
366
338
 
367
339
  const state$1 = {
@@ -525,9 +497,9 @@ const main = async () => {
525
497
  main();
526
498
 
527
499
  const getName = (pid, cmd, rootPid, pidMap) => {
528
- number$1(pid);
500
+ number(pid);
529
501
  string(cmd);
530
- number$1(rootPid);
502
+ number(rootPid);
531
503
  object(pidMap);
532
504
  if (pid === rootPid) {
533
505
  return 'main';
@@ -739,7 +711,7 @@ const getContent = async pid => {
739
711
  };
740
712
  const getAccurateMemoryUsage = async pid => {
741
713
  try {
742
- number$1(pid);
714
+ number(pid);
743
715
  if (isMacOs) {
744
716
  return 0;
745
717
  }
@@ -807,7 +779,7 @@ const parsePsOutputLine = line => {
807
779
  };
808
780
  const parsePsOutput = (stdout, rootPid, pidMap) => {
809
781
  string(stdout);
810
- number$1(rootPid);
782
+ number(rootPid);
811
783
  object(pidMap);
812
784
  if (stdout === EmptyString) {
813
785
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/process-explorer",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Process Explorer",
5
5
  "main": "dist/index.js",
6
6
  "bin": "bin/processExplorer.js",
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@lvce-editor/assert": "^1.3.0",
22
- "@lvce-editor/ipc": "^10.0.4",
23
- "@lvce-editor/json-rpc": "^3.0.0",
24
- "@lvce-editor/verror": "^1.4.0"
22
+ "@lvce-editor/ipc": "^13.7.0",
23
+ "@lvce-editor/json-rpc": "^5.4.0",
24
+ "@lvce-editor/verror": "^1.6.0"
25
25
  },
26
26
  "optionalDependencies": {
27
27
  "@vscode/windows-process-tree": "^0.6.0"