@lvce-editor/extension-management-worker 3.1.0 → 3.3.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,58 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
return line.slice('Error: '.length);
|
|
4
|
-
}
|
|
5
|
-
if (line.startsWith('VError: ')) {
|
|
6
|
-
return line.slice('VError: '.length);
|
|
7
|
-
}
|
|
8
|
-
return line;
|
|
9
|
-
};
|
|
10
|
-
const getCombinedMessage = (error, message) => {
|
|
11
|
-
const stringifiedError = normalizeLine(`${error}`);
|
|
12
|
-
if (message) {
|
|
13
|
-
return `${message}: ${stringifiedError}`;
|
|
14
|
-
}
|
|
15
|
-
return stringifiedError;
|
|
16
|
-
};
|
|
17
|
-
const NewLine$3 = '\n';
|
|
18
|
-
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
19
|
-
return string.indexOf(NewLine$3, startIndex);
|
|
20
|
-
};
|
|
21
|
-
const mergeStacks = (parent, child) => {
|
|
22
|
-
if (!child) {
|
|
23
|
-
return parent;
|
|
24
|
-
}
|
|
25
|
-
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
26
|
-
const childNewLineIndex = getNewLineIndex$1(child);
|
|
27
|
-
if (childNewLineIndex === -1) {
|
|
28
|
-
return parent;
|
|
29
|
-
}
|
|
30
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
31
|
-
const childRest = child.slice(childNewLineIndex);
|
|
32
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
33
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
34
|
-
return parentFirstLine + childRest;
|
|
35
|
-
}
|
|
36
|
-
return child;
|
|
1
|
+
const activateByEvent = async () => {
|
|
2
|
+
// TODO
|
|
37
3
|
};
|
|
38
|
-
class VError extends Error {
|
|
39
|
-
constructor(error, message) {
|
|
40
|
-
const combinedMessage = getCombinedMessage(error, message);
|
|
41
|
-
super(combinedMessage);
|
|
42
|
-
this.name = 'VError';
|
|
43
|
-
if (error instanceof Error) {
|
|
44
|
-
this.stack = mergeStacks(this.stack, error.stack);
|
|
45
|
-
}
|
|
46
|
-
if (error.codeFrame) {
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
this.codeFrame = error.codeFrame;
|
|
49
|
-
}
|
|
50
|
-
if (error.code) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
this.code = error.code;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
4
|
|
|
57
5
|
class AssertionError extends Error {
|
|
58
6
|
constructor(message) {
|
|
@@ -109,6 +57,62 @@ const string = value => {
|
|
|
109
57
|
}
|
|
110
58
|
};
|
|
111
59
|
|
|
60
|
+
const normalizeLine = line => {
|
|
61
|
+
if (line.startsWith('Error: ')) {
|
|
62
|
+
return line.slice('Error: '.length);
|
|
63
|
+
}
|
|
64
|
+
if (line.startsWith('VError: ')) {
|
|
65
|
+
return line.slice('VError: '.length);
|
|
66
|
+
}
|
|
67
|
+
return line;
|
|
68
|
+
};
|
|
69
|
+
const getCombinedMessage = (error, message) => {
|
|
70
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
71
|
+
if (message) {
|
|
72
|
+
return `${message}: ${stringifiedError}`;
|
|
73
|
+
}
|
|
74
|
+
return stringifiedError;
|
|
75
|
+
};
|
|
76
|
+
const NewLine$3 = '\n';
|
|
77
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
78
|
+
return string.indexOf(NewLine$3, startIndex);
|
|
79
|
+
};
|
|
80
|
+
const mergeStacks = (parent, child) => {
|
|
81
|
+
if (!child) {
|
|
82
|
+
return parent;
|
|
83
|
+
}
|
|
84
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
85
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
86
|
+
if (childNewLineIndex === -1) {
|
|
87
|
+
return parent;
|
|
88
|
+
}
|
|
89
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
90
|
+
const childRest = child.slice(childNewLineIndex);
|
|
91
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
92
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
93
|
+
return parentFirstLine + childRest;
|
|
94
|
+
}
|
|
95
|
+
return child;
|
|
96
|
+
};
|
|
97
|
+
class VError extends Error {
|
|
98
|
+
constructor(error, message) {
|
|
99
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
100
|
+
super(combinedMessage);
|
|
101
|
+
this.name = 'VError';
|
|
102
|
+
if (error instanceof Error) {
|
|
103
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
104
|
+
}
|
|
105
|
+
if (error.codeFrame) {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
this.codeFrame = error.codeFrame;
|
|
108
|
+
}
|
|
109
|
+
if (error.code) {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
this.code = error.code;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
const isMessagePort = value => {
|
|
113
117
|
return value && value instanceof MessagePort;
|
|
114
118
|
};
|
|
@@ -540,7 +544,7 @@ const waitForWebSocketToBeOpen = webSocket => {
|
|
|
540
544
|
open: Open
|
|
541
545
|
});
|
|
542
546
|
};
|
|
543
|
-
const create$
|
|
547
|
+
const create$d = async ({
|
|
544
548
|
webSocket
|
|
545
549
|
}) => {
|
|
546
550
|
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
@@ -577,7 +581,7 @@ const wrap = webSocket => {
|
|
|
577
581
|
};
|
|
578
582
|
const IpcParentWithWebSocket$1 = {
|
|
579
583
|
__proto__: null,
|
|
580
|
-
create: create$
|
|
584
|
+
create: create$d,
|
|
581
585
|
wrap
|
|
582
586
|
};
|
|
583
587
|
|
|
@@ -816,7 +820,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
816
820
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
817
821
|
return create$1$1(id, errorProperty);
|
|
818
822
|
};
|
|
819
|
-
const create$
|
|
823
|
+
const create$c = (message, result) => {
|
|
820
824
|
return {
|
|
821
825
|
id: message.id,
|
|
822
826
|
jsonrpc: Two$1,
|
|
@@ -825,7 +829,7 @@ const create$b = (message, result) => {
|
|
|
825
829
|
};
|
|
826
830
|
const getSuccessResponse = (message, result) => {
|
|
827
831
|
const resultProperty = result ?? null;
|
|
828
|
-
return create$
|
|
832
|
+
return create$c(message, resultProperty);
|
|
829
833
|
};
|
|
830
834
|
const getErrorResponseSimple = (id, error) => {
|
|
831
835
|
return {
|
|
@@ -919,7 +923,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
919
923
|
|
|
920
924
|
const Two = '2.0';
|
|
921
925
|
|
|
922
|
-
const create$
|
|
926
|
+
const create$b = (method, params) => {
|
|
923
927
|
return {
|
|
924
928
|
jsonrpc: Two,
|
|
925
929
|
method,
|
|
@@ -927,7 +931,7 @@ const create$a = (method, params) => {
|
|
|
927
931
|
};
|
|
928
932
|
};
|
|
929
933
|
|
|
930
|
-
const create$
|
|
934
|
+
const create$a = (id, method, params) => {
|
|
931
935
|
const message = {
|
|
932
936
|
id,
|
|
933
937
|
jsonrpc: Two,
|
|
@@ -938,12 +942,12 @@ const create$9 = (id, method, params) => {
|
|
|
938
942
|
};
|
|
939
943
|
|
|
940
944
|
let id$1 = 0;
|
|
941
|
-
const create$
|
|
945
|
+
const create$9 = () => {
|
|
942
946
|
return ++id$1;
|
|
943
947
|
};
|
|
944
948
|
|
|
945
949
|
const registerPromise = map => {
|
|
946
|
-
const id = create$
|
|
950
|
+
const id = create$9();
|
|
947
951
|
const {
|
|
948
952
|
promise,
|
|
949
953
|
resolve
|
|
@@ -960,7 +964,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
960
964
|
id,
|
|
961
965
|
promise
|
|
962
966
|
} = registerPromise(callbacks);
|
|
963
|
-
const message = create$
|
|
967
|
+
const message = create$a(id, method, params);
|
|
964
968
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
965
969
|
ipc.sendAndTransfer(message);
|
|
966
970
|
} else {
|
|
@@ -996,7 +1000,7 @@ const createRpc = ipc => {
|
|
|
996
1000
|
* @deprecated
|
|
997
1001
|
*/
|
|
998
1002
|
send(method, ...params) {
|
|
999
|
-
const message = create$
|
|
1003
|
+
const message = create$b(method, params);
|
|
1000
1004
|
ipc.send(message);
|
|
1001
1005
|
}
|
|
1002
1006
|
};
|
|
@@ -1036,7 +1040,7 @@ const listen$1 = async (module, options) => {
|
|
|
1036
1040
|
return ipc;
|
|
1037
1041
|
};
|
|
1038
1042
|
|
|
1039
|
-
const create$
|
|
1043
|
+
const create$8 = async ({
|
|
1040
1044
|
commandMap,
|
|
1041
1045
|
isMessagePortOpen = true,
|
|
1042
1046
|
messagePort
|
|
@@ -1054,7 +1058,7 @@ const create$7 = async ({
|
|
|
1054
1058
|
return rpc;
|
|
1055
1059
|
};
|
|
1056
1060
|
|
|
1057
|
-
const create$
|
|
1061
|
+
const create$7 = async ({
|
|
1058
1062
|
commandMap,
|
|
1059
1063
|
isMessagePortOpen,
|
|
1060
1064
|
send
|
|
@@ -1064,13 +1068,55 @@ const create$6 = async ({
|
|
|
1064
1068
|
port2
|
|
1065
1069
|
} = new MessageChannel();
|
|
1066
1070
|
await send(port1);
|
|
1067
|
-
return create$
|
|
1071
|
+
return create$8({
|
|
1068
1072
|
commandMap,
|
|
1069
1073
|
isMessagePortOpen,
|
|
1070
1074
|
messagePort: port2
|
|
1071
1075
|
});
|
|
1072
1076
|
};
|
|
1073
1077
|
|
|
1078
|
+
const createSharedLazyRpc = factory => {
|
|
1079
|
+
let rpcPromise;
|
|
1080
|
+
const getOrCreate = () => {
|
|
1081
|
+
if (!rpcPromise) {
|
|
1082
|
+
rpcPromise = factory();
|
|
1083
|
+
}
|
|
1084
|
+
return rpcPromise;
|
|
1085
|
+
};
|
|
1086
|
+
return {
|
|
1087
|
+
async dispose() {
|
|
1088
|
+
const rpc = await getOrCreate();
|
|
1089
|
+
await rpc.dispose();
|
|
1090
|
+
},
|
|
1091
|
+
async invoke(method, ...params) {
|
|
1092
|
+
const rpc = await getOrCreate();
|
|
1093
|
+
return rpc.invoke(method, ...params);
|
|
1094
|
+
},
|
|
1095
|
+
async invokeAndTransfer(method, ...params) {
|
|
1096
|
+
const rpc = await getOrCreate();
|
|
1097
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1098
|
+
},
|
|
1099
|
+
async send(method, ...params) {
|
|
1100
|
+
const rpc = await getOrCreate();
|
|
1101
|
+
rpc.send(method, ...params);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
const create$6 = async ({
|
|
1107
|
+
commandMap,
|
|
1108
|
+
isMessagePortOpen,
|
|
1109
|
+
send
|
|
1110
|
+
}) => {
|
|
1111
|
+
return createSharedLazyRpc(() => {
|
|
1112
|
+
return create$7({
|
|
1113
|
+
commandMap,
|
|
1114
|
+
isMessagePortOpen,
|
|
1115
|
+
send
|
|
1116
|
+
});
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1074
1120
|
const Https = 'https:';
|
|
1075
1121
|
const Ws = 'ws:';
|
|
1076
1122
|
const Wss = 'wss:';
|
|
@@ -1251,6 +1297,10 @@ const {
|
|
|
1251
1297
|
invokeAndTransfer: invokeAndTransfer$1,
|
|
1252
1298
|
set: set$4
|
|
1253
1299
|
} = create$1(RendererWorker);
|
|
1300
|
+
const sendMessagePortToIconThemeWorker = async (port, rpcId) => {
|
|
1301
|
+
const command = 'IconTheme.handleMessagePort';
|
|
1302
|
+
await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToIconThemeWorker', port, command, rpcId);
|
|
1303
|
+
};
|
|
1254
1304
|
const sendMessagePortToFileSystemWorker = async (port, rpcId) => {
|
|
1255
1305
|
const command = 'FileSystem.handleMessagePort';
|
|
1256
1306
|
await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToFileSystemWorker', port, command, rpcId);
|
|
@@ -1513,10 +1563,15 @@ const state$1 = {
|
|
|
1513
1563
|
const push = extension => {
|
|
1514
1564
|
state$1.webExtensions.push(extension);
|
|
1515
1565
|
};
|
|
1566
|
+
const hasUri = uri => {
|
|
1567
|
+
return state$1.webExtensions.some(extension => extension.uri === uri);
|
|
1568
|
+
};
|
|
1516
1569
|
const get$2 = () => {
|
|
1517
1570
|
return state$1.webExtensions;
|
|
1518
1571
|
};
|
|
1519
1572
|
|
|
1573
|
+
// TODO store one kind of ui state for whole extension management worker
|
|
1574
|
+
|
|
1520
1575
|
const cache = Object.create(null);
|
|
1521
1576
|
const id = 1;
|
|
1522
1577
|
const clear = () => {
|
|
@@ -1556,6 +1611,9 @@ const getWebManifestPath = path => {
|
|
|
1556
1611
|
};
|
|
1557
1612
|
|
|
1558
1613
|
const addWebExtension = async path => {
|
|
1614
|
+
if (hasUri(path)) {
|
|
1615
|
+
return undefined;
|
|
1616
|
+
}
|
|
1559
1617
|
const manifestPath = getWebManifestPath(path);
|
|
1560
1618
|
const manifest = await getWebExtensionManifest(path, manifestPath);
|
|
1561
1619
|
// TODO avoid mutation if possible
|
|
@@ -2125,49 +2183,35 @@ const getRuntimeStatus = extensionId => {
|
|
|
2125
2183
|
const commandMapRef = {};
|
|
2126
2184
|
|
|
2127
2185
|
const handleMessagePort = async port => {
|
|
2128
|
-
await create$
|
|
2186
|
+
await create$8({
|
|
2129
2187
|
commandMap: commandMapRef,
|
|
2130
2188
|
messagePort: port
|
|
2131
2189
|
});
|
|
2132
2190
|
};
|
|
2133
2191
|
|
|
2134
|
-
const
|
|
2135
|
-
const rpc = await create$
|
|
2192
|
+
const getRpcRemote = async () => {
|
|
2193
|
+
const rpc = await create$4({
|
|
2136
2194
|
commandMap: commandMapRef,
|
|
2137
|
-
|
|
2138
|
-
await sendMessagePortToExtensionHostWorker(port, 0);
|
|
2139
|
-
}
|
|
2195
|
+
type: 'shared-process'
|
|
2140
2196
|
});
|
|
2141
|
-
|
|
2197
|
+
return rpc;
|
|
2142
2198
|
};
|
|
2143
|
-
|
|
2144
|
-
const
|
|
2145
|
-
const rpc = await create$6({
|
|
2199
|
+
const getRpcElectron = async () => {
|
|
2200
|
+
const rpc = create$7({
|
|
2146
2201
|
commandMap: commandMapRef,
|
|
2147
2202
|
async send(port) {
|
|
2148
|
-
await
|
|
2203
|
+
await sendMessagePortToSharedProcess(port);
|
|
2149
2204
|
}
|
|
2150
2205
|
});
|
|
2151
|
-
|
|
2206
|
+
return rpc;
|
|
2152
2207
|
};
|
|
2153
|
-
|
|
2154
2208
|
const getRpc = async platform => {
|
|
2155
2209
|
// TODO create connection to shared process
|
|
2156
2210
|
if (platform === Remote) {
|
|
2157
|
-
|
|
2158
|
-
commandMap: commandMapRef,
|
|
2159
|
-
type: 'shared-process'
|
|
2160
|
-
});
|
|
2161
|
-
return rpc;
|
|
2211
|
+
return getRpcRemote();
|
|
2162
2212
|
}
|
|
2163
2213
|
if (platform === Electron) {
|
|
2164
|
-
|
|
2165
|
-
commandMap: commandMapRef,
|
|
2166
|
-
async send(port) {
|
|
2167
|
-
await sendMessagePortToSharedProcess(port);
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
|
-
return rpc;
|
|
2214
|
+
return getRpcElectron();
|
|
2171
2215
|
}
|
|
2172
2216
|
return undefined;
|
|
2173
2217
|
};
|
|
@@ -2182,7 +2226,7 @@ const initialize = async platform => {
|
|
|
2182
2226
|
update({
|
|
2183
2227
|
platform
|
|
2184
2228
|
});
|
|
2185
|
-
await
|
|
2229
|
+
await initializeSharedProcess(platform);
|
|
2186
2230
|
};
|
|
2187
2231
|
|
|
2188
2232
|
const installExtension = async () => {
|
|
@@ -2249,6 +2293,7 @@ const uninstallExtension = async () => {
|
|
|
2249
2293
|
const commandMap = {
|
|
2250
2294
|
'Extensions.activate2': activateExtension2,
|
|
2251
2295
|
'Extensions.activate3': activateExtension3,
|
|
2296
|
+
'Extensions.activateByEvent': activateByEvent,
|
|
2252
2297
|
'Extensions.addWebExtension': addWebExtension,
|
|
2253
2298
|
'Extensions.createWebViewWorkerRpc': createWebViewWorkerRpc,
|
|
2254
2299
|
'Extensions.createWebViewWorkerRpc2': createWebViewWorkerRpc2,
|
|
@@ -2275,14 +2320,48 @@ const commandMap = {
|
|
|
2275
2320
|
'Extensions.uninstall': uninstallExtension
|
|
2276
2321
|
};
|
|
2277
2322
|
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2323
|
+
const initializeExtensionHostWorker = async () => {
|
|
2324
|
+
const rpc = await create$6({
|
|
2325
|
+
commandMap: commandMapRef,
|
|
2326
|
+
async send(port) {
|
|
2327
|
+
await sendMessagePortToExtensionHostWorker(port, 0);
|
|
2328
|
+
}
|
|
2329
|
+
});
|
|
2330
|
+
set$6(rpc);
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
const initializeFileSystemWorker = async () => {
|
|
2334
|
+
const rpc = await create$6({
|
|
2335
|
+
commandMap: commandMapRef,
|
|
2336
|
+
async send(port) {
|
|
2337
|
+
await sendMessagePortToFileSystemWorker(port, 0);
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
set$5(rpc);
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
const initializeIframeWorker = async () => {
|
|
2344
|
+
const rpc = await create$6({
|
|
2345
|
+
commandMap: {},
|
|
2346
|
+
async send(port) {
|
|
2347
|
+
await sendMessagePortToIconThemeWorker(port, 0);
|
|
2348
|
+
}
|
|
2349
|
+
});
|
|
2350
|
+
return rpc;
|
|
2351
|
+
};
|
|
2352
|
+
|
|
2353
|
+
const initializeRendererWorker = async () => {
|
|
2280
2354
|
const rpc = await create$2({
|
|
2281
2355
|
commandMap: commandMap
|
|
2282
2356
|
});
|
|
2283
2357
|
set$4(rpc);
|
|
2284
2358
|
};
|
|
2285
2359
|
|
|
2360
|
+
const listen = async () => {
|
|
2361
|
+
Object.assign(commandMapRef, commandMap);
|
|
2362
|
+
await Promise.all([initializeRendererWorker(), initializeFileSystemWorker(), initializeIframeWorker(), initializeExtensionHostWorker()]);
|
|
2363
|
+
};
|
|
2364
|
+
|
|
2286
2365
|
const main = async () => {
|
|
2287
2366
|
await listen();
|
|
2288
2367
|
};
|