@lvce-editor/process-explorer 2.0.0 → 2.2.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 +135 -182
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -7,7 +7,6 @@ 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
-
11
10
  class AssertionError extends Error {
12
11
  constructor(message) {
13
12
  super(message);
@@ -42,7 +41,6 @@ const number = value => {
42
41
  throw new AssertionError('expected value to be of type number');
43
42
  }
44
43
  };
45
-
46
44
  const state$1$1 = {
47
45
  callbacks: Object.create(null)
48
46
  };
@@ -55,18 +53,15 @@ const get = id => {
55
53
  const remove = id => {
56
54
  delete state$1$1.callbacks[id];
57
55
  };
58
-
59
56
  const state$2 = {
60
57
  id: 0
61
58
  };
62
59
  const create$3 = () => {
63
60
  return ++state$2.id;
64
61
  };
65
-
66
62
  const warn = (...args) => {
67
63
  console.warn(...args);
68
64
  };
69
-
70
65
  const withResolvers$1 = () => {
71
66
  /**
72
67
  * @type {any}
@@ -80,7 +75,6 @@ const withResolvers$1 = () => {
80
75
  promise
81
76
  };
82
77
  };
83
-
84
78
  const registerPromise = () => {
85
79
  const id = create$3();
86
80
  const {
@@ -104,7 +98,6 @@ const resolve = (id, args) => {
104
98
  fn(args);
105
99
  remove(id);
106
100
  };
107
-
108
101
  const create$2 = (method, params) => {
109
102
  const {
110
103
  id,
@@ -121,21 +114,17 @@ const create$2 = (method, params) => {
121
114
  promise
122
115
  };
123
116
  };
124
-
125
117
  class JsonRpcError extends Error {
126
118
  constructor(message) {
127
119
  super(message);
128
120
  this.name = 'JsonRpcError';
129
121
  }
130
122
  }
131
-
132
123
  const NewLine$1 = '\n';
133
-
134
124
  const DomException = 'DOMException';
135
125
  const ReferenceError$1 = 'ReferenceError';
136
126
  const SyntaxError$1 = 'SyntaxError';
137
127
  const TypeError$1 = 'TypeError';
138
-
139
128
  const getErrorConstructor = (message, type) => {
140
129
  if (type) {
141
130
  switch (type) {
@@ -162,7 +151,6 @@ const getErrorConstructor = (message, type) => {
162
151
  }
163
152
  return Error;
164
153
  };
165
-
166
154
  const constructError = (message, type, name) => {
167
155
  const ErrorConstructor = getErrorConstructor(message, type);
168
156
  if (ErrorConstructor === DOMException && name) {
@@ -177,11 +165,9 @@ const constructError = (message, type, name) => {
177
165
  }
178
166
  return new ErrorConstructor(message);
179
167
  };
180
-
181
168
  const getNewLineIndex = (string, startIndex = undefined) => {
182
169
  return string.indexOf(NewLine$1, startIndex);
183
170
  };
184
-
185
171
  const getParentStack = error => {
186
172
  let parentStack = error.stack || error.data || error.message || '';
187
173
  if (parentStack.startsWith(' at')) {
@@ -189,18 +175,14 @@ const getParentStack = error => {
189
175
  }
190
176
  return parentStack;
191
177
  };
192
-
193
178
  const joinLines = lines => {
194
179
  return lines.join(NewLine$1);
195
180
  };
196
-
197
181
  const MethodNotFound = -32601;
198
182
  const Custom = -32001;
199
-
200
183
  const splitLines$1 = lines => {
201
184
  return lines.split(NewLine$1);
202
185
  };
203
-
204
186
  const restoreJsonRpcError = error => {
205
187
  if (error && error instanceof Error) {
206
188
  return error;
@@ -253,7 +235,6 @@ const restoreJsonRpcError = error => {
253
235
  }
254
236
  return new Error(`JsonRpc Error: ${error}`);
255
237
  };
256
-
257
238
  const unwrapJsonRpcResult = responseMessage => {
258
239
  if ('error' in responseMessage) {
259
240
  const restoredError = restoreJsonRpcError(responseMessage.error);
@@ -264,7 +245,6 @@ const unwrapJsonRpcResult = responseMessage => {
264
245
  }
265
246
  throw new JsonRpcError('unexpected response message');
266
247
  };
267
-
268
248
  const create$1 = (message, error) => {
269
249
  return {
270
250
  jsonrpc: Two,
@@ -272,9 +252,7 @@ const create$1 = (message, error) => {
272
252
  error
273
253
  };
274
254
  };
275
-
276
255
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
277
-
278
256
  const getErrorProperty = (error, prettyError) => {
279
257
  if (error && error.code === E_COMMAND_NOT_FOUND) {
280
258
  return {
@@ -300,7 +278,6 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
300
278
  const errorProperty = getErrorProperty(error, prettyError);
301
279
  return create$1(message, errorProperty);
302
280
  };
303
-
304
281
  const create = (message, result) => {
305
282
  return {
306
283
  jsonrpc: Two,
@@ -308,12 +285,10 @@ const create = (message, result) => {
308
285
  result: result ?? null
309
286
  };
310
287
  };
311
-
312
288
  const getSuccessResponse = (message, result) => {
313
289
  const resultProperty = result ?? null;
314
290
  return create(message, resultProperty);
315
291
  };
316
-
317
292
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
318
293
  try {
319
294
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
@@ -322,7 +297,6 @@ const getResponse = async (message, ipc, execute, preparePrettyError, logError,
322
297
  return getErrorResponse(message, error, preparePrettyError, logError);
323
298
  }
324
299
  };
325
-
326
300
  const defaultPreparePrettyError = error => {
327
301
  return error;
328
302
  };
@@ -391,48 +365,42 @@ const invoke$1 = async (ipc, method, ...params) => {
391
365
  };
392
366
 
393
367
  const state$1 = {
394
- commands: Object.create(null),
368
+ commands: Object.create(null)
395
369
  };
396
-
397
370
  const registerCommand = (key, fn) => {
398
371
  state$1.commands[key] = fn;
399
372
  };
400
-
401
- const registerCommands = (commandMap) => {
373
+ const registerCommands = commandMap => {
402
374
  for (const [key, value] of Object.entries(commandMap)) {
403
375
  registerCommand(key, value);
404
376
  }
405
377
  };
406
-
407
- const getCommand = (key) => {
408
- return state$1.commands[key]
378
+ const getCommand = key => {
379
+ return state$1.commands[key];
409
380
  };
410
381
 
411
382
  const execute = (command, ...args) => {
412
383
  const fn = getCommand(command);
413
384
  if (!fn) {
414
- throw new Error(`Command not found ${command}`)
385
+ throw new Error(`Command not found ${command}`);
415
386
  }
416
- return fn(...args)
387
+ return fn(...args);
417
388
  };
418
389
 
419
- const preparePrettyError = (error) => {
420
- return error
390
+ const preparePrettyError = error => {
391
+ return error;
421
392
  };
422
-
423
- const logError = (error) => {
393
+ const logError = error => {
424
394
  console.error(error);
425
395
  };
426
-
427
396
  const requiresSocket = () => {
428
- return false
397
+ return false;
429
398
  };
430
-
431
- const handleMessage = (event) => {
432
- return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket)
399
+ const handleMessage = event => {
400
+ return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
433
401
  };
434
402
 
435
- const handleIpc = (ipc) => {
403
+ const handleIpc = ipc => {
436
404
  if ('addEventListener' in ipc) {
437
405
  ipc.addEventListener('message', handleMessage);
438
406
  } else {
@@ -446,39 +414,43 @@ const NodeForkedProcess = 2;
446
414
  const ElectronUtilityProcess = 3;
447
415
  const ElectronMessagePort = 4;
448
416
  const WebSocket = 6;
449
-
450
417
  const Auto = () => {
451
- const { argv } = process;
418
+ const {
419
+ argv
420
+ } = process;
452
421
  if (argv.includes('--ipc-type=node-worker')) {
453
- return NodeWorker
422
+ return NodeWorker;
454
423
  }
455
424
  if (argv.includes('--ipc-type=node-forked-process')) {
456
- return NodeForkedProcess
425
+ return NodeForkedProcess;
457
426
  }
458
427
  if (argv.includes('--ipc-type=electron-utility-process')) {
459
- return ElectronUtilityProcess
428
+ return ElectronUtilityProcess;
460
429
  }
461
- throw new Error(`[shared-process] unknown ipc type`)
430
+ throw new Error(`[shared-process] unknown ipc type`);
462
431
  };
463
432
 
464
- const getModule$1 = (method) => {
433
+ const getModule$1 = method => {
465
434
  switch (method) {
466
435
  case NodeForkedProcess:
467
- return IpcChildWithNodeForkedProcess
436
+ return IpcChildWithNodeForkedProcess;
468
437
  case NodeWorker:
469
- return IpcChildWithNodeWorker
438
+ return IpcChildWithNodeWorker;
470
439
  case ElectronUtilityProcess:
471
- return IpcChildWithElectronUtilityProcess
440
+ return IpcChildWithElectronUtilityProcess;
472
441
  case ElectronMessagePort:
473
- return IpcChildWithElectronMessagePort
442
+ return IpcChildWithElectronMessagePort;
474
443
  case WebSocket:
475
- return IpcChildWithWebSocket
444
+ return IpcChildWithWebSocket;
476
445
  default:
477
- throw new Error('unexpected ipc type')
446
+ throw new Error('unexpected ipc type');
478
447
  }
479
448
  };
480
449
 
481
- const listen$1 = async ({ method, ...params }) => {
450
+ const listen$1 = async ({
451
+ method,
452
+ ...params
453
+ }) => {
482
454
  const module = await getModule$1(method);
483
455
  // @ts-ignore
484
456
  const rawIpc = await module.listen(params);
@@ -489,25 +461,23 @@ const listen$1 = async ({ method, ...params }) => {
489
461
  }
490
462
  // @ts-ignore
491
463
  const ipc = module.wrap(rawIpc);
492
- return ipc
464
+ return ipc;
493
465
  };
494
466
 
495
467
  const listen = async () => {
496
- const ipc = await listen$1({ method: Auto() });
468
+ const ipc = await listen$1({
469
+ method: Auto()
470
+ });
497
471
  handleIpc(ipc);
498
472
  };
499
473
 
500
474
  const MainProcess = -5;
501
475
 
502
476
  const state = {
503
- /**
504
- * @type {any}
505
- */
506
- ipc: undefined,
477
+ ipc: undefined
507
478
  };
508
-
509
479
  const invoke = (method, ...params) => {
510
- return invoke$1(state.ipc, method, ...params)
480
+ return invoke$1(state.ipc, method, ...params);
511
481
  };
512
482
 
513
483
  const handleElectronMessagePort = async (messagePort, ipcId) => {
@@ -515,7 +485,7 @@ const handleElectronMessagePort = async (messagePort, ipcId) => {
515
485
  // Assert.number(ipcId)
516
486
  const ipc = await listen$1({
517
487
  method: ElectronMessagePort,
518
- messagePort,
488
+ messagePort
519
489
  });
520
490
  handleIpc(ipc);
521
491
  if (ipcId === MainProcess) {
@@ -524,27 +494,26 @@ const handleElectronMessagePort = async (messagePort, ipcId) => {
524
494
  };
525
495
 
526
496
  const getMainProcessId = () => {
527
- return process.ppid
497
+ return process.ppid;
528
498
  };
529
499
 
530
500
  const isWindows = process.platform === 'win32';
531
501
 
532
502
  const getModule = () => {
533
503
  if (isWindows) {
534
- return Promise.resolve().then(function () { return ListProcessesWithMemoryUsageWindows; })
504
+ return Promise.resolve().then(function () { return ListProcessesWithMemoryUsageWindows; });
535
505
  }
536
- return Promise.resolve().then(function () { return ListProcessesWithMemoryUsageUnix; })
506
+ return Promise.resolve().then(function () { return ListProcessesWithMemoryUsageUnix; });
537
507
  };
538
-
539
- const listProcessesWithMemoryUsage$2 = async (rootPid) => {
508
+ const listProcessesWithMemoryUsage$2 = async rootPid => {
540
509
  const module = await getModule();
541
- return module.listProcessesWithMemoryUsage(rootPid)
510
+ return module.listProcessesWithMemoryUsage(rootPid);
542
511
  };
543
512
 
544
513
  const commandMap = {
545
514
  'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
546
515
  'ProcessId.getMainProcessId': getMainProcessId,
547
- 'ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage': listProcessesWithMemoryUsage$2,
516
+ 'ListProcessesWithMemoryUsage.listProcessesWithMemoryUsage': listProcessesWithMemoryUsage$2
548
517
  // 'ElectronContextMenu.openContextMenu': ElectronWebContentsView.handleContextMenu,
549
518
  };
550
519
 
@@ -561,74 +530,72 @@ const getName = (pid, cmd, rootPid, pidMap) => {
561
530
  number$1(rootPid);
562
531
  object(pidMap);
563
532
  if (pid === rootPid) {
564
- return 'main'
533
+ return 'main';
565
534
  }
566
535
  if (cmd.includes('--type=zygote')) {
567
- return 'zygote'
536
+ return 'zygote';
568
537
  }
569
538
  if (cmd.includes('--type=gpu-process')) {
570
- return 'gpu-process'
539
+ return 'gpu-process';
571
540
  }
572
541
  if (cmd.includes('extensionHostMain.js')) {
573
- return 'extension-host'
542
+ return 'extension-host';
574
543
  }
575
544
  if (cmd.includes('ptyHostMain.js')) {
576
- return 'pty-host'
545
+ return 'pty-host';
577
546
  }
578
547
  if (cmd.includes('--lvce-window-kind=process-explorer')) {
579
- return 'process-explorer'
548
+ return 'process-explorer';
580
549
  }
581
550
  if (pid in pidMap) {
582
- return pidMap[pid] || `<unknown>`
551
+ return pidMap[pid] || `<unknown>`;
583
552
  }
584
553
  if (cmd.includes('--type=renderer')) {
585
- return `renderer`
554
+ return `renderer`;
586
555
  }
587
556
  if (cmd.includes('--type=utility')) {
588
- return 'utility'
557
+ return 'utility';
589
558
  }
590
559
  if (cmd.includes('tsserver.js')) {
591
- return 'tsserver.js'
560
+ return 'tsserver.js';
592
561
  }
593
562
  if (cmd.includes('typingsInstaller.js')) {
594
- return 'typingsInstaller.js'
563
+ return 'typingsInstaller.js';
595
564
  }
596
565
  if (cmd.includes('extensionHostHelperProcessMain.js')) {
597
- return 'extension-host-helper-process'
566
+ return 'extension-host-helper-process';
598
567
  }
599
568
  if (cmd.includes('/bin/rg') || cmd.includes('rg.exe')) {
600
- return 'ripgrep'
569
+ return 'ripgrep';
601
570
  }
602
571
  if (cmd.startsWith('bash')) {
603
- return 'bash'
572
+ return 'bash';
604
573
  }
605
574
  if (cmd.startsWith(`/opt/sublime_text/sublime_text `)) {
606
- return 'sublime-text'
575
+ return 'sublime-text';
607
576
  }
608
577
  if (cmd.includes('\\conhost.exe')) {
609
- return 'conhost.exe'
578
+ return 'conhost.exe';
610
579
  }
611
- return `${cmd}`
580
+ return `${cmd}`;
612
581
  };
613
582
 
614
583
  const ENOENT = 'ENOENT';
615
584
  const ERR_DLOPEN_FAILED = 'ERR_DLOPEN_FAILED';
616
585
  const ESRCH = 'ESRCH';
617
586
 
618
- const isDlOpenError = (error) => {
619
- return error && error instanceof Error && 'code' in error && error.code === ERR_DLOPEN_FAILED
587
+ const isDlOpenError = error => {
588
+ return error && error instanceof Error && 'code' in error && error.code === ERR_DLOPEN_FAILED;
620
589
  };
621
590
 
622
591
  const loadWindowProcessTree = async () => {
623
592
  try {
624
- return await import('@vscode/windows-process-tree')
593
+ return await import('@vscode/windows-process-tree');
625
594
  } catch (error) {
626
595
  if (isDlOpenError(error)) {
627
- throw new VError(
628
- `Failed to load windows process tree: The native module "@vscode/windows-process-tree" is not compatible with this node version and must be compiled against a matching electron version using electron-rebuild`,
629
- )
596
+ throw new VError(`Failed to load windows process tree: The native module "@vscode/windows-process-tree" is not compatible with this node version and must be compiled against a matching electron version using electron-rebuild`);
630
597
  }
631
- throw new VError(error, `Failed to load windows process tree`)
598
+ throw new VError(error, `Failed to load windows process tree`);
632
599
  }
633
600
  };
634
601
 
@@ -648,45 +615,38 @@ const withResolvers = () => {
648
615
  return {
649
616
  resolve: _resolve,
650
617
  reject: _reject,
651
- promise,
652
- }
618
+ promise
619
+ };
653
620
  };
654
621
 
655
- /**
656
- *
657
- * @param {number} rootPid
658
- * @param {number} flags
659
- * @returns {Promise<any[] | undefined>}
660
- */
661
622
  const getProcessList = async (rootPid, flags) => {
662
623
  const WindowsProcessTree = await loadWindowProcessTree();
663
- const { resolve, promise } = withResolvers();
624
+ const {
625
+ resolve,
626
+ promise
627
+ } = withResolvers();
664
628
  WindowsProcessTree.getProcessList(rootPid, resolve, flags);
665
- return promise
629
+ return promise;
666
630
  };
667
-
668
- /**
669
- *
670
- * @param {any[]} processList
671
- * @returns Promise< WindowsProcessTree.IProcessCpuInfo[]>
672
- */
673
- const addCpuUsage = async (processList) => {
631
+ const addCpuUsage = async processList => {
674
632
  const WindowsProcessTree = await loadWindowProcessTree();
675
- const { resolve, promise } = withResolvers();
633
+ const {
634
+ resolve,
635
+ promise
636
+ } = withResolvers();
676
637
  WindowsProcessTree.getProcessCpuUsage(processList, resolve);
677
- return promise
638
+ return promise;
678
639
  };
679
640
 
680
641
  const Memory = 1;
681
642
  const CommandLine = 2;
682
643
 
683
644
  const createPidMap = async () => {
684
- return invoke('CreatePidMap.createPidMap')
645
+ return invoke('CreatePidMap.createPidMap');
685
646
  };
686
647
 
687
648
  // listProcesses windows implementation based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/ps.ts (License MIT)
688
649
 
689
-
690
650
  /**
691
651
  * @param {import('@vscode/windows-process-tree').IProcessCpuInfo} item
692
652
  * @param {number} rootPid
@@ -698,36 +658,29 @@ const toResultItem = (item, rootPid, pidMap) => {
698
658
  pid: item.pid,
699
659
  ppid: item.ppid,
700
660
  memory: item.memory,
701
- cmd: item.commandLine,
702
- }
661
+ cmd: item.commandLine
662
+ };
703
663
  };
704
-
705
- /**
706
- *
707
- * @param {import('@vscode/windows-process-tree').IProcessCpuInfo[]} completeProcessList
708
- * @param {number} rootPid
709
- */
710
664
  const toResult = (completeProcessList, rootPid, pidMap) => {
711
665
  const results = [];
712
666
  for (const item of completeProcessList) {
713
667
  results.push(toResultItem(item, rootPid, pidMap));
714
668
  }
715
- return results
669
+ return results;
716
670
  };
717
-
718
- const listProcessesWithMemoryUsage$1 = async (rootPid) => {
671
+ const listProcessesWithMemoryUsage$1 = async rootPid => {
719
672
  try {
720
673
  const processList = await getProcessList(rootPid, CommandLine | Memory);
721
674
  if (!processList) {
722
- throw new VError(`Root process ${rootPid} not found`)
675
+ throw new VError(`Root process ${rootPid} not found`);
723
676
  }
724
677
  const pidMap = await createPidMap();
725
678
  const completeProcessList = await addCpuUsage(processList);
726
679
  const result = toResult(completeProcessList, rootPid, pidMap);
727
- return result
680
+ return result;
728
681
  } catch (error) {
729
682
  // @ts-ignore
730
- throw new VError(error, `Failed to list processes`)
683
+ throw new VError(error, `Failed to list processes`);
731
684
  }
732
685
  };
733
686
 
@@ -738,23 +691,22 @@ const ListProcessesWithMemoryUsageWindows = {
738
691
 
739
692
  const Utf8 = 'utf8';
740
693
 
741
- const isEnoentErrorWindows = (error) => {
742
- return error && error.message && error.message.includes('The system cannot find the path specified.')
694
+ const isEnoentErrorWindows = error => {
695
+ return error && error.message && error.message.includes('The system cannot find the path specified.');
743
696
  };
744
697
 
745
- const isEnoentErrorLinux = (error) => {
746
- return error.code === ENOENT
698
+ const isEnoentErrorLinux = error => {
699
+ return error.code === ENOENT;
747
700
  };
748
-
749
- const isEnoentError = (error) => {
701
+ const isEnoentError = error => {
750
702
  if (!error) {
751
- return false
703
+ return false;
752
704
  }
753
- return isEnoentErrorLinux(error) || isEnoentErrorWindows(error)
705
+ return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
754
706
  };
755
707
 
756
- const isEsrchError = (error) => {
757
- return error && error.code === ESRCH
708
+ const isEsrchError = error => {
709
+ return error && error.code === ESRCH;
758
710
  };
759
711
 
760
712
  const isMacOs = process.platform === 'darwin';
@@ -763,105 +715,102 @@ const EmptyString = '';
763
715
  const NewLine = '\n';
764
716
  const Space = ' ';
765
717
 
766
- const parseMemory = (content) => {
718
+ const parseMemory = content => {
767
719
  const trimmedContent = content.trim();
768
720
  const numberBlocks = trimmedContent.split(Space);
769
721
  const pageSize = 4096;
770
722
  const rss = Number.parseInt(numberBlocks[1]) * pageSize;
771
723
  const shared = Number.parseInt(numberBlocks[2]) * pageSize;
772
724
  const memory = rss - shared;
773
- return memory
725
+ return memory;
774
726
  };
775
727
 
776
- const getContent = async (pid) => {
728
+ const getContent = async pid => {
777
729
  try {
778
730
  const filePath = join('/proc', `${pid}`, 'statm');
779
731
  const content = await readFile(filePath, Utf8);
780
- return content
732
+ return content;
781
733
  } catch (error) {
782
734
  if (isEnoentError(error) || isEsrchError(error)) {
783
- return ''
735
+ return '';
784
736
  }
785
- throw error
737
+ throw error;
786
738
  }
787
739
  };
788
-
789
- const getAccurateMemoryUsage = async (pid) => {
740
+ const getAccurateMemoryUsage = async pid => {
790
741
  try {
791
742
  number$1(pid);
792
743
  if (isMacOs) {
793
- return 0
744
+ return 0;
794
745
  }
795
746
  const content = await getContent(pid);
796
747
  if (!content) {
797
- return -1
748
+ return -1;
798
749
  }
799
750
  const memory = parseMemory(content);
800
- return memory
751
+ return memory;
801
752
  } catch (error) {
802
- throw new VError(error, 'Failed to get accurate memory usage')
753
+ throw new VError(error, 'Failed to get accurate memory usage');
803
754
  }
804
755
  };
805
756
 
806
- const addAccurateMemoryUsage = async (process) => {
757
+ const addAccurateMemoryUsage = async process => {
807
758
  const accurateMemoryUsage = await getAccurateMemoryUsage(process.pid);
808
759
  return {
809
760
  ...process,
810
- memory: accurateMemoryUsage,
811
- }
761
+ memory: accurateMemoryUsage
762
+ };
812
763
  };
813
764
 
814
765
  const SIGINT = 'SIGINT';
815
766
 
816
767
  const execFile = promisify(execFile$1);
817
-
818
768
  const getPsOutput = async () => {
819
769
  try {
820
- const { stdout } = await execFile('ps', ['-ax', '-o', 'pid=,ppid=,pcpu=,pmem=,command=']);
821
- return stdout.trim()
770
+ const {
771
+ stdout
772
+ } = await execFile('ps', ['-ax', '-o', 'pid=,ppid=,pcpu=,pmem=,command=']);
773
+ return stdout.trim();
822
774
  } catch (error) {
823
775
  // @ts-ignore
824
776
  if (error && error.signal === SIGINT) {
825
- return ''
777
+ return '';
826
778
  }
827
- throw new VError(error, `Failed to execute ps`)
779
+ throw new VError(error, `Failed to execute ps`);
828
780
  }
829
781
  };
830
782
 
831
- const hasPositiveMemoryUsage = (process) => {
832
- return process.memory >= 0
783
+ const hasPositiveMemoryUsage = process => {
784
+ return process.memory >= 0;
833
785
  };
834
786
 
835
- const splitLines = (lines) => {
836
- return lines.split(NewLine)
787
+ const splitLines = lines => {
788
+ return lines.split(NewLine);
837
789
  };
838
790
 
839
791
  // parse ps output based on vscode https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/node/ps.ts (License MIT)
840
792
 
841
-
842
793
  const PID_CMD = /^\s*(\d+)\s+(\d+)\s+([\d.]+)\s+([\d.]+)\s+(.+)$/s;
843
-
844
- const parsePsOutputLine = (line) => {
794
+ const parsePsOutputLine = line => {
845
795
  string(line);
846
796
  const matches = PID_CMD.exec(line.trim());
847
797
  if (matches && matches.length === 6) {
848
798
  return {
849
799
  pid: Number.parseInt(matches[1]),
850
800
  ppid: Number.parseInt(matches[2]),
851
- cmd: matches[5],
801
+ cmd: matches[5]
852
802
  // load: parseInt(matches[3]),
853
803
  // mem: parseInt(matches[4]),
854
- }
804
+ };
855
805
  }
856
- throw new Error(`line could not be parsed: ${line}`)
806
+ throw new Error(`line could not be parsed: ${line}`);
857
807
  };
858
-
859
808
  const parsePsOutput = (stdout, rootPid, pidMap) => {
860
809
  string(stdout);
861
810
  number$1(rootPid);
862
811
  object(pidMap);
863
812
  if (stdout === EmptyString) {
864
- return []
813
+ return [];
865
814
  }
866
815
  const lines = splitLines(stdout);
867
816
  const result = [];
@@ -869,22 +818,26 @@ const parsePsOutput = (stdout, rootPid, pidMap) => {
869
818
  depthMap[rootPid] = 1;
870
819
  const parsedLines = lines.map(parsePsOutputLine);
871
820
  for (const parsedLine of parsedLines) {
872
- const { pid, ppid, cmd } = parsedLine;
821
+ const {
822
+ pid,
823
+ ppid,
824
+ cmd
825
+ } = parsedLine;
873
826
  const depth = pid === rootPid ? 1 : depthMap[ppid];
874
827
  if (!depth) {
875
- continue
828
+ continue;
876
829
  }
877
830
  result.push({
878
831
  ...parsedLine,
879
832
  depth,
880
- name: getName(pid, cmd, rootPid, pidMap),
833
+ name: getName(pid, cmd, rootPid, pidMap)
881
834
  });
882
835
  depthMap[pid] = depth + 1;
883
836
  }
884
- return result
837
+ return result;
885
838
  };
886
839
 
887
- const listProcessesWithMemoryUsage = async (rootPid) => {
840
+ const listProcessesWithMemoryUsage = async rootPid => {
888
841
  // console.time('getPsOutput')
889
842
  const stdout = await getPsOutput();
890
843
  const pidMap = await createPidMap();
@@ -897,7 +850,7 @@ const listProcessesWithMemoryUsage = async (rootPid) => {
897
850
  const parsedWithAccurateMemoryUsage = await Promise.all(parsed.map(addAccurateMemoryUsage));
898
851
  // console.timeEnd('addAccurateMemoryUsage')
899
852
  const filtered = parsedWithAccurateMemoryUsage.filter(hasPositiveMemoryUsage);
900
- return filtered
853
+ return filtered;
901
854
  };
902
855
 
903
856
  const ListProcessesWithMemoryUsageUnix = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/process-explorer",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Process Explorer",
5
5
  "main": "dist/index.js",
6
6
  "bin": "bin/processExplorer.js",
@@ -18,8 +18,8 @@
18
18
  "node": ">=18"
19
19
  },
20
20
  "dependencies": {
21
- "@lvce-editor/assert": "^1.2.0",
22
- "@lvce-editor/ipc": "^10.0.2",
21
+ "@lvce-editor/assert": "^1.3.0",
22
+ "@lvce-editor/ipc": "^10.0.4",
23
23
  "@lvce-editor/json-rpc": "^3.0.0",
24
24
  "@lvce-editor/verror": "^1.4.0"
25
25
  },