@lvce-editor/test-worker 1.4.0 → 1.6.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/testWorkerMain.js +89 -95
- package/package.json +1 -1
package/dist/testWorkerMain.js
CHANGED
|
@@ -250,67 +250,6 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
250
250
|
}
|
|
251
251
|
throw new JsonRpcError('unexpected response message');
|
|
252
252
|
};
|
|
253
|
-
const isMessagePort = value => {
|
|
254
|
-
return typeof MessagePort !== 'undefined' && value instanceof MessagePort;
|
|
255
|
-
};
|
|
256
|
-
const isInstanceOf = (value, constructorName) => {
|
|
257
|
-
return value?.constructor?.name === constructorName;
|
|
258
|
-
};
|
|
259
|
-
const isMessagePortMain = value => {
|
|
260
|
-
return isInstanceOf(value, 'MessagePortMain');
|
|
261
|
-
};
|
|
262
|
-
const isOffscreenCanvas = value => {
|
|
263
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
264
|
-
};
|
|
265
|
-
const isSocket = value => {
|
|
266
|
-
return isInstanceOf(value, 'Socket');
|
|
267
|
-
};
|
|
268
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
269
|
-
const isTransferrable = value => {
|
|
270
|
-
for (const fn of transferrables) {
|
|
271
|
-
if (fn(value)) {
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return false;
|
|
276
|
-
};
|
|
277
|
-
const walkValue = (value, transferrables) => {
|
|
278
|
-
if (!value) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
if (isTransferrable(value)) {
|
|
282
|
-
transferrables.push(value);
|
|
283
|
-
}
|
|
284
|
-
if (Array.isArray(value)) {
|
|
285
|
-
for (const item of value) {
|
|
286
|
-
walkValue(item, transferrables);
|
|
287
|
-
}
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
if (typeof value === 'object') {
|
|
291
|
-
for (const property of Object.values(value)) {
|
|
292
|
-
walkValue(property, transferrables);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
const getTransferrables = value => {
|
|
297
|
-
const transferrables = [];
|
|
298
|
-
walkValue(value, transferrables);
|
|
299
|
-
return transferrables;
|
|
300
|
-
};
|
|
301
|
-
const isSingleTransferrable = value => {
|
|
302
|
-
return isSocket(value);
|
|
303
|
-
};
|
|
304
|
-
const getTransferrableParams = value => {
|
|
305
|
-
const transferrables = getTransferrables(value);
|
|
306
|
-
if (transferrables.length === 0) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
if (isSingleTransferrable(transferrables[0])) {
|
|
310
|
-
return transferrables[0];
|
|
311
|
-
}
|
|
312
|
-
return transferrables;
|
|
313
|
-
};
|
|
314
253
|
const create$1 = (message, error) => {
|
|
315
254
|
return {
|
|
316
255
|
jsonrpc: Two,
|
|
@@ -433,17 +372,15 @@ const invoke$1 = async (ipc, method, ...params) => {
|
|
|
433
372
|
// TODO deprecated old typings,
|
|
434
373
|
// always use automatic transferrable detection
|
|
435
374
|
const invokeAndTransfer$1 = async (ipc, handle, method, ...params) => {
|
|
436
|
-
let transfer = handle;
|
|
437
375
|
if (typeof handle === 'string') {
|
|
438
376
|
params = [method, ...params];
|
|
439
377
|
method = handle;
|
|
440
|
-
transfer = getTransferrableParams(params);
|
|
441
378
|
}
|
|
442
379
|
const {
|
|
443
380
|
message,
|
|
444
381
|
promise
|
|
445
382
|
} = create$2(method, params);
|
|
446
|
-
ipc.sendAndTransfer(message
|
|
383
|
+
ipc.sendAndTransfer(message);
|
|
447
384
|
const responseMessage = await promise;
|
|
448
385
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
449
386
|
return result;
|
|
@@ -457,7 +394,7 @@ const invokeAndTransfer = (method, ...params) => {
|
|
|
457
394
|
const ipc = get$1();
|
|
458
395
|
return invokeAndTransfer$1(ipc, method, ...params);
|
|
459
396
|
};
|
|
460
|
-
const listen$
|
|
397
|
+
const listen$2 = ipc => {
|
|
461
398
|
set$1(ipc);
|
|
462
399
|
};
|
|
463
400
|
|
|
@@ -465,7 +402,7 @@ const Rpc = {
|
|
|
465
402
|
__proto__: null,
|
|
466
403
|
invoke,
|
|
467
404
|
invokeAndTransfer,
|
|
468
|
-
listen: listen$
|
|
405
|
+
listen: listen$2
|
|
469
406
|
};
|
|
470
407
|
|
|
471
408
|
const Fail = 'fail';
|
|
@@ -1340,7 +1277,7 @@ const getIsFirefox = () => {
|
|
|
1340
1277
|
const isFirefox$1 = getIsFirefox();
|
|
1341
1278
|
|
|
1342
1279
|
const getNodePath$1 = () => {
|
|
1343
|
-
return invoke(
|
|
1280
|
+
return invoke(/* Platform.getNodePath */'Platform.getNodePath');
|
|
1344
1281
|
};
|
|
1345
1282
|
|
|
1346
1283
|
const getNodePath = () => {
|
|
@@ -1739,6 +1676,56 @@ const Auto = () => {
|
|
|
1739
1676
|
const getData$1 = event => {
|
|
1740
1677
|
return event.data;
|
|
1741
1678
|
};
|
|
1679
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
1680
|
+
if (!value) {
|
|
1681
|
+
return;
|
|
1682
|
+
}
|
|
1683
|
+
if (isTransferrable(value)) {
|
|
1684
|
+
transferrables.push(value);
|
|
1685
|
+
return;
|
|
1686
|
+
}
|
|
1687
|
+
if (Array.isArray(value)) {
|
|
1688
|
+
for (const item of value) {
|
|
1689
|
+
walkValue(item, transferrables, isTransferrable);
|
|
1690
|
+
}
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
if (typeof value === 'object') {
|
|
1694
|
+
for (const property of Object.values(value)) {
|
|
1695
|
+
walkValue(property, transferrables, isTransferrable);
|
|
1696
|
+
}
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
const isMessagePort = value => {
|
|
1701
|
+
return value && value instanceof MessagePort;
|
|
1702
|
+
};
|
|
1703
|
+
const isMessagePortMain = value => {
|
|
1704
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
1705
|
+
};
|
|
1706
|
+
const isOffscreenCanvas = value => {
|
|
1707
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
1708
|
+
};
|
|
1709
|
+
const isInstanceOf = (value, constructorName) => {
|
|
1710
|
+
return value?.constructor?.name === constructorName;
|
|
1711
|
+
};
|
|
1712
|
+
const isSocket = value => {
|
|
1713
|
+
return isInstanceOf(value, 'Socket');
|
|
1714
|
+
};
|
|
1715
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
1716
|
+
const isTransferrable = value => {
|
|
1717
|
+
for (const fn of transferrables) {
|
|
1718
|
+
if (fn(value)) {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return false;
|
|
1723
|
+
};
|
|
1724
|
+
const getTransferrables = value => {
|
|
1725
|
+
const transferrables = [];
|
|
1726
|
+
walkValue(value, transferrables, isTransferrable);
|
|
1727
|
+
return transferrables;
|
|
1728
|
+
};
|
|
1742
1729
|
const attachEvents = that => {
|
|
1743
1730
|
const handleMessage = (...args) => {
|
|
1744
1731
|
const data = that.getData(...args);
|
|
@@ -1760,14 +1747,14 @@ class Ipc extends EventTarget {
|
|
|
1760
1747
|
}
|
|
1761
1748
|
}
|
|
1762
1749
|
const readyMessage = 'ready';
|
|
1763
|
-
const listen$
|
|
1750
|
+
const listen$4 = () => {
|
|
1764
1751
|
// @ts-ignore
|
|
1765
1752
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
1766
1753
|
throw new TypeError('module is not in web worker scope');
|
|
1767
1754
|
}
|
|
1768
1755
|
return globalThis;
|
|
1769
1756
|
};
|
|
1770
|
-
const signal$
|
|
1757
|
+
const signal$3 = global => {
|
|
1771
1758
|
global.postMessage(readyMessage);
|
|
1772
1759
|
};
|
|
1773
1760
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -1778,7 +1765,8 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1778
1765
|
// @ts-ignore
|
|
1779
1766
|
this._rawIpc.postMessage(message);
|
|
1780
1767
|
}
|
|
1781
|
-
sendAndTransfer(message
|
|
1768
|
+
sendAndTransfer(message) {
|
|
1769
|
+
const transfer = getTransferrables(message);
|
|
1782
1770
|
// @ts-ignore
|
|
1783
1771
|
this._rawIpc.postMessage(message, transfer);
|
|
1784
1772
|
}
|
|
@@ -1792,14 +1780,14 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
1792
1780
|
this._rawIpc.addEventListener('message', callback);
|
|
1793
1781
|
}
|
|
1794
1782
|
}
|
|
1795
|
-
const wrap$
|
|
1783
|
+
const wrap$6 = global => {
|
|
1796
1784
|
return new IpcChildWithModuleWorker(global);
|
|
1797
1785
|
};
|
|
1798
1786
|
const IpcChildWithModuleWorker$1 = {
|
|
1799
1787
|
__proto__: null,
|
|
1800
|
-
listen: listen$
|
|
1801
|
-
signal: signal$
|
|
1802
|
-
wrap: wrap$
|
|
1788
|
+
listen: listen$4,
|
|
1789
|
+
signal: signal$3,
|
|
1790
|
+
wrap: wrap$6
|
|
1803
1791
|
};
|
|
1804
1792
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
1805
1793
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
@@ -1811,6 +1799,18 @@ const joinLines = lines => {
|
|
|
1811
1799
|
const splitLines = lines => {
|
|
1812
1800
|
return lines.split(NewLine$1);
|
|
1813
1801
|
};
|
|
1802
|
+
const isModuleNotFoundMessage = line => {
|
|
1803
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
1804
|
+
};
|
|
1805
|
+
const getModuleNotFoundError = stderr => {
|
|
1806
|
+
const lines = splitLines(stderr);
|
|
1807
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
1808
|
+
const message = lines[messageIndex];
|
|
1809
|
+
return {
|
|
1810
|
+
message,
|
|
1811
|
+
code: ERR_MODULE_NOT_FOUND
|
|
1812
|
+
};
|
|
1813
|
+
};
|
|
1814
1814
|
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
1815
1815
|
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
1816
1816
|
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
@@ -1859,18 +1859,6 @@ const isModuleNotFoundError = stderr => {
|
|
|
1859
1859
|
}
|
|
1860
1860
|
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
1861
1861
|
};
|
|
1862
|
-
const isModuleNotFoundMessage = line => {
|
|
1863
|
-
return line.includes('ERR_MODULE_NOT_FOUND');
|
|
1864
|
-
};
|
|
1865
|
-
const getModuleNotFoundError = stderr => {
|
|
1866
|
-
const lines = splitLines(stderr);
|
|
1867
|
-
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
1868
|
-
const message = lines[messageIndex];
|
|
1869
|
-
return {
|
|
1870
|
-
message,
|
|
1871
|
-
code: ERR_MODULE_NOT_FOUND
|
|
1872
|
-
};
|
|
1873
|
-
};
|
|
1874
1862
|
const isNormalStackLine = line => {
|
|
1875
1863
|
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
1876
1864
|
};
|
|
@@ -2017,16 +2005,21 @@ const waitForFirstMessage = async port => {
|
|
|
2017
2005
|
// @ts-ignore
|
|
2018
2006
|
return event.data;
|
|
2019
2007
|
};
|
|
2020
|
-
const listen$
|
|
2021
|
-
const parentIpcRaw = listen$
|
|
2022
|
-
signal$
|
|
2023
|
-
const parentIpc = wrap$
|
|
2008
|
+
const listen$3 = async () => {
|
|
2009
|
+
const parentIpcRaw = listen$4();
|
|
2010
|
+
signal$3(parentIpcRaw);
|
|
2011
|
+
const parentIpc = wrap$6(parentIpcRaw);
|
|
2024
2012
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
2025
2013
|
if (firstMessage.method !== 'initialize') {
|
|
2026
2014
|
throw new IpcError('unexpected first message');
|
|
2027
2015
|
}
|
|
2028
2016
|
const type = firstMessage.params[0];
|
|
2029
2017
|
if (type === 'message-port') {
|
|
2018
|
+
parentIpc.send({
|
|
2019
|
+
jsonrpc: '2.0',
|
|
2020
|
+
id: firstMessage.id,
|
|
2021
|
+
result: null
|
|
2022
|
+
});
|
|
2030
2023
|
parentIpc.dispose();
|
|
2031
2024
|
const port = firstMessage.params[1];
|
|
2032
2025
|
return port;
|
|
@@ -2043,7 +2036,8 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
2043
2036
|
send(message) {
|
|
2044
2037
|
this._rawIpc.postMessage(message);
|
|
2045
2038
|
}
|
|
2046
|
-
sendAndTransfer(message
|
|
2039
|
+
sendAndTransfer(message) {
|
|
2040
|
+
const transfer = getTransferrables(message);
|
|
2047
2041
|
this._rawIpc.postMessage(message, transfer);
|
|
2048
2042
|
}
|
|
2049
2043
|
dispose() {
|
|
@@ -2059,13 +2053,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
2059
2053
|
this._rawIpc.start();
|
|
2060
2054
|
}
|
|
2061
2055
|
}
|
|
2062
|
-
const wrap$
|
|
2056
|
+
const wrap$5 = port => {
|
|
2063
2057
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
2064
2058
|
};
|
|
2065
2059
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
2066
2060
|
__proto__: null,
|
|
2067
|
-
listen: listen$
|
|
2068
|
-
wrap: wrap$
|
|
2061
|
+
listen: listen$3,
|
|
2062
|
+
wrap: wrap$5
|
|
2069
2063
|
};
|
|
2070
2064
|
|
|
2071
2065
|
const getModule = method => {
|
|
@@ -2097,7 +2091,7 @@ const listen = async () => {
|
|
|
2097
2091
|
method: Auto()
|
|
2098
2092
|
});
|
|
2099
2093
|
handleIpc(ipc);
|
|
2100
|
-
listen$
|
|
2094
|
+
listen$2(ipc);
|
|
2101
2095
|
};
|
|
2102
2096
|
|
|
2103
2097
|
const main = async () => {
|