@lvce-editor/ipc 10.0.3 → 10.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/browser.js CHANGED
@@ -143,6 +143,19 @@ const splitLines = lines => {
143
143
  return lines.split(NewLine$1);
144
144
  };
145
145
 
146
+ const isModuleNotFoundMessage = line => {
147
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
148
+ };
149
+ const getModuleNotFoundError = stderr => {
150
+ const lines = splitLines(stderr);
151
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
152
+ const message = lines[messageIndex];
153
+ return {
154
+ message,
155
+ code: ERR_MODULE_NOT_FOUND
156
+ };
157
+ };
158
+
146
159
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
147
160
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
148
161
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
@@ -191,18 +204,6 @@ const isModuleNotFoundError = stderr => {
191
204
  }
192
205
  return stderr.includes('ERR_MODULE_NOT_FOUND');
193
206
  };
194
- const isModuleNotFoundMessage = line => {
195
- return line.includes('ERR_MODULE_NOT_FOUND');
196
- };
197
- const getModuleNotFoundError = stderr => {
198
- const lines = splitLines(stderr);
199
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
200
- const message = lines[messageIndex];
201
- return {
202
- message,
203
- code: ERR_MODULE_NOT_FOUND
204
- };
205
- };
206
207
  const isNormalStackLine = line => {
207
208
  return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
208
209
  };
package/dist/electron.js CHANGED
@@ -37,6 +37,102 @@ const Exit = 1;
37
37
  const Error$1 = 2;
38
38
  const Message = 3;
39
39
 
