@lvce-editor/ipc 12.2.0 → 13.1.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/index.d.ts CHANGED
@@ -33,3 +33,4 @@ export const IpcParentWithElectronMessagePort: IpcParent
33
33
  export const IpcParentWithMessagePort: IpcParent
34
34
  export const IpcParentWithWebSocket: IpcParent
35
35
  export const IpcParentWithModuleWorker: IpcParent
36
+ export const IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug: IpcParent
package/dist/index.js CHANGED
@@ -1,28 +1,6 @@
1
1
  import { VError } from '@lvce-editor/verror';
2
2
  import { string } from '@lvce-editor/assert';
3
3
 
4
- const walkValue = (value, transferrables, isTransferrable) => {
5
- if (!value) {
6
- return;
7
- }
8
- if (isTransferrable(value)) {
9
- transferrables.push(value);
10
- return;
11
- }
12
- if (Array.isArray(value)) {
13
- for (const item of value) {
14
- walkValue(item, transferrables, isTransferrable);
15
- }
16
- return;
17
- }
18
- if (typeof value === 'object') {
19
- for (const property of Object.values(value)) {
20
- walkValue(property, transferrables, isTransferrable);
21
- }
22
- return;
23
- }
24
- };
25
-
26
4
  const isMessagePort = value => {
27
5
  return value && value instanceof MessagePort;
28
6
  };
@@ -54,6 +32,28 @@ const isTransferrable = value => {
54
32
  return false;
55
33
  };
56
34
 
