@lvce-editor/find-widget-worker 1.9.0 → 1.11.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.
@@ -470,6 +470,16 @@ const constructError = (message, type, name) => {
470
470
  }
471
471
  return new ErrorConstructor(message);
472
472
  };
473
+ const joinLines = lines => {
474
+ return lines.join(NewLine);
475
+ };
476
+ const splitLines = lines => {
477
+ return lines.split(NewLine);
478
+ };
479
+ const getCurrentStack = () => {
480
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
481
+ return currentStack;
482
+ };
473
483
  const getNewLineIndex = (string, startIndex = undefined) => {
474
484
  return string.indexOf(NewLine, startIndex);
475
485
  };
@@ -480,19 +490,16 @@ const getParentStack = error => {
480
490
  }
481
491
  return parentStack;
482
492
  };
483
- const joinLines = lines => {
484
- return lines.join(NewLine);
485
- };
486
493
  const MethodNotFound = -32601;
487
494
  const Custom = -32001;
488
- const splitLines = lines => {
489
- return lines.split(NewLine);
490
- };
491
495
  const restoreJsonRpcError = error => {
496
+ const currentStack = getCurrentStack();
492
497
  if (error && error instanceof Error) {
498
+ if (typeof error.stack === 'string') {
499
+ error.stack = error.stack + NewLine + currentStack;
500
+ }
493
501
  return error;
494
502
  }
495
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
496
503
  if (error && error.code && error.code === MethodNotFound) {
497
504
  const restoredError = new JsonRpcError(error.message);
498
505
  const parentStack = getParentStack(error);
@@ -573,6 +580,17 @@ const getErrorType = prettyError => {
573
580
  }
574
581
  return undefined;
575
582
  };
583
+ const isAlreadyStack = line => {
584
+ return line.trim().startsWith('at ');
585
+ };
586
+ const getStack = prettyError => {
587
+ const stackString = prettyError.stack || '';
588
+ const newLineIndex = stackString.indexOf('\n');
589
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
590
+ return stackString.slice(newLineIndex + 1);
591
+ }
592
+ return stackString;
593
+ };
576
594
  const getErrorProperty = (error, prettyError) => {
577
595
  if (error && error.code === E_COMMAND_NOT_FOUND) {
578
596
  return {
@@ -585,7 +603,7 @@ const getErrorProperty = (error, prettyError) => {
585
603
  code: Custom,
586
604
  message: prettyError.message,
587
605
  data: {
588
- stack: prettyError.stack,
606
+ stack: getStack(prettyError),
589
607
  codeFrame: prettyError.codeFrame,
590
608
  type: getErrorType(prettyError),
591
609
  code: prettyError.code,
@@ -593,18 +611,18 @@ const getErrorProperty = (error, prettyError) => {
593
611
  }
594
612
  };
595
613
  };
596
- const create$1$1 = (message, error) => {
614
+ const create$1$1 = (id, error) => {
597
615
  return {
598
616
  jsonrpc: Two,
599
- id: message.id,
617
+ id,
600
618
  error
601
619
  };
602
620
  };
603
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
621
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
604
622
  const prettyError = preparePrettyError(error);
605
623
  logError(error, prettyError);
606
624
  const errorProperty = getErrorProperty(error, prettyError);
607
- return create$1$1(message, errorProperty);
625
+ return create$1$1(id, errorProperty);
608
626
  };
609
627
  const create$5 = (message, result) => {
610
628
  return {
@@ -617,12 +635,27 @@ const getSuccessResponse = (message, result) => {
617
635
  const resultProperty = result ?? null;
618
636
  return create$5(message, resultProperty);
619
637
  };
638
+ const getErrorResponseSimple = (id, error) => {
639
+ return {
640
+ jsonrpc: Two,
641
+ id,
642
+ error: {
643
+ code: Custom,
644
+ // @ts-ignore
645
+ message: error.message,
646
+ data: error
647
+ }
648
+ };
649
+ };
620
650
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
621
651
  try {
622
652
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
623
653
  return getSuccessResponse(message, result);
624
654
  } catch (error) {
625
- return getErrorResponse(message, error, preparePrettyError, logError);
655
+ if (ipc.canUseSimpleErrorResponse) {
656
+ return getErrorResponseSimple(message.id, error);
657
+ }
658
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
626
659
  }
627
660
  };
628
661
  const defaultPreparePrettyError = error => {
@@ -677,7 +710,7 @@ const handleJsonRpcMessage = async (...args) => {
677
710
  try {
678
711
  ipc.send(response);
679
712
  } catch (error) {
680
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
713
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
681
714
  ipc.send(errorResponse);
682
715
  }
683
716
  return;
@@ -982,7 +1015,7 @@ const focusCloseButton = state => {
982
1015
  };
983
1016
 
984
1017
  const rpcs = Object.create(null);
985
- const set$a = (id, rpc) => {
1018
+ const set$g = (id, rpc) => {
986
1019
  rpcs[id] = rpc;
987
1020
  };
988
1021
  const get = id => {
@@ -1006,19 +1039,22 @@ const create = rpcId => {
1006
1039
  return rpc.invokeAndTransfer(method, ...params);
1007
1040
  },
1008
1041
  set(rpc) {
1009
- set$a(rpcId, rpc);
1042
+ set$g(rpcId, rpc);
1043
+ },
1044
+ async dispose() {
1045
+ const rpc = get(rpcId);
1046
+ await rpc.dispose();
1010
1047
  }
1011
1048
  };
1012
1049
  };
1013
1050
  const EditorWorker$1 = 99;
1014
1051
  const {
1015
- invoke: invoke$9,
1016
- set: set$9
1017
- } = create(EditorWorker$1);
1052
+ invoke: invoke$d,
1053
+ set: set$c} = create(EditorWorker$1);
1018
1054
  const EditorWorker = {
1019
1055
  __proto__: null,
1020
- invoke: invoke$9,
1021
- set: set$9
1056
+ invoke: invoke$d,
1057
+ set: set$c
1022
1058
  };
1023
1059
 
1024
1060
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/find-widget-worker",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",