@lynx-js/web-worker-runtime 0.15.6 → 0.16.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589))
|
|
8
|
+
|
|
9
|
+
Before this change, We create a function wrapper and a fake globalThis for Javascript code.
|
|
10
|
+
|
|
11
|
+
This caused some issues.
|
|
12
|
+
|
|
13
|
+
After this change, we will create an iframe for createing an isolated Javascript context.
|
|
14
|
+
|
|
15
|
+
This means the globalThis will be the real one.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
22
|
+
- @lynx-js/web-mainthread-apis@0.16.0
|
|
23
|
+
- @lynx-js/web-constants@0.16.0
|
|
24
|
+
- @lynx-js/offscreen-document@0.1.4
|
|
25
|
+
- @lynx-js/web-worker-rpc@0.16.0
|
|
26
|
+
|
|
27
|
+
## 0.15.7
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- fix: globalThis is never accessible in MTS ([#1531](https://github.com/lynx-family/lynx-stack/pull/1531))
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`70863fb`](https://github.com/lynx-family/lynx-stack/commit/70863fbc311d8885ebda40855668097b0631f521)]:
|
|
34
|
+
- @lynx-js/web-mainthread-apis@0.15.7
|
|
35
|
+
- @lynx-js/web-constants@0.15.7
|
|
36
|
+
- @lynx-js/web-worker-rpc@0.15.7
|
|
37
|
+
|
|
3
38
|
## 0.15.6
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint,
|
|
1
|
+
import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, I18nResource, reportErrorEndpoint, } from '@lynx-js/web-constants';
|
|
2
2
|
import { createInvokeUIMethod } from './crossThreadHandlers/createInvokeUIMethod.js';
|
|
3
3
|
import { registerPublicComponentEventHandler } from './crossThreadHandlers/registerPublicComponentEventHandler.js';
|
|
4
4
|
import { registerGlobalExposureEventHandler } from './crossThreadHandlers/registerGlobalExposureEventHandler.js';
|
|
@@ -14,7 +14,7 @@ import { createGetPathInfo } from './crossThreadHandlers/createGetPathInfo.js';
|
|
|
14
14
|
let nativeAppCount = 0;
|
|
15
15
|
const sharedData = {};
|
|
16
16
|
export async function createNativeApp(config) {
|
|
17
|
-
const { mainThreadRpc, uiThreadRpc, template, nativeModulesMap, timingSystem,
|
|
17
|
+
const { mainThreadRpc, uiThreadRpc, template, nativeModulesMap, timingSystem, } = config;
|
|
18
18
|
const performanceApis = createPerformanceApis(timingSystem);
|
|
19
19
|
const callLepusMethod = mainThreadRpc.createCallbackify(callLepusMethodEndpoint, 2);
|
|
20
20
|
const setNativeProps = uiThreadRpc.createCall(setNativePropsEndpoint);
|
|
@@ -23,30 +23,7 @@ export async function createNativeApp(config) {
|
|
|
23
23
|
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
24
24
|
const createBundleInitReturnObj = () => {
|
|
25
25
|
const entry = globalThis.module.exports;
|
|
26
|
-
return
|
|
27
|
-
init: (lynxCoreInject) => {
|
|
28
|
-
lynxCoreInject.tt.lynxCoreInject = lynxCoreInject;
|
|
29
|
-
lynxCoreInject.tt.globalThis ??= new Proxy(lynxCoreInject, {
|
|
30
|
-
get(target, prop) {
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
return target[prop] ?? globalThis[prop];
|
|
33
|
-
},
|
|
34
|
-
set(target, prop, value) {
|
|
35
|
-
// @ts-expect-error
|
|
36
|
-
target[prop] = value;
|
|
37
|
-
return true;
|
|
38
|
-
},
|
|
39
|
-
ownKeys(target) {
|
|
40
|
-
return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
Object.assign(lynxCoreInject.tt, {
|
|
44
|
-
SystemInfo: { ...systemInfo, ...browserConfig },
|
|
45
|
-
});
|
|
46
|
-
const ret = entry?.(lynxCoreInject.tt);
|
|
47
|
-
return ret;
|
|
48
|
-
},
|
|
49
|
-
};
|
|
26
|
+
return entry;
|
|
50
27
|
};
|
|
51
28
|
const i18nResource = new I18nResource();
|
|
52
29
|
let release = '';
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { startBackgroundThread } from './backgroundThread/index.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { mode, toPeerThread, toUIThread } = ev
|
|
5
|
+
globalThis.onmessage = async (ev) => {
|
|
6
|
+
const { mode, toPeerThread, toUIThread, systemInfo } = ev
|
|
8
7
|
.data;
|
|
8
|
+
if (!globalThis.SystemInfo) {
|
|
9
|
+
globalThis.SystemInfo = systemInfo;
|
|
10
|
+
}
|
|
9
11
|
if (mode === 'main') {
|
|
12
|
+
const { startMainThreadWorker } = await import(
|
|
13
|
+
/* webpackChunkName: "web-worker-runtime-main-thread" */
|
|
14
|
+
/* webpackMode: "lazy-once" */
|
|
15
|
+
/* webpackPreload: true */
|
|
16
|
+
'./mainThread/startMainThread.js');
|
|
10
17
|
startMainThreadWorker(toUIThread, toPeerThread);
|
|
11
18
|
}
|
|
12
19
|
else {
|
|
@@ -7,8 +7,34 @@ import { createMarkTimingInternal } from './crossThreadHandlers/createMainthread
|
|
|
7
7
|
import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
|
|
8
8
|
import { _onEvent } from '@lynx-js/offscreen-document/webworker';
|
|
9
9
|
import { registerUpdateDataHandler } from './crossThreadHandlers/registerUpdateDataHandler.js';
|
|
10
|
+
const { prepareMainThreadAPIs } = await import(
|
|
11
|
+
/* webpackChunkName: "web-core-main-thread-apis" */
|
|
12
|
+
/* webpackMode: "lazy-once" */
|
|
13
|
+
/* webpackPreload: true */
|
|
14
|
+
/* webpackPrefetch: true */
|
|
15
|
+
/* webpackFetchPriority: "high" */
|
|
16
|
+
'@lynx-js/web-mainthread-apis');
|
|
17
|
+
function loadScriptSync(url) {
|
|
18
|
+
importScripts(url);
|
|
19
|
+
return globalThis.module?.exports;
|
|
20
|
+
}
|
|
21
|
+
function loadScript(url) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
fetch(url)
|
|
24
|
+
.then(() => {
|
|
25
|
+
importScripts(url);
|
|
26
|
+
resolve(globalThis.module?.exports);
|
|
27
|
+
}).catch(reject);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function createCurrentWorkerRealm() {
|
|
31
|
+
return {
|
|
32
|
+
globalWindow: globalThis,
|
|
33
|
+
loadScript,
|
|
34
|
+
loadScriptSync,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
10
37
|
export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort) {
|
|
11
|
-
const { prepareMainThreadAPIs } = await import('@lynx-js/web-mainthread-apis');
|
|
12
38
|
const uiThreadRpc = new Rpc(uiThreadPort, 'main-to-ui');
|
|
13
39
|
const backgroundThreadRpc = new Rpc(backgroundThreadPort, 'main-to-bg');
|
|
14
40
|
const { markTimingInternal, flushMarkTimingInternal } = createMarkTimingInternal(backgroundThreadRpc);
|
|
@@ -20,14 +46,19 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
|
|
|
20
46
|
options,
|
|
21
47
|
]);
|
|
22
48
|
};
|
|
23
|
-
const
|
|
49
|
+
const document = new OffscreenDocument({
|
|
24
50
|
onCommit: uiFlush,
|
|
25
51
|
});
|
|
52
|
+
Object.assign(globalThis, {
|
|
53
|
+
document,
|
|
54
|
+
});
|
|
55
|
+
const mtsRealm = createCurrentWorkerRealm();
|
|
26
56
|
const i18nResources = new I18nResources();
|
|
27
|
-
uiThreadRpc.registerHandler(postOffscreenEventEndpoint,
|
|
57
|
+
uiThreadRpc.registerHandler(postOffscreenEventEndpoint, document[_onEvent]);
|
|
28
58
|
const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
|
|
29
|
-
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc,
|
|
30
|
-
|
|
59
|
+
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, document, // rootDom
|
|
60
|
+
document, mtsRealm, (exposureChangedElementUniqueIds) => {
|
|
61
|
+
document.commit();
|
|
31
62
|
sendMultiThreadExposureChangedEndpoint(exposureChangedElementUniqueIds
|
|
32
63
|
.map(e => e.getAttribute(lynxUniqueIdAttribute))
|
|
33
64
|
.filter(id => id !== null));
|
|
@@ -35,10 +66,9 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
|
|
|
35
66
|
i18nResources.setData(initI18nResources);
|
|
36
67
|
return i18nResources;
|
|
37
68
|
});
|
|
38
|
-
uiThreadRpc.registerHandler(mainThreadStartEndpoint, (config) => {
|
|
39
|
-
startMainThread(config)
|
|
40
|
-
|
|
41
|
-
});
|
|
69
|
+
uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
|
|
70
|
+
await startMainThread(config);
|
|
71
|
+
registerUpdateDataHandler(uiThreadRpc, globalThis);
|
|
42
72
|
});
|
|
43
73
|
uiThreadRpc?.registerHandler(updateI18nResourcesEndpoint, data => {
|
|
44
74
|
i18nResources.setData(data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@lynx-js/
|
|
26
|
-
"@lynx-js/
|
|
27
|
-
"@lynx-js/web-
|
|
28
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
25
|
+
"@lynx-js/web-mainthread-apis": "0.16.0",
|
|
26
|
+
"@lynx-js/offscreen-document": "0.1.4",
|
|
27
|
+
"@lynx-js/web-constants": "0.16.0",
|
|
28
|
+
"@lynx-js/web-worker-rpc": "0.16.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@lynx-js/lynx-core": "0.1.3"
|