35
+ const walkValue = (value, transferrables, isTransferrable) => {
36
+ if (!value) {
37
+ return;
38
+ }
39
+ if (isTransferrable(value)) {
40
+ transferrables.push(value);
41
+ return;
42
+ }
43
+ if (Array.isArray(value)) {
44
+ for (const item of value) {
45
+ walkValue(item, transferrables, isTransferrable);
46
+ }
47
+ return;
48
+ }
49
+ if (typeof value === 'object') {
50
+ for (const property of Object.values(value)) {
51
+ walkValue(property, transferrables, isTransferrable);
52
+ }
53
+ return;
54
+ }
55
+ };
56
+
57
57
  const getTransferrables = value => {
58
58
  const transferrables = [];
59
59
  walkValue(value, transferrables, isTransferrable);
@@ -143,32 +143,37 @@ const joinLines = lines => {
143
143
  return lines.join(NewLine);
144
144
  };
145
145
 
146
- const splitLines = lines => {
147
- return lines.split(NewLine);
148
- };
149
-
150
- const isModuleNotFoundMessage = line => {
151
- return line.includes('[ERR_MODULE_NOT_FOUND]');
146
+ const RE_AT = /^\s+at/;
147
+ const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
148
+ const isNormalStackLine = line => {
149
+ return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
152
150
  };
153
- const getModuleNotFoundError = stderr => {
154
- const lines = splitLines(stderr);
155
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
156
- const message = lines[messageIndex];
151
+ const getDetails = lines => {
152
+ const index = lines.findIndex(isNormalStackLine);
153
+ if (index === -1) {
154
+ return {
155
+ actualMessage: joinLines(lines),
156
+ rest: []
157
+ };
158
+ }
159
+ let lastIndex = index - 1;
160
+ while (++lastIndex < lines.length) {
161
+ if (!isNormalStackLine(lines[lastIndex])) {
162
+ break;
163
+ }
164
+ }
157
165
  return {
158
- message,
159
- code: ERR_MODULE_NOT_FOUND
166
+ actualMessage: lines[index - 1],
167
+ rest: lines.slice(index, lastIndex)
160
168
  };
161
169
  };
162
170
 
163
- const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
164
- const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
171
+ const splitLines = lines => {
172
+ return lines.split(NewLine);
173
+ };
174
+
165
175
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
166
176
  const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
167
- const RE_AT = /^\s+at/;
168
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
169
- const isUnhelpfulNativeModuleError = stderr => {
170
- return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
171
- };
172
177
  const isMessageCodeBlockStartIndex = line => {
173
178
  return RE_MESSAGE_CODE_BLOCK_START.test(line);
174
179
  };
@@ -183,51 +188,51 @@ const getMessageCodeBlock = stderr => {
183
188
  const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
184
189
  return relevantMessage;
185
190
  };
186
- const getNativeModuleErrorMessage = stderr => {
187
- const message = getMessageCodeBlock(stderr);
191
+
192
+ const isModuleNotFoundMessage = line => {
193
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
194
+ };
195
+ const getModuleNotFoundError = stderr => {
196
+ const lines = splitLines(stderr);
197
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
198
+ const message = lines[messageIndex];
188
199
  return {
189
- message: `Incompatible native node module: ${message}`,
190
- code: E_INCOMPATIBLE_NATIVE_MODULE
200
+ message,
201
+ code: ERR_MODULE_NOT_FOUND
191
202
  };
192
203
  };
193
- const isModulesSyntaxError = stderr => {
204
+
205
+ const isModuleNotFoundError = stderr => {
194
206
  if (!stderr) {
195
207
  return false;
196
208
  }
197
- return stderr.includes('SyntaxError: Cannot use import statement outside a module');
198
- };
199
- const getModuleSyntaxError = () => {
200
- return {
201
- message: `ES Modules are not supported in electron`,
202
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
203
- };
209
+ return stderr.includes('ERR_MODULE_NOT_FOUND');
204
210
  };
205
- const isModuleNotFoundError = stderr => {
211
+
212
+ const isModulesSyntaxError = stderr => {
206
213
  if (!stderr) {
207
214
  return false;
208
215
  }
209
- return stderr.includes('ERR_MODULE_NOT_FOUND');
216
+ return stderr.includes('SyntaxError: Cannot use import statement outside a module');
210
217
  };
211
- const isNormalStackLine = line => {
212
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
218
+
219
+ const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
220
+ const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
221
+ const isUnhelpfulNativeModuleError = stderr => {
222
+ return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
213
223
  };
214
- const getDetails = lines => {
215
- const index = lines.findIndex(isNormalStackLine);
216
- if (index === -1) {
217
- return {
218
- actualMessage: joinLines(lines),
219
- rest: []
220
- };
221
- }
222
- let lastIndex = index - 1;
223
- while (++lastIndex < lines.length) {
224
- if (!isNormalStackLine(lines[lastIndex])) {
225
- break;
226
- }
227
- }
224
+
225
+ const getNativeModuleErrorMessage = stderr => {
226
+ const message = getMessageCodeBlock(stderr);
228
227
  return {
229
- actualMessage: lines[index - 1],
230
- rest: lines.slice(index, lastIndex)
228
+ message: `Incompatible native node module: ${message}`,
229
+ code: E_INCOMPATIBLE_NATIVE_MODULE
230
+ };
231
+ };
232
+ const getModuleSyntaxError = () => {
233
+ return {
234
+ message: `ES Modules are not supported in electron`,
235
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
231
236
  };
232
237
  };
233
238
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -246,7 +251,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
246
251
  rest
247
252
  } = getDetails(lines);
248
253
  return {
249
- message: `${actualMessage}`,
254
+ message: actualMessage,
250
255
  code: '',
251
256
  stack: rest
252
257
  };
@@ -287,13 +292,10 @@ const listen$b = ({
287
292
  }
288
293
  return messagePort;
289
294
  };
290
- const signal$b = messagePort => {
295
+ const signal$c = messagePort => {
291
296
  messagePort.start();
292
297
  };
293
298
  class IpcChildWithElectronMessagePort extends Ipc {
294
- constructor(port) {
295
- super(port);
296
- }
297
299
  getData = getActualDataElectron;
298
300
  send(message) {
299
301
  this._rawIpc.postMessage(message);
@@ -315,15 +317,15 @@ class IpcChildWithElectronMessagePort extends Ipc {
315
317
  this._rawIpc.on('close', callback);
316
318
  }
317
319
  }
318
- const wrap$i = messagePort => {
320
+ const wrap$j = messagePort => {
319
321
  return new IpcChildWithElectronMessagePort(messagePort);
320
322
  };
321
323
 
322
324
  const IpcChildWithElectronMessagePort$1 = {
323
325
  __proto__: null,
324
326
  listen: listen$b,
325
- signal: signal$b,
326
- wrap: wrap$i
327
+ signal: signal$c,
328
+ wrap: wrap$j
327
329
  };
328
330
 
329
331
  // @ts-ignore
@@ -353,7 +355,7 @@ const listen$a = () => {
353
355
  }
354
356
  return parentPort;
355
357
  };
356
- const signal$a = parentPort => {
358
+ const signal$b = parentPort => {
357
359
  parentPort.postMessage(readyMessage);
358
360
  };
359
361
  class IpcChildWithElectronUtilityProcess extends Ipc {
@@ -380,15 +382,15 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
380
382
  this._rawIpc.on('message', callback);
381
383
  }
382
384
  }
383
- const wrap$h = parentPort => {
385
+ const wrap$i = parentPort => {
384
386
  return new IpcChildWithElectronUtilityProcess(parentPort);
385
387
  };
386
388
 
387
389
  const IpcChildWithElectronUtilityProcess$1 = {
388
390
  __proto__: null,
389
391
  listen: listen$a,
390
- signal: signal$a,
391
- wrap: wrap$h
392
+ signal: signal$b,
393
+ wrap: wrap$i
392
394
  };
393
395
 
394
396
  const getData$2 = event => {
@@ -398,7 +400,7 @@ const getData$2 = event => {
398
400
  const listen$9 = () => {
399
401
  return window;
400
402
  };
401
- const signal$9 = global => {
403
+ const signal$a = global => {
402
404
  global.postMessage(readyMessage);
403
405
  };
404
406
  class IpcChildWithElectronWindow extends Ipc {
@@ -435,15 +437,15 @@ class IpcChildWithElectronWindow extends Ipc {
435
437
  this._rawIpc.addEventListener('message', wrapped);
436
438
  }
437
439
  }
438
- const wrap$g = window => {
440
+ const wrap$h = window => {
439
441
  return new IpcChildWithElectronWindow(window);
440
442
  };
441
443
 
442
444
  const IpcChildWithElectronWindow$1 = {
443
445
  __proto__: null,
444
446
  listen: listen$9,
445
- signal: signal$9,
446
- wrap: wrap$g
447
+ signal: signal$a,
448
+ wrap: wrap$h
447
449
  };
448
450
 
449
451
  const listen$8 = ({
@@ -451,13 +453,10 @@ const listen$8 = ({
451
453
  }) => {
452
454
  return port;
453
455
  };
454
- const signal$8 = port => {
456
+ const signal$9 = port => {
455
457
  port.postMessage(readyMessage);
456
458
  };
457
459
  class IpcChildWithMessagePort extends Ipc {
458
- constructor(port) {
459
- super(port);
460
- }
461
460
  getData(event) {
462
461
  return getData$2(event);
463
462
  }
@@ -479,15 +478,15 @@ class IpcChildWithMessagePort extends Ipc {
479
478
  this._rawIpc.start();
480
479
  }
481
480
  }
482
- const wrap$f = port => {
481
+ const wrap$g = port => {
483
482
  return new IpcChildWithMessagePort(port);
484
483
  };
485
484
 
486
485
  const IpcChildWithMessagePort$1 = {
487
486
  __proto__: null,
488
487
  listen: listen$8,
489
- signal: signal$8,
490
- wrap: wrap$f
488
+ signal: signal$9,
489
+ wrap: wrap$g
491
490
  };
492
491
 
493
492
  const listen$7 = () => {
@@ -497,7 +496,7 @@ const listen$7 = () => {
497
496
  }
498
497
  return globalThis;
499
498
  };
500
- const signal$7 = global => {
499
+ const signal$8 = global => {
501
500
  global.postMessage(readyMessage);
502
501
  };
503
502
  class IpcChildWithModuleWorker extends Ipc {
@@ -523,15 +522,15 @@ class IpcChildWithModuleWorker extends Ipc {
523
522
  this._rawIpc.addEventListener('message', callback);
524
523
  }
525
524
  }
526
- const wrap$e = global => {
525
+ const wrap$f = global => {
527
526
  return new IpcChildWithModuleWorker(global);
528
527
  };
529
528
 
530
529
  const IpcChildWithModuleWorker$1 = {
531
530
  __proto__: null,
532
531
  listen: listen$7,
533
- signal: signal$7,
534
- wrap: wrap$e
532
+ signal: signal$8,
533
+ wrap: wrap$f
535
534
  };
536
535
 
537
536
  const withResolvers = () => {
@@ -540,6 +539,7 @@ const withResolvers = () => {
540
539
  _resolve = resolve;
541
540
  });
542
541
  return {
542
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
543
543
  resolve: _resolve,
544
544
  promise
545
545
  };
@@ -560,8 +560,8 @@ const waitForFirstMessage = async port => {
560
560
 
561
561
  const listen$6 = async () => {
562
562
  const parentIpcRaw = listen$7();
563
- signal$7(parentIpcRaw);
564
- const parentIpc = wrap$e(parentIpcRaw);
563
+ signal$8(parentIpcRaw);
564
+ const parentIpc = wrap$f(parentIpcRaw);
565
565
  const firstMessage = await waitForFirstMessage(parentIpc);
566
566
  if (firstMessage.method !== 'initialize') {
567
567
  throw new IpcError('unexpected first message');
@@ -580,9 +580,6 @@ const listen$6 = async () => {
580
580
  return globalThis;
581
581
  };
582
582
  class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
583
- constructor(port) {
584
- super(port);
585
- }
586
583
  getData(event) {
587
584
  return getData$2(event);
588
585
  }
@@ -606,22 +603,14 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
606
603
  this._rawIpc.start();
607
604
  }
608
605
  }
609
- const wrap$d = port => {
606
+ const wrap$e = port => {
610
607
  return new IpcChildWithModuleWorkerAndMessagePort(port);
611
608
  };
612
609
 
613
610
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
614
611
  __proto__: null,
615
612
  listen: listen$6,
616
- wrap: wrap$d
617
- };
618
-
619
- const getTransferrablesNode = value => {
620
- const transferrables = getTransferrables(value);
621
- if (transferrables.length === 0) {
622
- throw new Error(`no transferrables found`);
623
- }
624
- return transferrables[0];
613
+ wrap: wrap$e
625
614
  };
626
615
 
627
616
  const getActualData = (message, handle) => {
@@ -634,19 +623,24 @@ const getActualData = (message, handle) => {
634
623
  return message;
635
624
  };
636
625
 
626
+ const getTransferrablesNode = value => {
627
+ const transferrables = getTransferrables(value);
628
+ if (transferrables.length === 0) {
629
+ throw new Error(`no transferrables found`);
630
+ }
631
+ return transferrables[0];
632
+ };
633
+
637
634
  const listen$5 = async () => {
638
635
  if (!process.send) {
639
636
  throw new Error('process.send must be defined');
640
637
  }
641
638
  return process;
642
639
  };
643
- const signal$6 = process => {
640
+ const signal$7 = process => {
644
641
  process.send(readyMessage);
645
642
  };
646
643
  class IpcChildWithNodeForkedProcess extends Ipc {
647
- constructor(process) {
648
- super(process);
649
- }
650
644
  getData(message, handle) {
651
645
  return getActualData(message, handle);
652
646
  }
@@ -667,15 +661,15 @@ class IpcChildWithNodeForkedProcess extends Ipc {
667
661
  // ignore
668
662
  }
669
663
  }
670
- const wrap$c = process => {
664
+ const wrap$d = process => {
671
665
  return new IpcChildWithNodeForkedProcess(process);
672
666
  };
673
667
 
674
668
  const IpcChildWithNodeForkedProcess$1 = {
675
669
  __proto__: null,
676
670
  listen: listen$5,
677
- signal: signal$6,
678
- wrap: wrap$c
671
+ signal: signal$7,
672
+ wrap: wrap$d
679
673
  };
680
674
 
681
675
  const listen$4 = async ({
@@ -686,10 +680,10 @@ const listen$4 = async ({
686
680
  }
687
681
  return messagePort;
688
682
  };
689
- const signal$5 = messagePort => {
683
+ const signal$6 = messagePort => {
690
684
  messagePort.start();
691
685
  };
692
- const wrap$b = port => {
686
+ const wrap$c = port => {
693
687
  return {
694
688
  port,
695
689
  on(event, listener) {
@@ -720,8 +714,8 @@ const wrap$b = port => {
720
714
  const IpcChildWithNodeMessagePort = {
721
715
  __proto__: null,
722
716
  listen: listen$4,
723
- signal: signal$5,
724
- wrap: wrap$b
717
+ signal: signal$6,
718
+ wrap: wrap$c
725
719
  };
726
720
 
727
721
  const listen$3 = async () => {
@@ -733,13 +727,10 @@ const listen$3 = async () => {
733
727
  }
734
728
  return parentPort;
735
729
  };
736
- const signal$4 = parentPort => {
730
+ const signal$5 = parentPort => {
737
731
  parentPort.postMessage(readyMessage);
738
732
  };
739
733
  class IpcChildWithNodeWorker extends Ipc {
740
- constructor(port) {
741
- super(port);
742
- }
743
734
  getData(data) {
744
735
  return data;
745
736
  }
@@ -760,15 +751,15 @@ class IpcChildWithNodeWorker extends Ipc {
760
751
  this._rawIpc.close();
761
752
  }
762
753
  }
763
- const wrap$a = parentPort => {
754
+ const wrap$b = parentPort => {
764
755
  return new IpcChildWithNodeWorker(parentPort);
765
756
  };
766
757
 
767
758
  const IpcChildWithNodeWorker$1 = {
768
759
  __proto__: null,
769
760
  listen: listen$3,
770
- signal: signal$4,
771
- wrap: wrap$a
761
+ signal: signal$5,
762
+ wrap: wrap$b
772
763
  };
773
764
 
774
765
  const preloadChannelType = 'port';
@@ -809,18 +800,19 @@ class IpcChildWithRendererProcess2 extends Ipc {
809
800
  this._rawIpc.on('destroyed', callback);
810
801
  }
811
802
  }
812
- const wrap$9 = webContents => {
803
+ const wrap$a = webContents => {
813
804
  return new IpcChildWithRendererProcess2(webContents);
814
805
  };
815
806
 
816
807
  const IpcChildWithRendererProcess2$1 = {
817
808
  __proto__: null,
818
809
  listen: listen$2,
819
- wrap: wrap$9
810
+ wrap: wrap$a
820
811
  };
821
812
 
822
- const Open = 1;
823
- const Close = 2;
813
+ const Error$3 = 1;
814
+ const Open = 2;
815
+ const Close = 3;
824
816
 
825
817
  const addListener = (emitter, type, callback) => {
826
818
  if ('addEventListener' in emitter) {
@@ -937,12 +929,12 @@ const listen$1 = async ({
937
929
  }
938
930
  return webSocket;
939
931
  };
940
- const signal$3 = webSocket => {
932
+ const signal$4 = webSocket => {
941
933
  webSocket.resume();
942
934
  };
943
935
 
944
936
  // @ts-ignore
945
- const wrap$8 = webSocket => {
937
+ const wrap$9 = webSocket => {
946
938
  return {
947
939
  webSocket,
948
940
  /**
@@ -992,14 +984,14 @@ const wrap$8 = webSocket => {
992
984
  const IpcChildWithWebSocket = {
993
985
  __proto__: null,
994
986
  listen: listen$1,
995
- signal: signal$3,
996
- wrap: wrap$8
987
+ signal: signal$4,
988
+ wrap: wrap$9
997
989
  };
998
990
 
999
991
  const listen = () => {
1000
992
  return window;
1001
993
  };
1002
- const signal$2 = global => {
994
+ const signal$3 = global => {
1003
995
  global.postMessage(readyMessage);
1004
996
  };
1005
997
  class IpcChildWithWindow extends Ipc {
@@ -1033,18 +1025,18 @@ class IpcChildWithWindow extends Ipc {
1033
1025
  this._rawIpc.addEventListener('message', wrapped);
1034
1026
  }
1035
1027
  }
1036
- const wrap$7 = window => {
1028
+ const wrap$8 = window => {
1037
1029
  return new IpcChildWithWindow(window);
1038
1030
  };
1039
1031
 
1040
1032
  const IpcChildWithWindow$1 = {
1041
1033
  __proto__: null,
1042
1034
  listen,
1043
- signal: signal$2,
1044
- wrap: wrap$7
1035
+ signal: signal$3,
1036
+ wrap: wrap$8
1045
1037
  };
1046
1038
 
1047
- const create$6 = ({
1039
+ const create$7 = ({
1048
1040
  messagePort
1049
1041
  }) => {
1050
1042
  if (!isMessagePortMain(messagePort)) {
@@ -1052,13 +1044,10 @@ const create$6 = ({
1052
1044
  }
1053
1045
  return messagePort;
1054
1046
  };
1055
- const signal$1 = messagePort => {
1047
+ const signal$2 = messagePort => {
1056
1048
  messagePort.start();
1057
1049
  };
1058
1050
  class IpcParentWithElectronMessagePort extends Ipc {
1059
- constructor(port) {
1060
- super(port);
1061
- }
1062
1051
  getData = getActualDataElectron;
1063
1052
  send(message) {
1064
1053
  this._rawIpc.postMessage(message);
@@ -1080,27 +1069,21 @@ class IpcParentWithElectronMessagePort extends Ipc {
1080
1069
  this._rawIpc.on('close', callback);
1081
1070
  }
1082
1071
  }
1083
- const wrap$6 = messagePort => {
1072
+ const wrap$7 = messagePort => {
1084
1073
  return new IpcParentWithElectronMessagePort(messagePort);
1085
1074
  };
1086
1075
 
1087
1076
  const IpcParentWithElectronMessagePort$1 = {
1088
1077
  __proto__: null,
1089
- create: create$6,
1090
- signal: signal$1,
1091
- wrap: wrap$6
1078
+ create: create$7,
1079
+ signal: signal$2,
1080
+ wrap: wrap$7
1092
1081
  };
1093
1082
 
1094
1083
  const Exit = 1;
1095
1084
  const Error$2 = 2;
1096
1085
  const Message$1 = 3;
1097
1086
 
1098
- /**
1099
- *
1100
- * @param {any} utilityProcess
1101
- * @returns
1102
- */
1103
- // @ts-ignore
1104
1087
  const getFirstUtilityProcessEvent = async utilityProcess => {
1105
1088
  const {
1106
1089
  resolve,
@@ -1108,7 +1091,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1108
1091
  } = withResolvers();
1109
1092
  let stdout = '';
1110
1093
  let stderr = '';
1111
- // @ts-ignore
1112
1094
  const cleanup = value => {
1113
1095
  // @ts-ignore
1114
1096
  utilityProcess.stderr.off('data', handleStdErrData);
@@ -1116,18 +1098,14 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1116
1098
  utilityProcess.stdout.off('data', handleStdoutData);
1117
1099
  utilityProcess.off('message', handleMessage);
1118
1100
  utilityProcess.off('exit', handleExit);
1119
- // @ts-ignore
1120
1101
  resolve(value);
1121
1102
  };
1122
- // @ts-ignore
1123
1103
  const handleStdErrData = data => {
1124
1104
  stderr += data;
1125
1105
  };
1126
- // @ts-ignore
1127
1106
  const handleStdoutData = data => {
1128
1107
  stdout += data;
1129
1108
  };
1130
- // @ts-ignore
1131
1109
  const handleMessage = event => {
1132
1110
  cleanup({
1133
1111
  type: Message$1,
@@ -1136,7 +1114,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1136
1114
  stderr
1137
1115
  });
1138
1116
  };
1139
- // @ts-ignore
1140
1117
  const handleExit = event => {
1141
1118
  cleanup({
1142
1119
  type: Exit,
@@ -1151,7 +1128,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1151
1128
  utilityProcess.stdout.on('data', handleStdoutData);
1152
1129
  utilityProcess.on('message', handleMessage);
1153
1130
  utilityProcess.on('exit', handleExit);
1154
- // @ts-ignore
1155
1131
  const {
1156
1132
  type,
1157
1133
  event
@@ -1164,8 +1140,7 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1164
1140
  };
1165
1141
  };
1166
1142
 
1167
- // @ts-ignore
1168
- const create$5 = async ({
1143
+ const create$6 = async ({
1169
1144
  path,
1170
1145
  argv = [],
1171
1146
  execArgv = [],
@@ -1228,17 +1203,17 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
1228
1203
  this._rawIpc.on('message', callback);
1229
1204
  }
1230
1205
  }
1231
- const wrap$5 = process => {
1206
+ const wrap$6 = process => {
1232
1207
  return new IpcParentWithElectronUtilityProcess(process);
1233
1208
  };
1234
1209
 
1235
1210
  const IpcParentWithElectronUtilityProcess$1 = {
1236
1211
  __proto__: null,
1237
- create: create$5,
1238
- wrap: wrap$5
1212
+ create: create$6,
1213
+ wrap: wrap$6
1239
1214
  };
1240
1215
 
1241
- const create$4 = async ({
1216
+ const create$5 = async ({
1242
1217
  messagePort,
1243
1218
  isMessagePortOpen
1244
1219
  }) => {
@@ -1259,13 +1234,10 @@ const create$4 = async ({
1259
1234
  }
1260
1235
  return messagePort;
1261
1236
  };
1262
- const signal = messagePort => {
1237
+ const signal$1 = messagePort => {
1263
1238
  messagePort.start();
1264
1239
  };
1265
1240
  class IpcParentWithMessagePort extends Ipc {
1266
- constructor(port) {
1267
- super(port);
1268
- }
1269
1241
  getData = getData$2;
1270
1242
  send(message) {
1271
1243
  this._rawIpc.postMessage(message);
@@ -1281,15 +1253,15 @@ class IpcParentWithMessagePort extends Ipc {
1281
1253
  }
1282
1254
  onClose(callback) {}
1283
1255
  }
1284
- const wrap$4 = messagePort => {
1256
+ const wrap$5 = messagePort => {
1285
1257
  return new IpcParentWithMessagePort(messagePort);
1286
1258
  };
1287
1259
 
1288
1260
  const IpcParentWithMessagePort$1 = {
1289
1261
  __proto__: null,
1290
- create: create$4,
1291
- signal,
1292
- wrap: wrap$4
1262
+ create: create$5,
1263
+ signal: signal$1,
1264
+ wrap: wrap$5
1293
1265
  };
1294
1266
 
1295
1267
  const Message = 'message';
@@ -1337,7 +1309,7 @@ ${relevant}`;
1337
1309
 
1338
1310
  const Module = 'module';
1339
1311
 
1340
- const create$3 = async ({
1312
+ const create$4 = async ({
1341
1313
  url,
1342
1314
  name
1343
1315
  }) => {
@@ -1394,13 +1366,74 @@ class IpcParentWithModuleWorker extends Ipc {
1394
1366
  this._rawIpc.addEventListener('message', callback);
1395
1367
  }
1396
1368
  }
1397
- const wrap$3 = worker => {
1369
+ const wrap$4 = worker => {
1398
1370
  return new IpcParentWithModuleWorker(worker);
1399
1371
  };
1400
1372
 
1401
1373
  const IpcParentWithModuleWorker$1 = {
1374
+ __proto__: null,
1375
+ create: create$4,
1376
+ wrap: wrap$4
1377
+ };
1378
+
1379
+ const getPortTuple = () => {
1380
+ const {
1381
+ port1,
1382
+ port2
1383
+ } = new MessageChannel();
1384
+ return {
1385
+ port1,
1386
+ port2
1387
+ };
1388
+ };
1389
+
1390
+ const create$3 = async ({
1391
+ sendPort,
1392
+ url,
1393
+ name
1394
+ }) => {
1395
+ const {
1396
+ port1,
1397
+ port2
1398
+ } = getPortTuple();
1399
+ await sendPort({
1400
+ port: port1,
1401
+ name,
1402
+ url
1403
+ });
1404
+ return port2;
1405
+ };
1406
+ const signal = messagePort => {
1407
+ messagePort.start();
1408
+ };
1409
+ class IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug extends Ipc {
1410
+ getData = getData$2;
1411
+ send(message) {
1412
+ this._rawIpc.postMessage(message);
1413
+ }
1414
+ sendAndTransfer(message) {
1415
+ const transfer = getTransferrables(message);
1416
+ this._rawIpc.postMessage(message, transfer);
1417
+ }
1418
+ dispose() {
1419
+ this._rawIpc.close();
1420
+ }
1421
+ onMessage(callback) {
1422
+ this._rawIpc.addEventListener('message', callback);
1423
+ this._rawIpc.start();
1424
+ }
1425
+ onClose(callback) {
1426
+ // ignore
1427
+ }
1428
+ }
1429
+ const wrap$3 = messagePort => {
1430
+ return new IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug(messagePort);
1431
+ };
1432
+
1433
+ const IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug$1 = {
1402
1434
  __proto__: null,
1403
1435
  create: create$3,
1436
+ signal,
1404
1437
  wrap: wrap$3
1405
1438
  };
1406
1439
 
@@ -1445,9 +1478,7 @@ const fixNodeChildProcessParameters = value => {
1445
1478
  };
1446
1479
  };
1447
1480
 
1448
- // @ts-ignore
1449
1481
  const getFirstNodeChildProcessEvent = async childProcess => {
1450
- // @ts-ignore
1451
1482
  const {
1452
1483
  type,
1453
1484
  event,
@@ -1456,7 +1487,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1456
1487
  } = await new Promise((resolve, reject) => {
1457
1488
  let stderr = '';
1458
1489
  let stdout = '';
1459
- // @ts-ignore
1460
1490
  const cleanup = value => {
1461
1491
  if (childProcess.stdout && childProcess.stderr) {
1462
1492
  childProcess.stderr.off('data', handleStdErrData);
@@ -1467,15 +1497,12 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1467
1497
  childProcess.off('error', handleError);
1468
1498
  resolve(value);
1469
1499
  };
1470
- // @ts-ignore
1471
1500
  const handleStdErrData = data => {
1472
1501
  stderr += data;
1473
1502
  };
1474
- // @ts-ignore
1475
1503
  const handleStdoutData = data => {
1476
1504
  stdout += data;
1477
1505
  };
1478
- // @ts-ignore
1479
1506
  const handleMessage = event => {
1480
1507
  cleanup({
1481
1508
  type: Message$1,
@@ -1484,7 +1511,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1484
1511
  stderr
1485
1512
  });
1486
1513
  };
1487
- // @ts-ignore
1488
1514
  const handleExit = event => {
1489
1515
  cleanup({
1490
1516
  type: Exit,
@@ -1493,7 +1519,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1493
1519
  stderr
1494
1520
  });
1495
1521
  };
1496
- // @ts-ignore
1497
1522
  const handleError = event => {
1498
1523
  cleanup({
1499
1524
  type: Error$2,
@@ -1622,7 +1647,6 @@ const create$1 = async ({
1622
1647
  env = process.env,
1623
1648
  execArgv = []
1624
1649
  }) => {
1625
- // @ts-ignore
1626
1650
  string(path);
1627
1651
  const actualArgv = ['--ipc-type=node-worker', ...argv];
1628
1652
  const actualEnv = {
@@ -1637,7 +1661,6 @@ const create$1 = async ({
1637
1661
  env: actualEnv,
1638
1662
  execArgv
1639
1663
  });
1640
- // @ts-ignore
1641
1664
  const {
1642
1665
  type,
1643
1666
  event
@@ -1654,9 +1677,6 @@ const create$1 = async ({
1654
1677
  return worker;
1655
1678
  };
1656
1679
  class IpcParentWithNodeWorker extends Ipc {
1657
- constructor(worker) {
1658
- super(worker);
1659
- }
1660
1680
  getData(message) {
1661
1681
  return message;
1662
1682
  }
@@ -1670,8 +1690,8 @@ class IpcParentWithNodeWorker extends Ipc {
1670
1690
  } = fixNodeWorkerParameters(message);
1671
1691
  this._rawIpc.postMessage(newValue, transfer);
1672
1692
  }
1673
- dispose() {
1674
- this._rawIpc.terminate();
1693
+ async dispose() {
1694
+ await this._rawIpc.terminate();
1675
1695
  }
1676
1696
  onClose(callback) {
1677
1697
  this._rawIpc.on('exit', callback);
@@ -1707,7 +1727,8 @@ const parse = content => {
1707
1727
  const waitForWebSocketToBeOpen = webSocket => {
1708
1728
  return getFirstEvent(webSocket, {
1709
1729
  open: Open,
1710
- close: Close
1730
+ close: Close,
1731
+ error: Error$3
1711
1732
  });
1712
1733
  };
1713
1734
 
@@ -1715,7 +1736,9 @@ const create = async ({
1715
1736
  webSocket
1716
1737
  }) => {
1717
1738
  const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
1718
- // @ts-ignore
1739
+ if (firstWebSocketEvent.type === Error$3) {
1740
+ throw new IpcError(`WebSocket connection error`);
1741
+ }
1719
1742
  if (firstWebSocketEvent.type === Close) {
1720
1743
  throw new IpcError('Websocket connection was immediately closed');
1721
1744
  }
@@ -1751,4 +1774,4 @@ const IpcParentWithWebSocket$1 = {
1751
1774
  wrap
1752
1775
  };
1753
1776
 
1754
- export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithElectronWindow$1 as IpcChildWithElectronWindow, IpcChildWithMessagePort$1 as IpcChildWithMessagePort, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker$1 as IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcChildWithWindow$1 as IpcChildWithWindow, IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithMessagePort$1 as IpcParentWithMessagePort, IpcParentWithModuleWorker$1 as IpcParentWithModuleWorker, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker$1 as IpcParentWithNodeWorker, IpcParentWithWebSocket$1 as IpcParentWithWebSocket };
1777
+ export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithElectronWindow$1 as IpcChildWithElectronWindow, IpcChildWithMessagePort$1 as IpcChildWithMessagePort, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker$1 as IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcChildWithWindow$1 as IpcChildWithWindow, IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithMessagePort$1 as IpcParentWithMessagePort, IpcParentWithModuleWorker$1 as IpcParentWithModuleWorker, IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug$1 as IpcParentWithModuleWorkerAndWorkaroundForChromeDevtoolsBug, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker$1 as IpcParentWithNodeWorker, IpcParentWithWebSocket$1 as IpcParentWithWebSocket };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "12.2.0",
3
+ "version": "13.1.0",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "@lvce-editor/web-socket-server": "^1.4.0"
21
21
  },
22
22
  "engines": {
23
- "node": ">=18"
23
+ "node": ">=22"
24
24
  },
25
25
  "types": "dist/index.d.ts",
26
26
  "browser": "dist/browser.js"