@lvce-editor/ipc 3.5.0 → 3.7.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/dist/browser.js +214 -17
- package/dist/index.js +11 -9
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const getData = event => {
|
|
1
|
+
const getData$1 = event => {
|
|
2
2
|
return event.data;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const readyMessage = 'ready';
|
|
6
|
+
|
|
7
|
+
const listen$2 = () => {
|
|
6
8
|
// @ts-ignore
|
|
7
9
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
8
10
|
throw new TypeError('module is not in web worker scope');
|
|
9
11
|
}
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
globalThis.postMessage('ready');
|
|
12
12
|
return globalThis;
|
|
13
13
|
};
|
|
14
|
-
const signal = global => {
|
|
15
|
-
global.postMessage(
|
|
14
|
+
const signal$1 = global => {
|
|
15
|
+
global.postMessage(readyMessage);
|
|
16
16
|
};
|
|
17
|
-
const wrap$
|
|
17
|
+
const wrap$3 = global => {
|
|
18
18
|
return {
|
|
19
19
|
global,
|
|
20
20
|
/**
|
|
@@ -32,7 +32,7 @@ const wrap$1 = global => {
|
|
|
32
32
|
},
|
|
33
33
|
set onmessage(listener) {
|
|
34
34
|
const wrappedListener = event => {
|
|
35
|
-
const data = getData(event);
|
|
35
|
+
const data = getData$1(event);
|
|
36
36
|
// @ts-expect-error
|
|
37
37
|
listener({
|
|
38
38
|
data,
|
|
@@ -47,9 +47,9 @@ const wrap$1 = global => {
|
|
|
47
47
|
|
|
48
48
|
const IpcChildWithModuleWorker = {
|
|
49
49
|
__proto__: null,
|
|
50
|
-
listen: listen$
|
|
51
|
-
signal,
|
|
52
|
-
wrap: wrap$
|
|
50
|
+
listen: listen$2,
|
|
51
|
+
signal: signal$1,
|
|
52
|
+
wrap: wrap$3
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
@@ -282,9 +282,9 @@ const waitForFirstMessage = async port => {
|
|
|
282
282
|
return event.data;
|
|
283
283
|
};
|
|
284
284
|
|
|
285
|
-
const listen = async () => {
|
|
286
|
-
const parentIpcRaw = listen$
|
|
287
|
-
const parentIpc = wrap$
|
|
285
|
+
const listen$1 = async () => {
|
|
286
|
+
const parentIpcRaw = listen$2();
|
|
287
|
+
const parentIpc = wrap$3(parentIpcRaw);
|
|
288
288
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
289
289
|
if (firstMessage.method !== 'initialize') {
|
|
290
290
|
throw new IpcError('unexpected first message');
|
|
@@ -296,7 +296,7 @@ const listen = async () => {
|
|
|
296
296
|
}
|
|
297
297
|
return globalThis;
|
|
298
298
|
};
|
|
299
|
-
const wrap = port => {
|
|
299
|
+
const wrap$2 = port => {
|
|
300
300
|
return {
|
|
301
301
|
port,
|
|
302
302
|
/**
|
|
@@ -316,7 +316,7 @@ const wrap = port => {
|
|
|
316
316
|
if (listener) {
|
|
317
317
|
// @ts-expect-error
|
|
318
318
|
this.wrappedListener = event => {
|
|
319
|
-
const data = getData(event);
|
|
319
|
+
const data = getData$1(event);
|
|
320
320
|
// @ts-expect-error
|
|
321
321
|
listener({
|
|
322
322
|
data,
|
|
@@ -332,9 +332,206 @@ const wrap = port => {
|
|
|
332
332
|
};
|
|
333
333
|
|
|
334
334
|
const IpcChildWithModuleWorkerAndMessagePort = {
|
|
335
|
+
__proto__: null,
|
|
336
|
+
listen: listen$1,
|
|
337
|
+
wrap: wrap$2
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const listen = () => {
|
|
341
|
+
// @ts-ignore
|
|
342
|
+
return window;
|
|
343
|
+
};
|
|
344
|
+
const signal = global => {
|
|
345
|
+
global.postMessage(readyMessage);
|
|
346
|
+
};
|
|
347
|
+
const wrap$1 = window => {
|
|
348
|
+
return {
|
|
349
|
+
window,
|
|
350
|
+
/**
|
|
351
|
+
* @type {any}
|
|
352
|
+
*/
|
|
353
|
+
listener: undefined,
|
|
354
|
+
get onmessage() {
|
|
355
|
+
return this.listener;
|
|
356
|
+
},
|
|
357
|
+
set onmessage(listener) {
|
|
358
|
+
this.listener = listener;
|
|
359
|
+
const wrappedListener = event => {
|
|
360
|
+
const data = event.data;
|
|
361
|
+
if ('method' in data) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
// @ts-ignore
|
|
365
|
+
listener({
|
|
366
|
+
data,
|
|
367
|
+
target: this
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
this.window.onmessage = wrappedListener;
|
|
371
|
+
},
|
|
372
|
+
send(message) {
|
|
373
|
+
this.window.postMessage(message);
|
|
374
|
+
},
|
|
375
|
+
sendAndTransfer(message, transfer) {
|
|
376
|
+
this.window.postMessage(message, '*', transfer);
|
|
377
|
+
},
|
|
378
|
+
dispose() {
|
|
379
|
+
this.window.onmessage = null;
|
|
380
|
+
this.window = undefined;
|
|
381
|
+
this.listener = undefined;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const IpcChildWithWindow = {
|
|
335
387
|
__proto__: null,
|
|
336
388
|
listen,
|
|
389
|
+
signal,
|
|
390
|
+
wrap: wrap$1
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const Message = 'message';
|
|
394
|
+
const Error$1 = 'error';
|
|
395
|
+
|
|
396
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
397
|
+
const {
|
|
398
|
+
resolve,
|
|
399
|
+
promise
|
|
400
|
+
} = withResolvers();
|
|
401
|
+
const listenerMap = Object.create(null);
|
|
402
|
+
// @ts-ignore
|
|
403
|
+
const cleanup = value => {
|
|
404
|
+
for (const event of Object.keys(eventMap)) {
|
|
405
|
+
eventEmitter.off(event, listenerMap[event]);
|
|
406
|
+
}
|
|
407
|
+
// @ts-ignore
|
|
408
|
+
resolve(value);
|
|
409
|
+
};
|
|
410
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
411
|
+
// @ts-ignore
|
|
412
|
+
const listener = event => {
|
|
413
|
+
cleanup({
|
|
414
|
+
type,
|
|
415
|
+
event
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
eventEmitter.on(event, listener);
|
|
419
|
+
listenerMap[event] = listener;
|
|
420
|
+
}
|
|
421
|
+
return promise;
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const getFirstWorkerEvent = worker => {
|
|
425
|
+
return getFirstEvent(worker, {
|
|
426
|
+
message: Message,
|
|
427
|
+
error: Error$1
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const isErrorEvent = event => {
|
|
432
|
+
return event instanceof ErrorEvent;
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const getWorkerDisplayName = name => {
|
|
436
|
+
if (!name) {
|
|
437
|
+
return '<unknown> worker';
|
|
438
|
+
}
|
|
439
|
+
if (name.endsWith('Worker') || name.endsWith('worker')) {
|
|
440
|
+
return name.toLowerCase();
|
|
441
|
+
}
|
|
442
|
+
return `${name} Worker`;
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const tryToGetActualErrorMessage = async ({
|
|
446
|
+
name
|
|
447
|
+
}) => {
|
|
448
|
+
const displayName = getWorkerDisplayName(name);
|
|
449
|
+
return `Failed to start ${displayName}: Worker Launch Error`;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
class WorkerError extends Error {
|
|
453
|
+
constructor(event) {
|
|
454
|
+
super(event.message);
|
|
455
|
+
const stackLines = splitLines(this.stack || '');
|
|
456
|
+
const relevantLines = stackLines.slice(1);
|
|
457
|
+
const relevant = joinLines(relevantLines);
|
|
458
|
+
this.stack = `${event.message}
|
|
459
|
+
at Module (${event.filename}:${event.lineno}:${event.colno})
|
|
460
|
+
${relevant}`;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const Module = 'module';
|
|
465
|
+
|
|
466
|
+
const create = async ({
|
|
467
|
+
url,
|
|
468
|
+
name
|
|
469
|
+
}) => {
|
|
470
|
+
const worker = new Worker(url, {
|
|
471
|
+
type: Module,
|
|
472
|
+
name
|
|
473
|
+
});
|
|
474
|
+
const {
|
|
475
|
+
type,
|
|
476
|
+
event
|
|
477
|
+
} = await getFirstWorkerEvent(worker);
|
|
478
|
+
switch (type) {
|
|
479
|
+
case Message:
|
|
480
|
+
if (event.data !== readyMessage) {
|
|
481
|
+
throw new IpcError('unexpected first message from worker');
|
|
482
|
+
}
|
|
483
|
+
break;
|
|
484
|
+
case Error$1:
|
|
485
|
+
if (isErrorEvent(event)) {
|
|
486
|
+
throw new WorkerError(event);
|
|
487
|
+
}
|
|
488
|
+
const actualErrorMessage = await tryToGetActualErrorMessage({
|
|
489
|
+
name
|
|
490
|
+
});
|
|
491
|
+
throw new Error(actualErrorMessage);
|
|
492
|
+
}
|
|
493
|
+
return worker;
|
|
494
|
+
};
|
|
495
|
+
const getData = event => {
|
|
496
|
+
// TODO why are some events not instance of message event?
|
|
497
|
+
if (event instanceof MessageEvent) {
|
|
498
|
+
return event.data;
|
|
499
|
+
}
|
|
500
|
+
return event;
|
|
501
|
+
};
|
|
502
|
+
const wrap = worker => {
|
|
503
|
+
let handleMessage;
|
|
504
|
+
return {
|
|
505
|
+
get onmessage() {
|
|
506
|
+
return handleMessage;
|
|
507
|
+
},
|
|
508
|
+
set onmessage(listener) {
|
|
509
|
+
if (listener) {
|
|
510
|
+
handleMessage = event => {
|
|
511
|
+
const data = getData(event);
|
|
512
|
+
listener({
|
|
513
|
+
data,
|
|
514
|
+
target: this
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
} else {
|
|
518
|
+
handleMessage = null;
|
|
519
|
+
}
|
|
520
|
+
worker.onmessage = handleMessage;
|
|
521
|
+
},
|
|
522
|
+
send(message) {
|
|
523
|
+
worker.postMessage(message);
|
|
524
|
+
},
|
|
525
|
+
sendAndTransfer(message, transfer) {
|
|
526
|
+
worker.postMessage(message, transfer);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
const IpcParentWithModuleWorker = {
|
|
532
|
+
__proto__: null,
|
|
533
|
+
create,
|
|
337
534
|
wrap
|
|
338
535
|
};
|
|
339
536
|
|
|
340
|
-
export { IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort };
|
|
537
|
+
export { IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow, IpcParentWithModuleWorker };
|
package/dist/index.js
CHANGED
|
@@ -232,6 +232,8 @@ const getUtilityProcessPortData = event => {
|
|
|
232
232
|
};
|
|
233
233
|
};
|
|
234
234
|
|
|
235
|
+
const readyMessage = 'ready';
|
|
236
|
+
|
|
235
237
|
const listen$6 = () => {
|
|
236
238
|
// @ts-ignore
|
|
237
239
|
const {
|
|
@@ -245,7 +247,7 @@ const listen$6 = () => {
|
|
|
245
247
|
|
|
246
248
|
// @ts-ignore
|
|
247
249
|
const signal$3 = parentPort => {
|
|
248
|
-
parentPort.postMessage(
|
|
250
|
+
parentPort.postMessage(readyMessage);
|
|
249
251
|
};
|
|
250
252
|
|
|
251
253
|
// @ts-ignore
|
|
@@ -301,12 +303,10 @@ const listen$5 = () => {
|
|
|
301
303
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
302
304
|
throw new TypeError('module is not in web worker scope');
|
|
303
305
|
}
|
|
304
|
-
// @ts-ignore
|
|
305
|
-
globalThis.postMessage('ready');
|
|
306
306
|
return globalThis;
|
|
307
307
|
};
|
|
308
308
|
const signal$2 = global => {
|
|
309
|
-
global.postMessage(
|
|
309
|
+
global.postMessage(readyMessage);
|
|
310
310
|
};
|
|
311
311
|
const wrap$8 = global => {
|
|
312
312
|
return {
|
|
@@ -439,7 +439,7 @@ const listen$3 = async () => {
|
|
|
439
439
|
|
|
440
440
|
// @ts-ignore
|
|
441
441
|
const signal$1 = process => {
|
|
442
|
-
process.send(
|
|
442
|
+
process.send(readyMessage);
|
|
443
443
|
};
|
|
444
444
|
|
|
445
445
|
// @ts-ignore
|
|
@@ -540,7 +540,7 @@ const listen$1 = async () => {
|
|
|
540
540
|
return parentPort;
|
|
541
541
|
};
|
|
542
542
|
const signal = parentPort => {
|
|
543
|
-
parentPort.postMessage(
|
|
543
|
+
parentPort.postMessage(readyMessage);
|
|
544
544
|
};
|
|
545
545
|
const wrap$4 = parentPort => {
|
|
546
546
|
return {
|
|
@@ -803,7 +803,8 @@ const create$2 = async ({
|
|
|
803
803
|
path,
|
|
804
804
|
argv = [],
|
|
805
805
|
execArgv = [],
|
|
806
|
-
name
|
|
806
|
+
name,
|
|
807
|
+
env = process.env
|
|
807
808
|
}) => {
|
|
808
809
|
string(path);
|
|
809
810
|
const actualArgv = ['--ipc-type=electron-utility-process', ...argv];
|
|
@@ -814,7 +815,8 @@ const create$2 = async ({
|
|
|
814
815
|
const childProcess = utilityProcess.fork(path, actualArgv, {
|
|
815
816
|
execArgv,
|
|
816
817
|
stdio: 'pipe',
|
|
817
|
-
serviceName: name
|
|
818
|
+
serviceName: name,
|
|
819
|
+
env
|
|
818
820
|
});
|
|
819
821
|
// @ts-ignore
|
|
820
822
|
childProcess.stdout.pipe(process.stdout);
|
|
@@ -1077,7 +1079,7 @@ const create = async ({
|
|
|
1077
1079
|
if (type === Error$1) {
|
|
1078
1080
|
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
1079
1081
|
}
|
|
1080
|
-
if (event !==
|
|
1082
|
+
if (event !== readyMessage) {
|
|
1081
1083
|
throw new IpcError('unexpected first message from worker');
|
|
1082
1084
|
}
|
|
1083
1085
|
return worker;
|