40
+ const walkValue = (value, transferrables, isTransferrable) => {
41
+ if (!value) {
42
+ return;
43
+ }
44
+ if (isTransferrable(value)) {
45
+ transferrables.push(value);
46
+ return;
47
+ }
48
+ if (Array.isArray(value)) {
49
+ for (const item of value) {
50
+ walkValue(item, transferrables, isTransferrable);
51
+ }
52
+ return;
53
+ }
54
+ if (typeof value === 'object') {
55
+ for (const property of Object.values(value)) {
56
+ walkValue(property, transferrables, isTransferrable);
57
+ }
58
+ return;
59
+ }
60
+ };
61
+
62
+ const isMessagePort = value => {
63
+ return value && value instanceof MessagePort;
64
+ };
65
+
66
+ const isMessagePortMain = value => {
67
+ return value && value.constructor && value.constructor.name === 'MessagePortMain';
68
+ };
69
+
70
+ const isOffscreenCanvas = value => {
71
+ return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
72
+ };
73
+
74
+ const isInstanceOf = (value, constructorName) => {
75
+ return value?.constructor?.name === constructorName;
76
+ };
77
+
78
+ const isSocket = value => {
79
+ return isInstanceOf(value, 'Socket');
80
+ };
81
+
82
+ const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
83
+
84
+ const isTransferrable = value => {
85
+ for (const fn of transferrables) {
86
+ if (fn(value)) {
87
+ return true;
88
+ }
89
+ }
90
+ return false;
91
+ };
92
+
93
+ const getTransferrables = value => {
94
+ const transferrables = [];
95
+ walkValue(value, transferrables, isTransferrable);
96
+ return transferrables;
97
+ };
98
+
99
+ const removeValues = (value, toRemove) => {
100
+ if (!value) {
101
+ return value;
102
+ }
103
+ if (Array.isArray(value)) {
104
+ const newItems = [];
105
+ for (const item of value) {
106
+ if (!toRemove.includes(item)) {
107
+ newItems.push(removeValues(item, toRemove));
108
+ }
109
+ }
110
+ return newItems;
111
+ }
112
+ if (typeof value === 'object') {
113
+ const newObject = Object.create(null);
114
+ for (const [key, property] of Object.entries(value)) {
115
+ if (!toRemove.includes(property)) {
116
+ newObject[key] = removeValues(property, toRemove);
117
+ }
118
+ }
119
+ return newObject;
120
+ }
121
+ return value;
122
+ };
123
+
124
+ // workaround for electron not supporting transferrable objects
125
+ // as parameters. If the transferrable object is a parameter, in electron
126
+ // only an empty objected is received in the main process
127
+ const fixElectronParameters = value => {
128
+ const transfer = getTransferrables(value);
129
+ const newValue = removeValues(value, transfer);
130
+ return {
131
+ newValue,
132
+ transfer
133
+ };
134
+ };
135
+
40
136
  const withResolvers = () => {
41
137
  let _resolve;
42
138
  const promise = new Promise(resolve => {
@@ -153,6 +249,19 @@ const splitLines = lines => {
153
249
  return lines.split(NewLine$1);
154
250
  };
155
251
 
252
+ const isModuleNotFoundMessage = line => {
253
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
254
+ };
255
+ const getModuleNotFoundError = stderr => {
256
+ const lines = splitLines(stderr);
257
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
258
+ const message = lines[messageIndex];
259
+ return {
260
+ message,
261
+ code: ERR_MODULE_NOT_FOUND
262
+ };
263
+ };
264
+
156
265
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
157
266
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
158
267
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
@@ -201,18 +310,6 @@ const isModuleNotFoundError = stderr => {
201
310
  }
202
311
  return stderr.includes('ERR_MODULE_NOT_FOUND');
203
312
  };
204
- const isModuleNotFoundMessage = line => {
205
- return line.includes('ERR_MODULE_NOT_FOUND');
206
- };
207
- const getModuleNotFoundError = stderr => {
208
- const lines = splitLines(stderr);
209
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
210
- const message = lines[messageIndex];
211
- return {
212
- message,
213
- code: ERR_MODULE_NOT_FOUND
214
- };
215
- };
216
313
  const isNormalStackLine = line => {
217
314
  return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
218
315
  };
@@ -340,65 +437,6 @@ class IpcError extends VError {
340
437
  }
341
438
  }
342
439
 
343
- const walkValue = (value, transferrables, isTransferrable) => {
344
- if (!value) {
345
- return;
346
- }
347
- if (isTransferrable(value)) {
348
- transferrables.push(value);
349
- return;
350
- }
351
- if (Array.isArray(value)) {
352
- for (const item of value) {
353
- walkValue(item, transferrables, isTransferrable);
354
- }
355
- return;
356
- }
357
- if (typeof value === 'object') {
358
- for (const property of Object.values(value)) {
359
- walkValue(property, transferrables, isTransferrable);
360
- }
361
- return;
362
- }
363
- };
364
-
365
- const isMessagePort = value => {
366
- return value && value instanceof MessagePort;
367
- };
368
-
369
- const isMessagePortMain = value => {
370
- return value && value.constructor && value.constructor.name === 'MessagePortMain';
371
- };
372
-
373
- const isOffscreenCanvas = value => {
374
- return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
375
- };
376
-
377
- const isInstanceOf = (value, constructorName) => {
378
- return value?.constructor?.name === constructorName;
379
- };
380
-
381
- const isSocket = value => {
382
- return isInstanceOf(value, 'Socket');
383
- };
384
-
385
- const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
386
-
387
- const isTransferrable = value => {
388
- for (const fn of transferrables) {
389
- if (fn(value)) {
390
- return true;
391
- }
392
- }
393
- return false;
394
- };
395
-
396
- const getTransferrables = value => {
397
- const transferrables = [];
398
- walkValue(value, transferrables, isTransferrable);
399
- return transferrables;
400
- };
401
-
402
440
  // @ts-ignore
403
441
  const create$2 = async ({
404
442
  path,
@@ -447,8 +485,11 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
447
485
  this._rawIpc.postMessage(message);
448
486
  }
449
487
  sendAndTransfer(message) {
450
- const transfer = getTransferrables(message);
451
- this._rawIpc.postMessage(message, transfer);
488
+ const {
489
+ newValue,
490
+ transfer
491
+ } = fixElectronParameters(message);
492
+ this._rawIpc.postMessage(newValue, transfer);
452
493
  }
453
494
  dispose() {
454
495
  this._rawIpc.kill();
@@ -496,31 +537,6 @@ class ChildProcessError extends Error {
496
537
  }
497
538
  }
498
539
 
499
- const removeValues = (value, toRemove) => {
500
- if (!value) {
501
- return value;
502
- }
503
- if (Array.isArray(value)) {
504
- const newItems = [];
505
- for (const item of value) {
506
- if (!toRemove.includes(item)) {
507
- newItems.push(removeValues(item, toRemove));
508
- }
509
- }
510
- return newItems;
511
- }
512
- if (typeof value === 'object') {
513
- const newObject = Object.create(null);
514
- for (const [key, property] of Object.entries(value)) {
515
- if (!toRemove.includes(property)) {
516
- newObject[key] = removeValues(property, toRemove);
517
- }
518
- }
519
- return newObject;
520
- }
521
- return value;
522
- };
523
-
524
540
  // workaround for node not supporting transferrable objects
525
541
  // as parameters. If the transferrable object is a parameter,
526
542
  // it is received as a plain object is received in the receiving process
package/dist/index.js CHANGED
@@ -133,6 +133,19 @@ const splitLines = lines => {
133
133
  return lines.split(NewLine);
134
134
  };
135
135
 
136
+ const isModuleNotFoundMessage = line => {
137
+ return line.includes('[ERR_MODULE_NOT_FOUND]');
138
+ };
139
+ const getModuleNotFoundError = stderr => {
140
+ const lines = splitLines(stderr);
141
+ const messageIndex = lines.findIndex(isModuleNotFoundMessage);
142
+ const message = lines[messageIndex];
143
+ return {
144
+ message,
145
+ code: ERR_MODULE_NOT_FOUND
146
+ };
147
+ };
148
+
136
149
  const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
137
150
  const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
138
151
  const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
@@ -181,18 +194,6 @@ const isModuleNotFoundError = stderr => {
181
194
  }
182
195
  return stderr.includes('ERR_MODULE_NOT_FOUND');
183
196
  };
184
- const isModuleNotFoundMessage = line => {
185
- return line.includes('ERR_MODULE_NOT_FOUND');
186
- };
187
- const getModuleNotFoundError = stderr => {
188
- const lines = splitLines(stderr);
189
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
190
- const message = lines[messageIndex];
191
- return {
192
- message,
193
- code: ERR_MODULE_NOT_FOUND
194
- };
195
- };
196
197
  const isNormalStackLine = line => {
197
198
  return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
198
199
  };
@@ -1014,8 +1015,11 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
1014
1015
  this._rawIpc.postMessage(message);
1015
1016
  }
1016
1017
  sendAndTransfer(message) {
1017
- const transfer = getTransferrables(message);
1018
- this._rawIpc.postMessage(message, transfer);
1018
+ const {
1019
+ newValue,
1020
+ transfer
1021
+ } = fixElectronParameters(message);
1022
+ this._rawIpc.postMessage(newValue, transfer);
1019
1023
  }
1020
1024
  dispose() {
1021
1025
  this._rawIpc.kill();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "10.0.3",
3
+ "version": "10.1.0",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  "url": "https://github.com/lvce-editor/ipc.git"
15
15
  },
16
16
  "dependencies": {
17
- "@lvce-editor/assert": "^1.2.0",
17
+ "@lvce-editor/assert": "^1.3.0",
18
18
  "@lvce-editor/verror": "^1.4.0",
19
19
  "@lvce-editor/web-socket-server": "^1.3.0"
20
20
  },