@lvce-editor/ipc 12.1.0 → 13.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/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export const IpcChildWithRendererProcess2: IpcChild
19
19
  export const IpcChildWithModuleWorkerAndMessagePort: IpcChild
20
20
  export const IpcChildWithModuleWorker: IpcChild
21
21
  export const IpcChildWithMessagePort: IpcChild
22
+ export const IpcChildWithElectronWindow: IpcChild
22
23
 
23
24
  interface IpcParent {
24
25
  readonly create: any
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);
@@ -139,10 +139,6 @@ const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
139
139
 
140
140
  const NewLine = '\n';
141
141
 
142
- const joinLines = lines => {
143
- return lines.join(NewLine);
144
- };
145
-
146
142
  const splitLines = lines => {
147
143
  return lines.split(NewLine);
148
144
  };
@@ -160,6 +156,10 @@ const getModuleNotFoundError = stderr => {
160
156
  };
161
157
  };
162
158
 
159
+ const joinLines = lines => {
160
+ return lines.join(NewLine);
161
+ };
162
+
163
163
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
164
164
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
165
165
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
@@ -246,7 +246,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
246
246
  rest
247
247
  } = getDetails(lines);
248
248
  return {
249
- message: `${actualMessage}`,
249
+ message: actualMessage,
250
250
  code: '',
251
251
  stack: rest
252
252
  };
@@ -291,9 +291,6 @@ const signal$b = messagePort => {
291
291
  messagePort.start();
292
292
  };
