@lvce-editor/extension-management-worker 3.0.0 → 3.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.
@@ -1,3 +1,58 @@
1
+ class AssertionError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'AssertionError';
5
+ }
6
+ }
7
+ const Object$1 = 1;
8
+ const Number = 2;
9
+ const Array$1 = 3;
10
+ const String = 4;
11
+ const Boolean$1 = 5;
12
+ const Function = 6;
13
+ const Null = 7;
14
+ const Unknown = 8;
15
+ const getType = value => {
16
+ switch (typeof value) {
17
+ case 'number':
18
+ return Number;
19
+ case 'function':
20
+ return Function;
21
+ case 'string':
22
+ return String;
23
+ case 'object':
24
+ if (value === null) {
25
+ return Null;
26
+ }
27
+ if (Array.isArray(value)) {
28
+ return Array$1;
29
+ }
30
+ return Object$1;
31
+ case 'boolean':
32
+ return Boolean$1;
33
+ default:
34
+ return Unknown;
35
+ }
36
+ };
37
+ const object = value => {
38
+ const type = getType(value);
39
+ if (type !== Object$1) {
40
+ throw new AssertionError('expected value to be of type object');
41
+ }
42
+ };
43
+ const number = value => {
44
+ const type = getType(value);
45
+ if (type !== Number) {
46
+ throw new AssertionError('expected value to be of type number');
47
+ }
48
+ };
49
+ const string = value => {
50
+ const type = getType(value);
51
+ if (type !== String) {
52
+ throw new AssertionError('expected value to be of type string');
53
+ }
54
+ };
55
+
1
56
  const normalizeLine = line => {
2
57
  if (line.startsWith('Error: ')) {
3
58
  return line.slice('Error: '.length);
@@ -54,61 +109,6 @@ class VError extends Error {
54
109
  }
55
110
  }
56
111
 
57
- class AssertionError extends Error {
58
- constructor(message) {
59
- super(message);
60
- this.name = 'AssertionError';
61
- }
62
- }
63
- const Object$1 = 1;
64
- const Number = 2;
65
- const Array$1 = 3;
66
- const String = 4;
67
- const Boolean$1 = 5;
68
- const Function = 6;
69
- const Null = 7;
70
- const Unknown = 8;
71
- const getType = value => {
72
- switch (typeof value) {
73
- case 'number':
74
- return Number;
75
- case 'function':
76
- return Function;
77
- case 'string':
78
- return String;
79
- case 'object':
80
- if (value === null) {
81
- return Null;
82
- }
83
- if (Array.isArray(value)) {
84
- return Array$1;
85
- }
86
- return Object$1;
87
- case 'boolean':
88
- return Boolean$1;
89
- default:
90
- return Unknown;
91
- }
92
- };
93
- const object = value => {
94
- const type = getType(value);
95
- if (type !== Object$1) {
96
- throw new AssertionError('expected value to be of type object');
97
- }
98
- };
99
- const number = value => {
100
- const type = getType(value);
101
- if (type !== Number) {
102
- throw new AssertionError('expected value to be of type number');
103
- }
104
- };
105
- const string = value => {
106
- const type = getType(value);
107
- if (type !== String) {
108
- throw new AssertionError('expected value to be of type string');
109
- }
110
- };
111
-
112
112
  const isMessagePort = value => {
113
113
  return value && value instanceof MessagePort;
114
114
  };
@@ -540,7 +540,7 @@ const waitForWebSocketToBeOpen = webSocket => {
540
540
  open: Open
541
541
  });
542
542
  };
