@lvce-editor/opener-worker 1.0.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.
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/openerWorkerMain.js +992 -0
- package/package.json +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lvce Editor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
const normalizeLine = line => {
|
|
2
|
+
if (line.startsWith('Error: ')) {
|
|
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$2 = '\n';
|
|
18
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
19
|
+
return string.indexOf(NewLine$2, 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;
|
|
37
|
+
};
|
|
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
|
+
|
|
57
|
+
const isMessagePort = value => {
|
|
58
|
+
return value && value instanceof MessagePort;
|
|
59
|
+
};
|
|
60
|
+
const isMessagePortMain = value => {
|
|
61
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
62
|
+
};
|
|
63
|
+
const isOffscreenCanvas = value => {
|
|
64
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
65
|
+
};
|
|
66
|
+
const isInstanceOf = (value, constructorName) => {
|
|
67
|
+
return value?.constructor?.name === constructorName;
|
|
68
|
+
};
|
|
69
|
+
const isSocket = value => {
|
|
70
|
+
return isInstanceOf(value, 'Socket');
|
|
71
|
+
};
|
|
72
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
73
|
+
const isTransferrable = value => {
|
|
74
|
+
for (const fn of transferrables) {
|
|
75
|
+
if (fn(value)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
};
|
|
81
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
82
|
+
if (!value) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (isTransferrable(value)) {
|
|
86
|
+
transferrables.push(value);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
walkValue(item, transferrables, isTransferrable);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'object') {
|
|
96
|
+
for (const property of Object.values(value)) {
|
|
97
|
+
walkValue(property, transferrables, isTransferrable);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const getTransferrables = value => {
|
|
103
|
+
const transferrables = [];
|
|
104
|
+
walkValue(value, transferrables, isTransferrable);
|
|
105
|
+
return transferrables;
|
|
106
|
+
};
|
|
107
|
+
const attachEvents = that => {
|
|
108
|
+
const handleMessage = (...args) => {
|
|
109
|
+
const data = that.getData(...args);
|
|
110
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
111
|
+
data
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
that.onMessage(handleMessage);
|
|
115
|
+
const handleClose = event => {
|
|
116
|
+
that.dispatchEvent(new Event('close'));
|
|
117
|
+
};
|
|
118
|
+
that.onClose(handleClose);
|
|
119
|
+
};
|
|
120
|
+
class Ipc extends EventTarget {
|
|
121
|
+
constructor(rawIpc) {
|
|
122
|
+
super();
|
|
123
|
+
this._rawIpc = rawIpc;
|
|
124
|
+
attachEvents(this);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
128
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
129
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
130
|
+
const NewLine$1 = '\n';
|
|
131
|
+
const joinLines$1 = lines => {
|
|
132
|
+
return lines.join(NewLine$1);
|
|
133
|
+
};
|
|
134
|
+
const RE_AT = /^\s+at/;
|
|
135
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
136
|
+
const isNormalStackLine = line => {
|
|
137
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
138
|
+
};
|
|
139
|
+
const getDetails = lines => {
|
|
140
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
141
|
+
if (index === -1) {
|
|
142
|
+
return {
|
|
143
|
+
actualMessage: joinLines$1(lines),
|
|
144
|
+
rest: []
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
let lastIndex = index - 1;
|
|
148
|
+
while (++lastIndex < lines.length) {
|
|
149
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
actualMessage: lines[index - 1],
|
|
155
|
+
rest: lines.slice(index, lastIndex)
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
const splitLines$1 = lines => {
|
|
159
|
+
return lines.split(NewLine$1);
|
|
160
|
+
};
|
|
161
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
162
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
163
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
164
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
165
|
+
};
|
|
166
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
167
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
168
|
+
};
|
|
169
|
+
const getMessageCodeBlock = stderr => {
|
|
170
|
+
const lines = splitLines$1(stderr);
|
|
171
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
172
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
173
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
174
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
175
|
+
return relevantMessage;
|
|
176
|
+
};
|
|
177
|
+
const isModuleNotFoundMessage = line => {
|
|
178
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
179
|
+
};
|
|
180
|
+
const getModuleNotFoundError = stderr => {
|
|
181
|
+
const lines = splitLines$1(stderr);
|
|
182
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
183
|
+
const message = lines[messageIndex];
|
|
184
|
+
return {
|
|
185
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
186
|
+
message
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const isModuleNotFoundError = stderr => {
|
|
190
|
+
if (!stderr) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
194
|
+
};
|
|
195
|
+
const isModulesSyntaxError = stderr => {
|
|
196
|
+
if (!stderr) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
200
|
+
};
|
|
201
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
202
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
203
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
204
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
205
|
+
};
|
|
206
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
207
|
+
const message = getMessageCodeBlock(stderr);
|
|
208
|
+
return {
|
|
209
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
210
|
+
message: `Incompatible native node module: ${message}`
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
const getModuleSyntaxError = () => {
|
|
214
|
+
return {
|
|
215
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
216
|
+
message: `ES Modules are not supported in electron`
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
220
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
221
|
+
return getNativeModuleErrorMessage(stderr);
|
|
222
|
+
}
|
|
223
|
+
if (isModulesSyntaxError(stderr)) {
|
|
224
|
+
return getModuleSyntaxError();
|
|
225
|
+
}
|
|
226
|
+
if (isModuleNotFoundError(stderr)) {
|
|
227
|
+
return getModuleNotFoundError(stderr);
|
|
228
|
+
}
|
|
229
|
+
const lines = splitLines$1(stderr);
|
|
230
|
+
const {
|
|
231
|
+
actualMessage,
|
|
232
|
+
rest
|
|
233
|
+
} = getDetails(lines);
|
|
234
|
+
return {
|
|
235
|
+
code: '',
|
|
236
|
+
message: actualMessage,
|
|
237
|
+
stack: rest
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
class IpcError extends VError {
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
243
|
+
if (stdout || stderr) {
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
const {
|
|
246
|
+
code,
|
|
247
|
+
message,
|
|
248
|
+
stack
|
|
249
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
250
|
+
const cause = new Error(message);
|
|
251
|
+
// @ts-ignore
|
|
252
|
+
cause.code = code;
|
|
253
|
+
cause.stack = stack;
|
|
254
|
+
super(cause, betterMessage);
|
|
255
|
+
} else {
|
|
256
|
+
super(betterMessage);
|
|
257
|
+
}
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
this.name = 'IpcError';
|
|
260
|
+
// @ts-ignore
|
|
261
|
+
this.stdout = stdout;
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
this.stderr = stderr;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const readyMessage = 'ready';
|
|
267
|
+
const getData$2 = event => {
|
|
268
|
+
return event.data;
|
|
269
|
+
};
|
|
270
|
+
const listen$7 = () => {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
273
|
+
throw new TypeError('module is not in web worker scope');
|
|
274
|
+
}
|
|
275
|
+
return globalThis;
|
|
276
|
+
};
|
|
277
|
+
const signal$8 = global => {
|
|
278
|
+
global.postMessage(readyMessage);
|
|
279
|
+
};
|
|
280
|
+
class IpcChildWithModuleWorker extends Ipc {
|
|
281
|
+
getData(event) {
|
|
282
|
+
return getData$2(event);
|
|
283
|
+
}
|
|
284
|
+
send(message) {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
this._rawIpc.postMessage(message);
|
|
287
|
+
}
|
|
288
|
+
sendAndTransfer(message) {
|
|
289
|
+
const transfer = getTransferrables(message);
|
|
290
|
+
// @ts-ignore
|
|
291
|
+
this._rawIpc.postMessage(message, transfer);
|
|
292
|
+
}
|
|
293
|
+
dispose() {
|
|
294
|
+
// ignore
|
|
295
|
+
}
|
|
296
|
+
onClose(callback) {
|
|
297
|
+
// ignore
|
|
298
|
+
}
|
|
299
|
+
onMessage(callback) {
|
|
300
|
+
this._rawIpc.addEventListener('message', callback);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const wrap$f = global => {
|
|
304
|
+
return new IpcChildWithModuleWorker(global);
|
|
305
|
+
};
|
|
306
|
+
const waitForFirstMessage = async port => {
|
|
307
|
+
const {
|
|
308
|
+
promise,
|
|
309
|
+
resolve
|
|
310
|
+
} = Promise.withResolvers();
|
|
311
|
+
port.addEventListener('message', resolve, {
|
|
312
|
+
once: true
|
|
313
|
+
});
|
|
314
|
+
const event = await promise;
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
return event.data;
|
|
317
|
+
};
|
|
318
|
+
const listen$6 = async () => {
|
|
319
|
+
const parentIpcRaw = listen$7();
|
|
320
|
+
signal$8(parentIpcRaw);
|
|
321
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
322
|
+
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
323
|
+
if (firstMessage.method !== 'initialize') {
|
|
324
|
+
throw new IpcError('unexpected first message');
|
|
325
|
+
}
|
|
326
|
+
const type = firstMessage.params[0];
|
|
327
|
+
if (type === 'message-port') {
|
|
328
|
+
parentIpc.send({
|
|
329
|
+
id: firstMessage.id,
|
|
330
|
+
jsonrpc: '2.0',
|
|
331
|
+
result: null
|
|
332
|
+
});
|
|
333
|
+
parentIpc.dispose();
|
|
334
|
+
const port = firstMessage.params[1];
|
|
335
|
+
return port;
|
|
336
|
+
}
|
|
337
|
+
return globalThis;
|
|
338
|
+
};
|
|
339
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
340
|
+
getData(event) {
|
|
341
|
+
return getData$2(event);
|
|
342
|
+
}
|
|
343
|
+
send(message) {
|
|
344
|
+
this._rawIpc.postMessage(message);
|
|
345
|
+
}
|
|
346
|
+
sendAndTransfer(message) {
|
|
347
|
+
const transfer = getTransferrables(message);
|
|
348
|
+
this._rawIpc.postMessage(message, transfer);
|
|
349
|
+
}
|
|
350
|
+
dispose() {
|
|
351
|
+
if (this._rawIpc.close) {
|
|
352
|
+
this._rawIpc.close();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
onClose(callback) {
|
|
356
|
+
// ignore
|
|
357
|
+
}
|
|
358
|
+
onMessage(callback) {
|
|
359
|
+
this._rawIpc.addEventListener('message', callback);
|
|
360
|
+
this._rawIpc.start();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const wrap$e = port => {
|
|
364
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
365
|
+
};
|
|
366
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
367
|
+
__proto__: null,
|
|
368
|
+
listen: listen$6,
|
|
369
|
+
wrap: wrap$e
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const Two$1 = '2.0';
|
|
373
|
+
const callbacks = Object.create(null);
|
|
374
|
+
const get$1 = id => {
|
|
375
|
+
return callbacks[id];
|
|
376
|
+
};
|
|
377
|
+
const remove$1 = id => {
|
|
378
|
+
delete callbacks[id];
|
|
379
|
+
};
|
|
380
|
+
class JsonRpcError extends Error {
|
|
381
|
+
constructor(message) {
|
|
382
|
+
super(message);
|
|
383
|
+
this.name = 'JsonRpcError';
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const NewLine = '\n';
|
|
387
|
+
const DomException = 'DOMException';
|
|
388
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
389
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
390
|
+
const TypeError$1 = 'TypeError';
|
|
391
|
+
const getErrorConstructor = (message, type) => {
|
|
392
|
+
if (type) {
|
|
393
|
+
switch (type) {
|
|
394
|
+
case DomException:
|
|
395
|
+
return DOMException;
|
|
396
|
+
case TypeError$1:
|
|
397
|
+
return TypeError;
|
|
398
|
+
case SyntaxError$1:
|
|
399
|
+
return SyntaxError;
|
|
400
|
+
case ReferenceError$1:
|
|
401
|
+
return ReferenceError;
|
|
402
|
+
default:
|
|
403
|
+
return Error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (message.startsWith('TypeError: ')) {
|
|
407
|
+
return TypeError;
|
|
408
|
+
}
|
|
409
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
410
|
+
return SyntaxError;
|
|
411
|
+
}
|
|
412
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
413
|
+
return ReferenceError;
|
|
414
|
+
}
|
|
415
|
+
return Error;
|
|
416
|
+
};
|
|
417
|
+
const constructError = (message, type, name) => {
|
|
418
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
419
|
+
if (ErrorConstructor === DOMException && name) {
|
|
420
|
+
return new ErrorConstructor(message, name);
|
|
421
|
+
}
|
|
422
|
+
if (ErrorConstructor === Error) {
|
|
423
|
+
const error = new Error(message);
|
|
424
|
+
if (name && name !== 'VError') {
|
|
425
|
+
error.name = name;
|
|
426
|
+
}
|
|
427
|
+
return error;
|
|
428
|
+
}
|
|
429
|
+
return new ErrorConstructor(message);
|
|
430
|
+
};
|
|
431
|
+
const joinLines = lines => {
|
|
432
|
+
return lines.join(NewLine);
|
|
433
|
+
};
|
|
434
|
+
const splitLines = lines => {
|
|
435
|
+
return lines.split(NewLine);
|
|
436
|
+
};
|
|
437
|
+
const getCurrentStack = () => {
|
|
438
|
+
const stackLinesToSkip = 3;
|
|
439
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
440
|
+
return currentStack;
|
|
441
|
+
};
|
|
442
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
443
|
+
return string.indexOf(NewLine, startIndex);
|
|
444
|
+
};
|
|
445
|
+
const getParentStack = error => {
|
|
446
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
447
|
+
if (parentStack.startsWith(' at')) {
|
|
448
|
+
parentStack = error.message + NewLine + parentStack;
|
|
449
|
+
}
|
|
450
|
+
return parentStack;
|
|
451
|
+
};
|
|
452
|
+
const MethodNotFound = -32601;
|
|
453
|
+
const Custom = -32001;
|
|
454
|
+
const restoreJsonRpcError = error => {
|
|
455
|
+
const currentStack = getCurrentStack();
|
|
456
|
+
if (error && error instanceof Error) {
|
|
457
|
+
if (typeof error.stack === 'string') {
|
|
458
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
459
|
+
}
|
|
460
|
+
return error;
|
|
461
|
+
}
|
|
462
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
463
|
+
const restoredError = new JsonRpcError(error.message);
|
|
464
|
+
const parentStack = getParentStack(error);
|
|
465
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
466
|
+
return restoredError;
|
|
467
|
+
}
|
|
468
|
+
if (error && error.message) {
|
|
469
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
470
|
+
if (error.data) {
|
|
471
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
472
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
473
|
+
} else if (error.data.stack) {
|
|
474
|
+
restoredError.stack = error.data.stack;
|
|
475
|
+
}
|
|
476
|
+
if (error.data.codeFrame) {
|
|
477
|
+
// @ts-ignore
|
|
478
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
479
|
+
}
|
|
480
|
+
if (error.data.code) {
|
|
481
|
+
// @ts-ignore
|
|
482
|
+
restoredError.code = error.data.code;
|
|
483
|
+
}
|
|
484
|
+
if (error.data.type) {
|
|
485
|
+
// @ts-ignore
|
|
486
|
+
restoredError.name = error.data.type;
|
|
487
|
+
}
|
|
488
|
+
} else {
|
|
489
|
+
if (error.stack) {
|
|
490
|
+
const lowerStack = restoredError.stack || '';
|
|
491
|
+
// @ts-ignore
|
|
492
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
493
|
+
const parentStack = getParentStack(error);
|
|
494
|
+
// @ts-ignore
|
|
495
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
496
|
+
}
|
|
497
|
+
if (error.codeFrame) {
|
|
498
|
+
// @ts-ignore
|
|
499
|
+
restoredError.codeFrame = error.codeFrame;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return restoredError;
|
|
503
|
+
}
|
|
504
|
+
if (typeof error === 'string') {
|
|
505
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
506
|
+
}
|
|
507
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
508
|
+
};
|
|
509
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
510
|
+
if ('error' in responseMessage) {
|
|
511
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
512
|
+
throw restoredError;
|
|
513
|
+
}
|
|
514
|
+
if ('result' in responseMessage) {
|
|
515
|
+
return responseMessage.result;
|
|
516
|
+
}
|
|
517
|
+
throw new JsonRpcError('unexpected response message');
|
|
518
|
+
};
|
|
519
|
+
const warn = (...args) => {
|
|
520
|
+
console.warn(...args);
|
|
521
|
+
};
|
|
522
|
+
const resolve = (id, response) => {
|
|
523
|
+
const fn = get$1(id);
|
|
524
|
+
if (!fn) {
|
|
525
|
+
console.log(response);
|
|
526
|
+
warn(`callback ${id} may already be disposed`);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
fn(response);
|
|
530
|
+
remove$1(id);
|
|
531
|
+
};
|
|
532
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
533
|
+
const getErrorType = prettyError => {
|
|
534
|
+
if (prettyError && prettyError.type) {
|
|
535
|
+
return prettyError.type;
|
|
536
|
+
}
|
|
537
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
538
|
+
return prettyError.constructor.name;
|
|
539
|
+
}
|
|
540
|
+
return undefined;
|
|
541
|
+
};
|
|
542
|
+
const isAlreadyStack = line => {
|
|
543
|
+
return line.trim().startsWith('at ');
|
|
544
|
+
};
|
|
545
|
+
const getStack = prettyError => {
|
|
546
|
+
const stackString = prettyError.stack || '';
|
|
547
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
548
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
549
|
+
return stackString.slice(newLineIndex + 1);
|
|
550
|
+
}
|
|
551
|
+
return stackString;
|
|
552
|
+
};
|
|
553
|
+
const getErrorProperty = (error, prettyError) => {
|
|
554
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
555
|
+
return {
|
|
556
|
+
code: MethodNotFound,
|
|
557
|
+
message: error.message,
|
|
558
|
+
data: error.stack
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
code: Custom,
|
|
563
|
+
message: prettyError.message,
|
|
564
|
+
data: {
|
|
565
|
+
stack: getStack(prettyError),
|
|
566
|
+
codeFrame: prettyError.codeFrame,
|
|
567
|
+
type: getErrorType(prettyError),
|
|
568
|
+
code: prettyError.code,
|
|
569
|
+
name: prettyError.name
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
};
|
|
573
|
+
const create$1$1 = (id, error) => {
|
|
574
|
+
return {
|
|
575
|
+
jsonrpc: Two$1,
|
|
576
|
+
id,
|
|
577
|
+
error
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
581
|
+
const prettyError = preparePrettyError(error);
|
|
582
|
+
logError(error, prettyError);
|
|
583
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
584
|
+
return create$1$1(id, errorProperty);
|
|
585
|
+
};
|
|
586
|
+
const create$2 = (message, result) => {
|
|
587
|
+
return {
|
|
588
|
+
jsonrpc: Two$1,
|
|
589
|
+
id: message.id,
|
|
590
|
+
result: result ?? null
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
const getSuccessResponse = (message, result) => {
|
|
594
|
+
const resultProperty = result ?? null;
|
|
595
|
+
return create$2(message, resultProperty);
|
|
596
|
+
};
|
|
597
|
+
const getErrorResponseSimple = (id, error) => {
|
|
598
|
+
return {
|
|
599
|
+
jsonrpc: Two$1,
|
|
600
|
+
id,
|
|
601
|
+
error: {
|
|
602
|
+
code: Custom,
|
|
603
|
+
// @ts-ignore
|
|
604
|
+
message: error.message,
|
|
605
|
+
data: error
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
610
|
+
try {
|
|
611
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
612
|
+
return getSuccessResponse(message, result);
|
|
613
|
+
} catch (error) {
|
|
614
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
615
|
+
return getErrorResponseSimple(message.id, error);
|
|
616
|
+
}
|
|
617
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
const defaultPreparePrettyError = error => {
|
|
621
|
+
return error;
|
|
622
|
+
};
|
|
623
|
+
const defaultLogError = () => {
|
|
624
|
+
// ignore
|
|
625
|
+
};
|
|
626
|
+
const defaultRequiresSocket = () => {
|
|
627
|
+
return false;
|
|
628
|
+
};
|
|
629
|
+
const defaultResolve = resolve;
|
|
630
|
+
|
|
631
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
632
|
+
const normalizeParams = args => {
|
|
633
|
+
if (args.length === 1) {
|
|
634
|
+
const options = args[0];
|
|
635
|
+
return {
|
|
636
|
+
ipc: options.ipc,
|
|
637
|
+
message: options.message,
|
|
638
|
+
execute: options.execute,
|
|
639
|
+
resolve: options.resolve || defaultResolve,
|
|
640
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
641
|
+
logError: options.logError || defaultLogError,
|
|
642
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
ipc: args[0],
|
|
647
|
+
message: args[1],
|
|
648
|
+
execute: args[2],
|
|
649
|
+
resolve: args[3],
|
|
650
|
+
preparePrettyError: args[4],
|
|
651
|
+
logError: args[5],
|
|
652
|
+
requiresSocket: args[6]
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
656
|
+
const options = normalizeParams(args);
|
|
657
|
+
const {
|
|
658
|
+
message,
|
|
659
|
+
ipc,
|
|
660
|
+
execute,
|
|
661
|
+
resolve,
|
|
662
|
+
preparePrettyError,
|
|
663
|
+
logError,
|
|
664
|
+
requiresSocket
|
|
665
|
+
} = options;
|
|
666
|
+
if ('id' in message) {
|
|
667
|
+
if ('method' in message) {
|
|
668
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
669
|
+
try {
|
|
670
|
+
ipc.send(response);
|
|
671
|
+
} catch (error) {
|
|
672
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
673
|
+
ipc.send(errorResponse);
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
resolve(message.id, message);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
if ('method' in message) {
|
|
681
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
throw new JsonRpcError('unexpected message');
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
class CommandNotFoundError extends Error {
|
|
688
|
+
constructor(command) {
|
|
689
|
+
super(`Command not found ${command}`);
|
|
690
|
+
this.name = 'CommandNotFoundError';
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const commands = Object.create(null);
|
|
694
|
+
const register = commandMap => {
|
|
695
|
+
Object.assign(commands, commandMap);
|
|
696
|
+
};
|
|
697
|
+
const getCommand = key => {
|
|
698
|
+
return commands[key];
|
|
699
|
+
};
|
|
700
|
+
const execute = (command, ...args) => {
|
|
701
|
+
const fn = getCommand(command);
|
|
702
|
+
if (!fn) {
|
|
703
|
+
throw new CommandNotFoundError(command);
|
|
704
|
+
}
|
|
705
|
+
return fn(...args);
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
const Two = '2.0';
|
|
709
|
+
const create$s = (method, params) => {
|
|
710
|
+
return {
|
|
711
|
+
jsonrpc: Two,
|
|
712
|
+
method,
|
|
713
|
+
params
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
const create$r = (id, method, params) => {
|
|
717
|
+
const message = {
|
|
718
|
+
id,
|
|
719
|
+
jsonrpc: Two,
|
|
720
|
+
method,
|
|
721
|
+
params
|
|
722
|
+
};
|
|
723
|
+
return message;
|
|
724
|
+
};
|
|
725
|
+
let id = 0;
|
|
726
|
+
const create$q = () => {
|
|
727
|
+
return ++id;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
731
|
+
|
|
732
|
+
const registerPromise = map => {
|
|
733
|
+
const id = create$q();
|
|
734
|
+
const {
|
|
735
|
+
promise,
|
|
736
|
+
resolve
|
|
737
|
+
} = Promise.withResolvers();
|
|
738
|
+
map[id] = resolve;
|
|
739
|
+
return {
|
|
740
|
+
id,
|
|
741
|
+
promise
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
// @ts-ignore
|
|
746
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
747
|
+
const {
|
|
748
|
+
id,
|
|
749
|
+
promise
|
|
750
|
+
} = registerPromise(callbacks);
|
|
751
|
+
const message = create$r(id, method, params);
|
|
752
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
|
+
ipc.sendAndTransfer(message);
|
|
754
|
+
} else {
|
|
755
|
+
ipc.send(message);
|
|
756
|
+
}
|
|
757
|
+
const responseMessage = await promise;
|
|
758
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
759
|
+
};
|
|
760
|
+
const createRpc = ipc => {
|
|
761
|
+
const callbacks = Object.create(null);
|
|
762
|
+
ipc._resolve = (id, response) => {
|
|
763
|
+
const fn = callbacks[id];
|
|
764
|
+
if (!fn) {
|
|
765
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
fn(response);
|
|
769
|
+
delete callbacks[id];
|
|
770
|
+
};
|
|
771
|
+
const rpc = {
|
|
772
|
+
async dispose() {
|
|
773
|
+
await ipc?.dispose();
|
|
774
|
+
},
|
|
775
|
+
invoke(method, ...params) {
|
|
776
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
777
|
+
},
|
|
778
|
+
invokeAndTransfer(method, ...params) {
|
|
779
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
780
|
+
},
|
|
781
|
+
// @ts-ignore
|
|
782
|
+
ipc,
|
|
783
|
+
/**
|
|
784
|
+
* @deprecated
|
|
785
|
+
*/
|
|
786
|
+
send(method, ...params) {
|
|
787
|
+
const message = create$s(method, params);
|
|
788
|
+
ipc.send(message);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
return rpc;
|
|
792
|
+
};
|
|
793
|
+
const requiresSocket = () => {
|
|
794
|
+
return false;
|
|
795
|
+
};
|
|
796
|
+
const preparePrettyError = error => {
|
|
797
|
+
return error;
|
|
798
|
+
};
|
|
799
|
+
const logError = () => {
|
|
800
|
+
// handled by renderer worker
|
|
801
|
+
};
|
|
802
|
+
const handleMessage = event => {
|
|
803
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
804
|
+
const actualExecute = event?.target?.execute || execute;
|
|
805
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
806
|
+
};
|
|
807
|
+
const handleIpc = ipc => {
|
|
808
|
+
if ('addEventListener' in ipc) {
|
|
809
|
+
ipc.addEventListener('message', handleMessage);
|
|
810
|
+
} else if ('on' in ipc) {
|
|
811
|
+
// deprecated
|
|
812
|
+
ipc.on('message', handleMessage);
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
const listen$1 = async (module, options) => {
|
|
816
|
+
const rawIpc = await module.listen(options);
|
|
817
|
+
if (module.signal) {
|
|
818
|
+
module.signal(rawIpc);
|
|
819
|
+
}
|
|
820
|
+
const ipc = module.wrap(rawIpc);
|
|
821
|
+
return ipc;
|
|
822
|
+
};
|
|
823
|
+
const create$1 = async ({
|
|
824
|
+
commandMap
|
|
825
|
+
}) => {
|
|
826
|
+
// TODO create a commandMap per rpc instance
|
|
827
|
+
register(commandMap);
|
|
828
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
829
|
+
handleIpc(ipc);
|
|
830
|
+
const rpc = createRpc(ipc);
|
|
831
|
+
return rpc;
|
|
832
|
+
};
|
|
833
|
+
const WebWorkerRpcClient = {
|
|
834
|
+
__proto__: null,
|
|
835
|
+
create: create$1
|
|
836
|
+
};
|
|
837
|
+
const createMockRpc = ({
|
|
838
|
+
commandMap
|
|
839
|
+
}) => {
|
|
840
|
+
const invocations = [];
|
|
841
|
+
const invoke = (method, ...params) => {
|
|
842
|
+
invocations.push([method, ...params]);
|
|
843
|
+
const command = commandMap[method];
|
|
844
|
+
if (!command) {
|
|
845
|
+
throw new Error(`command ${method} not found`);
|
|
846
|
+
}
|
|
847
|
+
return command(...params);
|
|
848
|
+
};
|
|
849
|
+
const mockRpc = {
|
|
850
|
+
invocations,
|
|
851
|
+
invoke,
|
|
852
|
+
invokeAndTransfer: invoke
|
|
853
|
+
};
|
|
854
|
+
return mockRpc;
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
const Electron = 2;
|
|
858
|
+
|
|
859
|
+
const RendererWorker = 1;
|
|
860
|
+
|
|
861
|
+
const rpcs = Object.create(null);
|
|
862
|
+
const set$2 = (id, rpc) => {
|
|
863
|
+
rpcs[id] = rpc;
|
|
864
|
+
};
|
|
865
|
+
const get = id => {
|
|
866
|
+
return rpcs[id];
|
|
867
|
+
};
|
|
868
|
+
const remove = id => {
|
|
869
|
+
delete rpcs[id];
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
873
|
+
const create = rpcId => {
|
|
874
|
+
return {
|
|
875
|
+
async dispose() {
|
|
876
|
+
const rpc = get(rpcId);
|
|
877
|
+
await rpc.dispose();
|
|
878
|
+
},
|
|
879
|
+
// @ts-ignore
|
|
880
|
+
invoke(method, ...params) {
|
|
881
|
+
const rpc = get(rpcId);
|
|
882
|
+
// @ts-ignore
|
|
883
|
+
return rpc.invoke(method, ...params);
|
|
884
|
+
},
|
|
885
|
+
// @ts-ignore
|
|
886
|
+
invokeAndTransfer(method, ...params) {
|
|
887
|
+
const rpc = get(rpcId);
|
|
888
|
+
// @ts-ignore
|
|
889
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
890
|
+
},
|
|
891
|
+
registerMockRpc(commandMap) {
|
|
892
|
+
const mockRpc = createMockRpc({
|
|
893
|
+
commandMap
|
|
894
|
+
});
|
|
895
|
+
set$2(rpcId, mockRpc);
|
|
896
|
+
// @ts-ignore
|
|
897
|
+
mockRpc[Symbol.dispose] = () => {
|
|
898
|
+
remove(rpcId);
|
|
899
|
+
};
|
|
900
|
+
// @ts-ignore
|
|
901
|
+
return mockRpc;
|
|
902
|
+
},
|
|
903
|
+
set(rpc) {
|
|
904
|
+
set$2(rpcId, rpc);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
const {
|
|
910
|
+
set: set$1
|
|
911
|
+
} = create(RendererWorker);
|
|
912
|
+
|
|
913
|
+
const openNew = async url => {
|
|
914
|
+
// TODO
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
const invoke$1 = async (method, ...params) => {
|
|
918
|
+
// TODO
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
const openExternal$1 = url => {
|
|
922
|
+
return invoke$1('OpenExternal.openExternal', url);
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
const OpenExternal = {
|
|
926
|
+
__proto__: null,
|
|
927
|
+
openExternal: openExternal$1
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
const platform = 0;
|
|
931
|
+
|
|
932
|
+
const invoke = async (method, ...params) => {
|
|
933
|
+
// TODO
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
const openUrlWeb = async url => {
|
|
937
|
+
try {
|
|
938
|
+
await invoke(/* Open.openUrl */'Open.openUrl', /* url */url);
|
|
939
|
+
} catch (error) {
|
|
940
|
+
throw new VError(error, `Failed to open url ${url}`);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
const openUrlElectron = async url => {
|
|
944
|
+
await openNew();
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
// TODO add required platform argument
|
|
948
|
+
const openUrl = async url => {
|
|
949
|
+
switch (platform) {
|
|
950
|
+
case Electron:
|
|
951
|
+
return openUrlElectron();
|
|
952
|
+
default:
|
|
953
|
+
return openUrlWeb(url);
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
const {
|
|
957
|
+
openExternal
|
|
958
|
+
} = OpenExternal;
|
|
959
|
+
|
|
960
|
+
let text = '';
|
|
961
|
+
const set = value => {
|
|
962
|
+
};
|
|
963
|
+
const readUrl = () => {
|
|
964
|
+
return text;
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
const readOpenedMemory = () => {
|
|
968
|
+
return readUrl();
|
|
969
|
+
};
|
|
970
|
+
const enable = () => {
|
|
971
|
+
return set();
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
const commandMap = {
|
|
975
|
+
'Open.enableMemoryOpener': enable,
|
|
976
|
+
'Open.openExternal': openExternal,
|
|
977
|
+
'Open.openUrl': openUrl,
|
|
978
|
+
'Open.readOpenedUrl': readOpenedMemory
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
const listen = async () => {
|
|
982
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
983
|
+
commandMap: commandMap
|
|
984
|
+
});
|
|
985
|
+
set$1(rpc);
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
const main = async () => {
|
|
989
|
+
await listen();
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lvce-editor/opener-worker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Menu Worker",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/lvce-editor/opener-worker.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Lvce Editor",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/openerWorkerMain.js"
|
|
13
|
+
}
|