293
293
  class IpcChildWithElectronMessagePort extends Ipc {
294
- constructor(port) {
295
- super(port);
296
- }
297
294
  getData = getActualDataElectron;
298
295
  send(message) {
299
296
  this._rawIpc.postMessage(message);
@@ -455,9 +452,6 @@ const signal$8 = port => {
455
452
  port.postMessage(readyMessage);
456
453
  };
457
454
  class IpcChildWithMessagePort extends Ipc {
458
- constructor(port) {
459
- super(port);
460
- }
461
455
  getData(event) {
462
456
  return getData$2(event);
463
457
  }
@@ -540,6 +534,7 @@ const withResolvers = () => {
540
534
  _resolve = resolve;
541
535
  });
542
536
  return {
537
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
543
538
  resolve: _resolve,
544
539
  promise
545
540
  };
@@ -580,9 +575,6 @@ const listen$6 = async () => {
580
575
  return globalThis;
581
576
  };
582
577
  class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
583
- constructor(port) {
584
- super(port);
585
- }
586
578
  getData(event) {
587
579
  return getData$2(event);
588
580
  }
@@ -616,14 +608,6 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
616
608
  wrap: wrap$d
617
609
  };
618
610
 
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];
625
- };
626
-
627
611
  const getActualData = (message, handle) => {
628
612
  if (handle) {
629
613
  return {
@@ -634,6 +618,14 @@ const getActualData = (message, handle) => {
634
618
  return message;
635
619
  };
636
620
 
621
+ const getTransferrablesNode = value => {
622
+ const transferrables = getTransferrables(value);
623
+ if (transferrables.length === 0) {
624
+ throw new Error(`no transferrables found`);
625
+ }
626
+ return transferrables[0];
627
+ };
628
+
637
629
  const listen$5 = async () => {
638
630
  if (!process.send) {
639
631
  throw new Error('process.send must be defined');
@@ -644,9 +636,6 @@ const signal$6 = process => {
644
636
  process.send(readyMessage);
645
637
  };
646
638
  class IpcChildWithNodeForkedProcess extends Ipc {
647
- constructor(process) {
648
- super(process);
649
- }
650
639
  getData(message, handle) {
651
640
  return getActualData(message, handle);
652
641
  }
@@ -737,9 +726,6 @@ const signal$4 = parentPort => {
737
726
  parentPort.postMessage(readyMessage);
738
727
  };
739
728
  class IpcChildWithNodeWorker extends Ipc {
740
- constructor(port) {
741
- super(port);
742
- }
743
729
  getData(data) {
744
730
  return data;
745
731
  }
@@ -1056,9 +1042,6 @@ const signal$1 = messagePort => {
1056
1042
  messagePort.start();
1057
1043
  };
1058
1044
  class IpcParentWithElectronMessagePort extends Ipc {
1059
- constructor(port) {
1060
- super(port);
1061
- }
1062
1045
  getData = getActualDataElectron;
1063
1046
  send(message) {
1064
1047
  this._rawIpc.postMessage(message);
@@ -1095,12 +1078,6 @@ const Exit = 1;
1095
1078
  const Error$2 = 2;
1096
1079
  const Message$1 = 3;
1097
1080
 
1098
- /**
1099
- *
1100
- * @param {any} utilityProcess
1101
- * @returns
1102
- */
1103
- // @ts-ignore
1104
1081
  const getFirstUtilityProcessEvent = async utilityProcess => {
1105
1082
  const {
1106
1083
  resolve,
@@ -1108,7 +1085,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1108
1085
  } = withResolvers();
1109
1086
  let stdout = '';
1110
1087
  let stderr = '';
1111
- // @ts-ignore
1112
1088
  const cleanup = value => {
1113
1089
  // @ts-ignore
1114
1090
  utilityProcess.stderr.off('data', handleStdErrData);
@@ -1116,18 +1092,14 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1116
1092
  utilityProcess.stdout.off('data', handleStdoutData);
1117
1093
  utilityProcess.off('message', handleMessage);
1118
1094
  utilityProcess.off('exit', handleExit);
1119
- // @ts-ignore
1120
1095
  resolve(value);
1121
1096
  };
1122
- // @ts-ignore
1123
1097
  const handleStdErrData = data => {
1124
1098
  stderr += data;
1125
1099
  };
1126
- // @ts-ignore
1127
1100
  const handleStdoutData = data => {
1128
1101
  stdout += data;
1129
1102
  };
1130
- // @ts-ignore
1131
1103
  const handleMessage = event => {
1132
1104
  cleanup({
1133
1105
  type: Message$1,
@@ -1136,7 +1108,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1136
1108
  stderr
1137
1109
  });
1138
1110
  };
1139
- // @ts-ignore
1140
1111
  const handleExit = event => {
1141
1112
  cleanup({
1142
1113
  type: Exit,
@@ -1151,7 +1122,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1151
1122
  utilityProcess.stdout.on('data', handleStdoutData);
1152
1123
  utilityProcess.on('message', handleMessage);
1153
1124
  utilityProcess.on('exit', handleExit);
1154
- // @ts-ignore
1155
1125
  const {
1156
1126
  type,
1157
1127
  event
@@ -1164,7 +1134,6 @@ const getFirstUtilityProcessEvent = async utilityProcess => {
1164
1134
  };
1165
1135
  };
1166
1136
 
1167
- // @ts-ignore
1168
1137
  const create$5 = async ({
1169
1138
  path,
1170
1139
  argv = [],
@@ -1263,9 +1232,6 @@ const signal = messagePort => {
1263
1232
  messagePort.start();
1264
1233
  };
1265
1234
  class IpcParentWithMessagePort extends Ipc {
1266
- constructor(port) {
1267
- super(port);
1268
- }
1269
1235
  getData = getData$2;
1270
1236
  send(message) {
1271
1237
  this._rawIpc.postMessage(message);
@@ -1445,9 +1411,7 @@ const fixNodeChildProcessParameters = value => {
1445
1411
  };
1446
1412
  };
1447
1413
 
1448
- // @ts-ignore
1449
1414
  const getFirstNodeChildProcessEvent = async childProcess => {
1450
- // @ts-ignore
1451
1415
  const {
1452
1416
  type,
1453
1417
  event,
@@ -1456,7 +1420,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1456
1420
  } = await new Promise((resolve, reject) => {
1457
1421
  let stderr = '';
1458
1422
  let stdout = '';
1459
- // @ts-ignore
1460
1423
  const cleanup = value => {
1461
1424
  if (childProcess.stdout && childProcess.stderr) {
1462
1425
  childProcess.stderr.off('data', handleStdErrData);
@@ -1467,15 +1430,12 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1467
1430
  childProcess.off('error', handleError);
1468
1431
  resolve(value);
1469
1432
  };
1470
- // @ts-ignore
1471
1433
  const handleStdErrData = data => {
1472
1434
  stderr += data;
1473
1435
  };
1474
- // @ts-ignore
1475
1436
  const handleStdoutData = data => {
1476
1437
  stdout += data;
1477
1438
  };
1478
- // @ts-ignore
1479
1439
  const handleMessage = event => {
1480
1440
  cleanup({
1481
1441
  type: Message$1,
@@ -1484,7 +1444,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1484
1444
  stderr
1485
1445
  });
1486
1446
  };
1487
- // @ts-ignore
1488
1447
  const handleExit = event => {
1489
1448
  cleanup({
1490
1449
  type: Exit,
@@ -1493,7 +1452,6 @@ const getFirstNodeChildProcessEvent = async childProcess => {
1493
1452
  stderr
1494
1453
  });
1495
1454
  };
1496
- // @ts-ignore
1497
1455
  const handleError = event => {
1498
1456
  cleanup({
1499
1457
  type: Error$2,
@@ -1622,7 +1580,6 @@ const create$1 = async ({
1622
1580
  env = process.env,
1623
1581
  execArgv = []
1624
1582
  }) => {
1625
- // @ts-ignore
1626
1583
  string(path);
1627
1584
  const actualArgv = ['--ipc-type=node-worker', ...argv];
1628
1585
  const actualEnv = {
@@ -1637,7 +1594,6 @@ const create$1 = async ({
1637
1594
  env: actualEnv,
1638
1595
  execArgv
1639
1596
  });
1640
- // @ts-ignore
1641
1597
  const {
1642
1598
  type,
1643
1599
  event
@@ -1654,9 +1610,6 @@ const create$1 = async ({
1654
1610
  return worker;
1655
1611
  };
1656
1612
  class IpcParentWithNodeWorker extends Ipc {
1657
- constructor(worker) {
1658
- super(worker);
1659
- }
1660
1613
  getData(message) {
1661
1614
  return message;
1662
1615
  }
@@ -1670,8 +1623,8 @@ class IpcParentWithNodeWorker extends Ipc {
1670
1623
  } = fixNodeWorkerParameters(message);
1671
1624
  this._rawIpc.postMessage(newValue, transfer);
1672
1625
  }
1673
- dispose() {
1674
- this._rawIpc.terminate();
1626
+ async dispose() {
1627
+ await this._rawIpc.terminate();
1675
1628
  }
1676
1629
  onClose(callback) {
1677
1630
  this._rawIpc.on('exit', callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "12.1.0",
3
+ "version": "13.0.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"