543
- const create$6 = async ({
543
+ const create$d = async ({
544
544
  webSocket
545
545
  }) => {
546
546
  const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
@@ -577,13 +577,34 @@ const wrap = webSocket => {
577
577
  };
578
578
  const IpcParentWithWebSocket$1 = {
579
579
  __proto__: null,
580
- create: create$6,
580
+ create: create$d,
581
581
  wrap
582
582
  };
583
583
 
584
+ class CommandNotFoundError extends Error {
585
+ constructor(command) {
586
+ super(`Command not found ${command}`);
587
+ this.name = 'CommandNotFoundError';
588
+ }
589
+ }
590
+ const commands = Object.create(null);
591
+ const register = commandMap => {
592
+ Object.assign(commands, commandMap);
593
+ };
594
+ const getCommand = key => {
595
+ return commands[key];
596
+ };
597
+ const execute = (command, ...args) => {
598
+ const fn = getCommand(command);
599
+ if (!fn) {
600
+ throw new CommandNotFoundError(command);
601
+ }
602
+ return fn(...args);
603
+ };
604
+
584
605
  const Two$1 = '2.0';
585
606
  const callbacks = Object.create(null);
586
- const get$5 = id => {
607
+ const get$6 = id => {
587
608
  return callbacks[id];
588
609
  };
589
610
  const remove$1 = id => {
@@ -605,12 +626,12 @@ const getErrorConstructor = (message, type) => {
605
626
  switch (type) {
606
627
  case DomException:
607
628
  return DOMException;
608
- case TypeError$1:
609
- return TypeError;
610
- case SyntaxError$1:
611
- return SyntaxError;
612
629
  case ReferenceError$1:
613
630
  return ReferenceError;
631
+ case SyntaxError$1:
632
+ return SyntaxError;
633
+ case TypeError$1:
634
+ return TypeError;
614
635
  default:
615
636
  return Error;
616
637
  }
@@ -732,7 +753,7 @@ const warn$1 = (...args) => {
732
753
  console.warn(...args);
733
754
  };
734
755
  const resolve = (id, response) => {
735
- const fn = get$5(id);
756
+ const fn = get$6(id);
736
757
  if (!fn) {
737
758
  console.log(response);
738
759
  warn$1(`callback ${id} may already be disposed`);
@@ -766,27 +787,27 @@ const getErrorProperty = (error, prettyError) => {
766
787
  if (error && error.code === E_COMMAND_NOT_FOUND) {
767
788
  return {
768
789
  code: MethodNotFound,
769
- message: error.message,
770
- data: error.stack
790
+ data: error.stack,
791
+ message: error.message
771
792
  };
772
793
  }
773
794
  return {
774
795
  code: Custom,
775
- message: prettyError.message,
776
796
  data: {
777
- stack: getStack(prettyError),
778
- codeFrame: prettyError.codeFrame,
779
- type: getErrorType(prettyError),
780
797
  code: prettyError.code,
781
- name: prettyError.name
782
- }
798
+ codeFrame: prettyError.codeFrame,
799
+ name: prettyError.name,
800
+ stack: getStack(prettyError),
801
+ type: getErrorType(prettyError)
802
+ },
803
+ message: prettyError.message
783
804
  };
784
805
  };
785
806
  const create$1$1 = (id, error) => {
786
807
  return {
787
- jsonrpc: Two$1,
808
+ error,
788
809
  id,
789
- error
810
+ jsonrpc: Two$1
790
811
  };
791
812
  };
792
813
  const getErrorResponse = (id, error, preparePrettyError, logError) => {
@@ -795,27 +816,27 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
795
816
  const errorProperty = getErrorProperty(error, prettyError);
796
817
  return create$1$1(id, errorProperty);
797
818
  };
798
- const create$4 = (message, result) => {
819
+ const create$c = (message, result) => {
799
820
  return {
800
- jsonrpc: Two$1,
801
821
  id: message.id,
822
+ jsonrpc: Two$1,
802
823
  result: result ?? null
803
824
  };
804
825
  };
805
826
  const getSuccessResponse = (message, result) => {
806
827
  const resultProperty = result ?? null;
807
- return create$4(message, resultProperty);
828
+ return create$c(message, resultProperty);
808
829
  };
809
830
  const getErrorResponseSimple = (id, error) => {
810
831
  return {
811
- jsonrpc: Two$1,
812
- id,
813
832
  error: {
814
833
  code: Custom,
834
+ data: error,
815
835
  // @ts-ignore
816
- message: error.message,
817
- data: error
818
- }
836
+ message: error.message
837
+ },
838
+ id,
839
+ jsonrpc: Two$1
819
840
  };
820
841
  };
821
842
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
@@ -845,35 +866,35 @@ const normalizeParams = args => {
845
866
  if (args.length === 1) {
846
867
  const options = args[0];
847
868
  return {
869
+ execute: options.execute,
848
870
  ipc: options.ipc,
871
+ logError: options.logError || defaultLogError,
849
872
  message: options.message,
850
- execute: options.execute,
851
- resolve: options.resolve || defaultResolve,
852
873
  preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
853
- logError: options.logError || defaultLogError,
854
- requiresSocket: options.requiresSocket || defaultRequiresSocket
874
+ requiresSocket: options.requiresSocket || defaultRequiresSocket,
875
+ resolve: options.resolve || defaultResolve
855
876
  };
856
877
  }
857
878
  return {
879
+ execute: args[2],
858
880
  ipc: args[0],
881
+ logError: args[5],
859
882
  message: args[1],
860
- execute: args[2],
861
- resolve: args[3],
862
883
  preparePrettyError: args[4],
863
- logError: args[5],
864
- requiresSocket: args[6]
884
+ requiresSocket: args[6],
885
+ resolve: args[3]
865
886
  };
866
887
  };
867
888
  const handleJsonRpcMessage = async (...args) => {
868
889
  const options = normalizeParams(args);
869
890
  const {
870
- message,
871
- ipc,
872
891
  execute,
873
- resolve,
874
- preparePrettyError,
892
+ ipc,
875
893
  logError,
876
- requiresSocket
894
+ message,
895
+ preparePrettyError,
896
+ requiresSocket,
897
+ resolve
877
898
  } = options;
878
899
  if ('id' in message) {
879
900
  if ('method' in message) {
@@ -896,36 +917,17 @@ const handleJsonRpcMessage = async (...args) => {
896
917
  throw new JsonRpcError('unexpected message');
897
918
  };
898
919
 
899
- class CommandNotFoundError extends Error {
900
- constructor(command) {
901
- super(`Command not found ${command}`);
902
- this.name = 'CommandNotFoundError';
903
- }
904
- }
905
- const commands = Object.create(null);
906
- const register = commandMap => {
907
- Object.assign(commands, commandMap);
908
- };
909
- const getCommand = key => {
910
- return commands[key];
911
- };
912
- const execute = (command, ...args) => {
913
- const fn = getCommand(command);
914
- if (!fn) {
915
- throw new CommandNotFoundError(command);
916
- }
917
- return fn(...args);
918
- };
919
-
920
920
  const Two = '2.0';
921
- const create$t = (method, params) => {
921
+
922
+ const create$b = (method, params) => {
922
923
  return {
923
924
  jsonrpc: Two,
924
925
  method,
925
926
  params
926
927
  };
927
928
  };
928
- const create$s = (id, method, params) => {
929
+
930
+ const create$a = (id, method, params) => {
929
931
  const message = {
930
932
  id,
931
933
  jsonrpc: Two,
@@ -934,15 +936,14 @@ const create$s = (id, method, params) => {
934
936
  };
935
937
  return message;
936
938
  };
939
+
937
940
  let id$1 = 0;
938
- const create$r = () => {
941
+ const create$9 = () => {
939
942
  return ++id$1;
940
943
  };
941
944
 
942
- /* eslint-disable n/no-unsupported-features/es-syntax */
943
-
944
945
  const registerPromise = map => {
945
- const id = create$r();
946
+ const id = create$9();
946
947
  const {
947
948
  promise,
948
949
  resolve
@@ -954,13 +955,12 @@ const registerPromise = map => {
954
955
  };
955
956
  };
956
957
 
957
- // @ts-ignore
958
958
  const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
959
959
  const {
960
960
  id,
961
961
  promise
962
962
  } = registerPromise(callbacks);
963
- const message = create$s(id, method, params);
963
+ const message = create$a(id, method, params);
964
964
  if (useSendAndTransfer && ipc.sendAndTransfer) {
965
965
  ipc.sendAndTransfer(message);
966
966
  } else {
@@ -996,12 +996,13 @@ const createRpc = ipc => {
996
996
  * @deprecated
997
997
  */
998
998
  send(method, ...params) {
999
- const message = create$t(method, params);
999
+ const message = create$b(method, params);
1000
1000
  ipc.send(message);
1001
1001
  }
1002
1002
  };
1003
1003
  return rpc;
1004
1004
  };
1005
+
1005
1006
  const requiresSocket = () => {
1006
1007
  return false;
1007
1008
  };
@@ -1016,6 +1017,7 @@ const handleMessage = event => {
1016
1017
  const actualExecute = event?.target?.execute || execute;
1017
1018
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
1018
1019
  };
1020
+
1019
1021
  const handleIpc = ipc => {
1020
1022
  if ('addEventListener' in ipc) {
1021
1023
  ipc.addEventListener('message', handleMessage);
@@ -1024,6 +1026,7 @@ const handleIpc = ipc => {
1024
1026
  ipc.on('message', handleMessage);
1025
1027
  }
1026
1028
  };
1029
+
1027
1030
  const listen$1 = async (module, options) => {
1028
1031
  const rawIpc = await module.listen(options);
1029
1032
  if (module.signal) {
@@ -1032,23 +1035,105 @@ const listen$1 = async (module, options) => {
1032
1035
  const ipc = module.wrap(rawIpc);
1033
1036
  return ipc;
1034
1037
  };
1038
+
1039
+ const create$8 = async ({
1040
+ commandMap,
1041
+ isMessagePortOpen = true,
1042
+ messagePort
1043
+ }) => {
1044
+ // TODO create a commandMap per rpc instance
1045
+ register(commandMap);
1046
+ const rawIpc = await IpcParentWithMessagePort$1.create({
1047
+ isMessagePortOpen,
1048
+ messagePort
1049
+ });
1050
+ const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1051
+ handleIpc(ipc);
1052
+ const rpc = createRpc(ipc);
1053
+ messagePort.start();
1054
+ return rpc;
1055
+ };
1056
+
1057
+ const create$7 = async ({
1058
+ commandMap,
1059
+ isMessagePortOpen,
1060
+ send
1061
+ }) => {
1062
+ const {
1063
+ port1,
1064
+ port2
1065
+ } = new MessageChannel();
1066
+ await send(port1);
1067
+ return create$8({
1068
+ commandMap,
1069
+ isMessagePortOpen,
1070
+ messagePort: port2
1071
+ });
1072
+ };
1073
+
1074
+ const createSharedLazyRpc = factory => {
1075
+ let rpcPromise;
1076
+ const getOrCreate = () => {
1077
+ if (!rpcPromise) {
1078
+ rpcPromise = factory();
1079
+ }
1080
+ return rpcPromise;
1081
+ };
1082
+ return {
1083
+ async dispose() {
1084
+ const rpc = await getOrCreate();
1085
+ await rpc.dispose();
1086
+ },
1087
+ async invoke(method, ...params) {
1088
+ const rpc = await getOrCreate();
1089
+ return rpc.invoke(method, ...params);
1090
+ },
1091
+ async invokeAndTransfer(method, ...params) {
1092
+ const rpc = await getOrCreate();
1093
+ return rpc.invokeAndTransfer(method, ...params);
1094
+ },
1095
+ async send(method, ...params) {
1096
+ const rpc = await getOrCreate();
1097
+ rpc.send(method, ...params);
1098
+ }
1099
+ };
1100
+ };
1101
+
1102
+ const create$6 = async ({
1103
+ commandMap,
1104
+ isMessagePortOpen,
1105
+ send
1106
+ }) => {
1107
+ return createSharedLazyRpc(() => {
1108
+ return create$7({
1109
+ commandMap,
1110
+ isMessagePortOpen,
1111
+ send
1112
+ });
1113
+ });
1114
+ };
1115
+
1035
1116
  const Https = 'https:';
1036
1117
  const Ws = 'ws:';
1037
1118
  const Wss = 'wss:';
1119
+
1038
1120
  const getWebSocketProtocol = locationProtocol => {
1039
1121
  return locationProtocol === Https ? Wss : Ws;
1040
1122
  };
1123
+
1041
1124
  const getWebSocketUrl = (type, host, locationProtocol) => {
1042
1125
  const wsProtocol = getWebSocketProtocol(locationProtocol);
1043
1126
  return `${wsProtocol}//${host}/websocket/${type}`;
1044
1127
  };
1128
+
1045
1129
  const getHost = () => {
1046
1130
  return location.host;
1047
1131
  };
1048
1132
  const getProtocol = () => {
1049
1133
  return location.protocol;
1050
1134
  };
1051
- const create$i = async ({
1135
+
1136
+ const create$5 = async ({
1052
1137
  commandMap,
1053
1138
  webSocket
1054
1139
  }) => {
@@ -1062,7 +1147,8 @@ const create$i = async ({
1062
1147
  const rpc = createRpc(ipc);
1063
1148
  return rpc;
1064
1149
  };
1065
- const create$h = async ({
1150
+
1151
+ const create$4 = async ({
1066
1152
  commandMap,
1067
1153
  type
1068
1154
  }) => {
@@ -1070,17 +1156,14 @@ const create$h = async ({
1070
1156
  const protocol = getProtocol();
1071
1157
  const wsUrl = getWebSocketUrl(type, host, protocol);
1072
1158
  const webSocket = new WebSocket(wsUrl);
1073
- const rpc = await create$i({
1159
+ const rpc = await create$5({
1074
1160
  commandMap,
1075
1161
  webSocket
1076
1162
  });
1077
1163
  return rpc;
1078
1164
  };
1079
- const WebSocketRpcParent2 = {
1080
- __proto__: null,
1081
- create: create$h
1082
- };
1083
- const create$e = async ({
1165
+
1166
+ const create$3 = async ({
1084
1167
  commandMap,
1085
1168
  isMessagePortOpen,
1086
1169
  messagePort
@@ -1096,51 +1179,7 @@ const create$e = async ({
1096
1179
  const rpc = createRpc(ipc);
1097
1180
  return rpc;
1098
1181
  };
1099
- const MessagePortRpcParent = {
1100
- __proto__: null,
1101
- create: create$e
1102
- };
1103
- const create$5 = async ({
1104
- commandMap,
1105
- isMessagePortOpen = true,
1106
- messagePort
1107
- }) => {
1108
- // TODO create a commandMap per rpc instance
1109
- register(commandMap);
1110
- const rawIpc = await IpcParentWithMessagePort$1.create({
1111
- isMessagePortOpen,
1112
- messagePort
1113
- });
1114
- const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
1115
- handleIpc(ipc);
1116
- const rpc = createRpc(ipc);
1117
- messagePort.start();
1118
- return rpc;
1119
- };
1120
- const PlainMessagePortRpc = {
1121
- __proto__: null,
1122
- create: create$5
1123
- };
1124
- const create$3 = async ({
1125
- commandMap,
1126
- isMessagePortOpen,
1127
- send
1128
- }) => {
1129
- const {
1130
- port1,
1131
- port2
1132
- } = new MessageChannel();
1133
- await send(port1);
1134
- return create$5({
1135
- commandMap,
1136
- isMessagePortOpen,
1137
- messagePort: port2
1138
- });
1139
- };
1140
- const TransferMessagePortRpcParent = {
1141
- __proto__: null,
1142
- create: create$3
1143
- };
1182
+
1144
1183
  const create$2 = async ({
1145
1184
  commandMap
1146
1185
  }) => {
@@ -1151,10 +1190,7 @@ const create$2 = async ({
1151
1190
  const rpc = createRpc(ipc);
1152
1191
  return rpc;
1153
1192
  };
1154
- const WebWorkerRpcClient = {
1155
- __proto__: null,
1156
- create: create$2
1157
- };
1193
+
1158
1194
  const createMockRpc = ({
1159
1195
  commandMap
1160
1196
  }) => {
@@ -1175,21 +1211,11 @@ const createMockRpc = ({
1175
1211
  return mockRpc;
1176
1212
  };
1177
1213
 
1178
- const Web = 1;
1179
- const Electron = 2;
1180
- const Remote = 3;
1181
- const Test = 4;
1182
-
1183
- const ExtensionHostWorker = 44;
1184
- const FileSystemWorker = 209;
1185
- const RendererWorker = 1;
1186
- const SharedProcess = 1492;
1187
-
1188
1214
  const rpcs$1 = Object.create(null);
1189
1215
  const set$7 = (id, rpc) => {
1190
1216
  rpcs$1[id] = rpc;
1191
1217
  };
1192
- const get$4 = id => {
1218
+ const get$5 = id => {
1193
1219
  return rpcs$1[id];
1194
1220
  };
1195
1221
  const remove = id => {
@@ -1200,18 +1226,18 @@ const remove = id => {
1200
1226
  const create$1 = rpcId => {
1201
1227
  return {
1202
1228
  async dispose() {
1203
- const rpc = get$4(rpcId);
1229
+ const rpc = get$5(rpcId);
1204
1230
  await rpc.dispose();
1205
1231
  },
1206
1232
  // @ts-ignore
1207
1233
  invoke(method, ...params) {
1208
- const rpc = get$4(rpcId);
1234
+ const rpc = get$5(rpcId);
1209
1235
  // @ts-ignore
1210
1236
  return rpc.invoke(method, ...params);
1211
1237
  },
1212
1238
  // @ts-ignore
1213
1239
  invokeAndTransfer(method, ...params) {
1214
- const rpc = get$4(rpcId);
1240
+ const rpc = get$5(rpcId);
1215
1241
  // @ts-ignore
1216
1242
  return rpc.invokeAndTransfer(method, ...params);
1217
1243
  },
@@ -1233,6 +1259,16 @@ const create$1 = rpcId => {
1233
1259
  };
1234
1260
  };
1235
1261
 
1262
+ const Web = 1;
1263
+ const Electron = 2;
1264
+ const Remote = 3;
1265
+ const Test = 4;
1266
+
1267
+ const ExtensionHostWorker = 44;
1268
+ const FileSystemWorker = 209;
1269
+ const RendererWorker = 1;
1270
+ const SharedProcess = 1492;
1271
+
1236
1272
  const {
1237
1273
  invoke: invoke$4,
1238
1274
  set: set$6
@@ -1259,7 +1295,6 @@ const {
1259
1295
  } = create$1(RendererWorker);
1260
1296
  const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
1261
1297
  const command = 'FileSystem.handleMessagePort';
1262
- // @ts-ignore
1263
1298
  await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
1264
1299
  };
1265
1300
  const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
@@ -1268,7 +1303,6 @@ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1268
1303
  };
1269
1304
  const sendMessagePortToSharedProcess = async port => {
1270
1305
  const command = 'HandleElectronMessagePort.handleElectronMessagePort';
1271
- // @ts-ignore
1272
1306
  await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
1273
1307
  };
1274
1308
 
@@ -1323,7 +1357,7 @@ const states = Object.create(null);
1323
1357
  const set$2 = status => {
1324
1358
  states[status.id] = status;
1325
1359
  };
1326
- const get$3 = extensionId => {
1360
+ const get$4 = extensionId => {
1327
1361
  return states[extensionId];
1328
1362
  };
1329
1363
  const update$1 = (id, update) => {
@@ -1404,7 +1438,9 @@ const activateExtension2 = async (extensionId, extension, absolutePath) => {
1404
1438
  const id = getExtensionId(extension);
1405
1439
  if (isImportError(error)) {
1406
1440
  const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
1407
- throw new Error(`Failed to activate extension ${id}: ${actualErrorMessage}`);
1441
+ throw new Error(`Failed to activate extension ${id}: ${actualErrorMessage}`, {
1442
+ cause: error
1443
+ });
1408
1444
  }
1409
1445
  update$1(extensionId, {
1410
1446
  status: Error$1 // TODO maybe store error also in runtime status state
@@ -1419,7 +1455,7 @@ const rpcs = Object.create(null);
1419
1455
  const add = (id, rpc) => {
1420
1456
  rpcs[id] = rpc;
1421
1457
  };
1422
- const get$2 = id => {
1458
+ const get$3 = id => {
1423
1459
  return rpcs[id];
1424
1460
  };
1425
1461
 
@@ -1487,7 +1523,9 @@ const importExtension = async (extensionId, absolutePath, activationEvent) => {
1487
1523
  });
1488
1524
  if (isImportError(error)) {
1489
1525
  const actualErrorMessage = await tryToGetActualImportErrorMessage(absolutePath, error);
1490
- throw new Error(actualErrorMessage);
1526
+ throw new Error(actualErrorMessage, {
1527
+ cause: error
1528
+ });
1491
1529
  }
1492
1530
  throw error;
1493
1531
  }
@@ -1514,6 +1552,12 @@ const activateExtension3 = async (extension, absolutePath, activationEvent, plat
1514
1552
  const state$1 = {
1515
1553
  webExtensions: []
1516
1554
  };
1555
+ const push = extension => {
1556
+ state$1.webExtensions.push(extension);
1557
+ };
1558
+ const get$2 = () => {
1559
+ return state$1.webExtensions;
1560
+ };
1517
1561
 
1518
1562
  const cache = Object.create(null);
1519
1563
  const id = 1;
@@ -1557,7 +1601,7 @@ const addWebExtension = async path => {
1557
1601
  const manifestPath = getWebManifestPath(path);
1558
1602
  const manifest = await getWebExtensionManifest(path, manifestPath);
1559
1603
  // TODO avoid mutation if possible
1560
- state$1.webExtensions.push(manifest);
1604
+ push(manifest);
1561
1605
  clear();
1562
1606
  return manifest;
1563
1607
  };
@@ -1580,7 +1624,7 @@ const createWebViewWorkerRpc2 = async (rpcInfo, port) => {
1580
1624
  // the two message ports
1581
1625
 
1582
1626
  // TODO have a way so that the worker already includes the webview api and the extension
1583
- // host subworker doesn't need to import the other file
1627
+ // host sub-worker doesn't need to import the other file
1584
1628
  await invokeAndTransfer('IpcParent.create', {
1585
1629
  method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
1586
1630
  name: rpcInfo.name,
@@ -1610,7 +1654,7 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
1610
1654
  // the two message ports
1611
1655
 
1612
1656
  // TODO have a way so that the worker already includes the webview api and the extension
1613
- // host subworker doesn't need to import the other file
1657
+ // host sub-worker doesn't need to import the other file
1614
1658
  await invokeAndTransfer$1('IpcParent.create', {
1615
1659
  method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
1616
1660
  name: rpcInfo.name,
@@ -1936,7 +1980,7 @@ const getColorThemeUri = (extensions, colorThemeId) => {
1936
1980
  };
1937
1981
 
1938
1982
  const getDynamicWebExtensions = () => {
1939
- return state$1.webExtensions;
1983
+ return get$2();
1940
1984
  };
1941
1985
 
1942
1986
  const getWebExtensionsUrl = assetDir => {
@@ -2061,7 +2105,7 @@ const createWebViewIpc = async webView => {
2061
2105
  port1,
2062
2106
  port2
2063
2107
  } = getPortTuple();
2064
- const rpcPromise = MessagePortRpcParent.create({
2108
+ const rpcPromise = create$3({
2065
2109
  commandMap: {},
2066
2110
  isMessagePortOpen: false,
2067
2111
  messagePort: port2
@@ -2082,8 +2126,8 @@ const getWebView = id => {
2082
2126
  // TODO if webViewId is provided,
2083
2127
  // 1. read file as blob
2084
2128
  // 2. send blob to webview
2085
- // 3. create objecturl in webview
2086
- // 4. send back objecturl to extension host worker
2129
+ // 3. create object URL in webview
2130
+ // 4. send back object URL to extension host worker
2087
2131
  // 5. provide objectUrl to extension
2088
2132
 
2089
2133
  const getRemoteUrlForWebView = async (uri, options = {}) => {
@@ -2098,7 +2142,7 @@ const getRemoteUrlForWebView = async (uri, options = {}) => {
2098
2142
  };
2099
2143
 
2100
2144
  const getRpcInfo = rpcId => {
2101
- const info = get$2(rpcId);
2145
+ const info = get$3(rpcId);
2102
2146
  if (!info) {
2103
2147
  throw new Error(`Rpc not found ${rpcId}`);
2104
2148
  }
@@ -2117,20 +2161,20 @@ const emptyStatus = {
2117
2161
  status: None
2118
2162
  };
2119
2163
  const getRuntimeStatus = extensionId => {
2120
- return get$3(extensionId) || emptyStatus;
2164
+ return get$4(extensionId) || emptyStatus;
2121
2165
  };
2122
2166
 
2123
2167
  const commandMapRef = {};
2124
2168
 
2125
2169
  const handleMessagePort = async port => {
2126
- await PlainMessagePortRpc.create({
2170
+ await create$8({
2127
2171
  commandMap: commandMapRef,
2128
2172
  messagePort: port
2129
2173
  });
2130
2174
  };
2131
2175
 
2132
2176
  const initializeExtensionHostWorker = async () => {
2133
- const rpc = await TransferMessagePortRpcParent.create({
2177
+ const rpc = await create$6({
2134
2178
  commandMap: commandMapRef,
2135
2179
  async send(port) {
2136
2180
  await sendMessagePortToExtensionHostWorker(port, 0);
@@ -2140,7 +2184,7 @@ const initializeExtensionHostWorker = async () => {
2140
2184
  };
2141
2185
 
2142
2186
  const initializeFileSystemWorker = async () => {
2143
- const rpc = await TransferMessagePortRpcParent.create({
2187
+ const rpc = await create$6({
2144
2188
  commandMap: commandMapRef,
2145
2189
  async send(port) {
2146
2190
  await sendMessagePortToFileSystemWorker(port, 0);
@@ -2149,23 +2193,29 @@ const initializeFileSystemWorker = async () => {
2149
2193
  set$5(rpc);
2150
2194
  };
2151
2195
 
2196
+ const getRpcRemote = async () => {
2197
+ const rpc = await create$4({
2198
+ commandMap: commandMapRef,
2199
+ type: 'shared-process'
2200
+ });
2201
+ return rpc;
2202
+ };
2203
+ const getRpcElectron = async () => {
2204
+ const rpc = create$7({
2205
+ commandMap: commandMapRef,
2206
+ async send(port) {
2207
+ await sendMessagePortToSharedProcess(port);
2208
+ }
2209
+ });
2210
+ return rpc;
2211
+ };
2152
2212
  const getRpc = async platform => {
2153
2213
  // TODO create connection to shared process
2154
2214
  if (platform === Remote) {
2155
- const rpc = await WebSocketRpcParent2.create({
2156
- commandMap: commandMapRef,
2157
- type: 'shared-process'
2158
- });
2159
- return rpc;
2215
+ return getRpcRemote();
2160
2216
  }
2161
2217
  if (platform === Electron) {
2162
- const rpc = TransferMessagePortRpcParent.create({
2163
- commandMap: commandMapRef,
2164
- async send(port) {
2165
- await sendMessagePortToSharedProcess(port);
2166
- }
2167
- });
2168
- return rpc;
2218
+ return getRpcElectron();
2169
2219
  }
2170
2220
  return undefined;
2171
2221
  };
@@ -2273,14 +2323,18 @@ const commandMap = {
2273
2323
  'Extensions.uninstall': uninstallExtension
2274
2324
  };
2275
2325
 
2276
- const listen = async () => {
2277
- Object.assign(commandMapRef, commandMap);
2278
- const rpc = await WebWorkerRpcClient.create({
2326
+ const initializeRendererWorker = async () => {
2327
+ const rpc = await create$2({
2279
2328
  commandMap: commandMap
2280
2329
  });
2281
2330
  set$4(rpc);
2282
2331
  };
2283
2332
 
2333
+ const listen = async () => {
2334
+ Object.assign(commandMapRef, commandMap);
2335
+ await initializeRendererWorker();
2336
+ };
2337
+
2284
2338
  const main = async () => {
2285
2339
  await listen();
2286
2340
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"