@lynx-js/web-worker-runtime 0.8.0 → 0.9.1
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 +71 -0
- package/dist/backgroundThread/background-apis/createNapiLoader.js +1 -1
- package/dist/backgroundThread/background-apis/createNativeApp.d.ts +3 -3
- package/dist/backgroundThread/background-apis/createNativeApp.js +3 -3
- package/dist/backgroundThread/background-apis/createNativeModules.d.ts +2 -1
- package/dist/backgroundThread/background-apis/createNativeModules.js +7 -29
- package/dist/backgroundThread/background-apis/startBackgroundThread.js +1 -6
- package/dist/mainThread/startMainThread.js +6 -7
- package/package.json +4 -4
- package/dist/mainThread/crossThreadHandlers/createReportError.d.ts +0 -2
- package/dist/mainThread/crossThreadHandlers/createReportError.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# @lynx-js/web-worker-runtime
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @lynx-js/web-constants@0.9.1
|
|
9
|
+
- @lynx-js/web-mainthread-apis@0.9.1
|
|
10
|
+
- @lynx-js/web-worker-rpc@0.9.1
|
|
11
|
+
|
|
12
|
+
## 0.9.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- feat: `nativeModulesUrl` of lynx-view is changed to `nativeModulesMap`, and the usage is completely aligned with `napiModulesMap`. ([#220](https://github.com/lynx-family/lynx-stack/pull/220))
|
|
17
|
+
|
|
18
|
+
"warning: This is a breaking change."
|
|
19
|
+
|
|
20
|
+
`nativeModulesMap` will be a map: key is module-name, value should be a esm url which export default a
|
|
21
|
+
function with two parameters(you never need to use `this`):
|
|
22
|
+
|
|
23
|
+
- `NativeModules`: oriented `NativeModules`, which you can use to call
|
|
24
|
+
other Native-Modules.
|
|
25
|
+
|
|
26
|
+
- `NativeModulesCall`: trigger `onNativeModulesCall`, same as the deprecated `this.nativeModulesCall`.
|
|
27
|
+
|
|
28
|
+
example:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const nativeModulesMap = {
|
|
32
|
+
CustomModule: URL.createObjectURL(
|
|
33
|
+
new Blob(
|
|
34
|
+
[
|
|
35
|
+
`export default function(NativeModules, NativeModulesCall) {
|
|
36
|
+
return {
|
|
37
|
+
async getColor(data, callback) {
|
|
38
|
+
const color = await NativeModulesCall('getColor', data);
|
|
39
|
+
callback(color);
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
};`,
|
|
43
|
+
],
|
|
44
|
+
{ type: 'text/javascript' },
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
lynxView.nativeModulesMap = nativeModulesMap;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
In addition, we will use Promise.all to load `nativeModules`, which will optimize performance in the case of multiple modules.
|
|
52
|
+
|
|
53
|
+
- refractor: remove entryId concept ([#217](https://github.com/lynx-family/lynx-stack/pull/217))
|
|
54
|
+
|
|
55
|
+
After the PR #198
|
|
56
|
+
All contents are isolated by a shadowroot.
|
|
57
|
+
Therefore we don't need to add the entryId selector to avoid the lynx-view's style taking effect on the whole page.
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- refactor: remove customelement defined detecting logic ([#247](https://github.com/lynx-family/lynx-stack/pull/247))
|
|
62
|
+
|
|
63
|
+
Before this commit, for those element with tag without `-`, we always try to detect if the `x-${tagName}` is defined.
|
|
64
|
+
|
|
65
|
+
After this commit, we pre-define a map(could be override by the `overrideLynxTagToHTMLTagMap`) to make that transformation for tag name.
|
|
66
|
+
|
|
67
|
+
This change is a path to SSR and the MTS support.
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [[`5b5e090`](https://github.com/lynx-family/lynx-stack/commit/5b5e090fdf0e896f1c38a49bf3ed9889117c4fb8), [`b844e75`](https://github.com/lynx-family/lynx-stack/commit/b844e751f566d924256365d37aec4c86c520ec00), [`53230f0`](https://github.com/lynx-family/lynx-stack/commit/53230f012216f3a627853e11d544e4be175c5b9b), [`6f16827`](https://github.com/lynx-family/lynx-stack/commit/6f16827d1f4d7364870d354fc805a8868c110f1e), [`d2d55ef`](https://github.com/lynx-family/lynx-stack/commit/d2d55ef9fe438c35921d9db0daa40d5228822ecc)]:
|
|
70
|
+
- @lynx-js/web-constants@0.9.0
|
|
71
|
+
- @lynx-js/web-mainthread-apis@0.9.0
|
|
72
|
+
- @lynx-js/web-worker-rpc@0.9.0
|
|
73
|
+
|
|
3
74
|
## 0.8.0
|
|
4
75
|
|
|
5
76
|
### Minor Changes
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { napiModulesCallEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
export const createNapiLoader = async (rpc, napiModulesMap) => {
|
|
6
6
|
const napiModulesCall = rpc.createCall(napiModulesCallEndpoint);
|
|
7
|
-
|
|
7
|
+
const napiModules = {};
|
|
8
8
|
await Promise.all(Object.entries(napiModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => napiModules[moduleName] = module?.default?.(napiModules, (name, data) => napiModulesCall(name, data, moduleName)))));
|
|
9
9
|
return {
|
|
10
10
|
load(moduleName) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
import { type LynxTemplate, type NativeApp } from '@lynx-js/web-constants';
|
|
2
|
+
import { type LynxTemplate, type NativeApp, type NativeModulesMap } from '@lynx-js/web-constants';
|
|
3
3
|
export declare function createNativeApp(config: {
|
|
4
4
|
template: LynxTemplate;
|
|
5
5
|
uiThreadRpc: Rpc;
|
|
6
6
|
mainThreadRpc: Rpc;
|
|
7
7
|
markTimingInternal: (timingKey: string, pipelineId?: string) => void;
|
|
8
|
-
|
|
9
|
-
}): NativeApp
|
|
8
|
+
nativeModulesMap: NativeModulesMap;
|
|
9
|
+
}): Promise<NativeApp>;
|
|
@@ -12,8 +12,8 @@ import { registerOnNativeAppReadyHandler } from './crossThreadHandlers/registerO
|
|
|
12
12
|
import { registerSendGlobalEventHandler } from './crossThreadHandlers/registerSendGlobalEvent.js';
|
|
13
13
|
import { createJSObjectDestructionObserver } from './crossThreadHandlers/createJSObjectDestructionObserver.js';
|
|
14
14
|
let nativeAppCount = 0;
|
|
15
|
-
export function createNativeApp(config) {
|
|
16
|
-
const { mainThreadRpc, uiThreadRpc, markTimingInternal, template,
|
|
15
|
+
export async function createNativeApp(config) {
|
|
16
|
+
const { mainThreadRpc, uiThreadRpc, markTimingInternal, template, nativeModulesMap, } = config;
|
|
17
17
|
const { performanceApis, pipelineIdToTimingFlags } = createPerformanceApis(markTimingInternal);
|
|
18
18
|
const callLepusMethod = mainThreadRpc.createCallbackify(callLepusMethodEndpoint, 2);
|
|
19
19
|
const setNativeProps = uiThreadRpc.createCall(setNativePropsEndpoint);
|
|
@@ -26,7 +26,7 @@ export function createNativeApp(config) {
|
|
|
26
26
|
setInterval: setInterval,
|
|
27
27
|
clearTimeout: clearTimeout,
|
|
28
28
|
clearInterval: clearInterval,
|
|
29
|
-
nativeModuleProxy: createNativeModules(uiThreadRpc,
|
|
29
|
+
nativeModuleProxy: await createNativeModules(uiThreadRpc, nativeModulesMap),
|
|
30
30
|
loadScriptAsync: function (sourceURL, callback) {
|
|
31
31
|
const mainfestUrl = template.manifest[`/${sourceURL}`];
|
|
32
32
|
if (mainfestUrl)
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { type NativeModulesMap } from '@lynx-js/web-constants';
|
|
1
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
export declare function createNativeModules(rpc: Rpc,
|
|
3
|
+
export declare function createNativeModules(rpc: Rpc, nativeModulesMap: NativeModulesMap): Promise<Record<string, any>>;
|
|
@@ -2,7 +2,7 @@
|
|
|
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 { nativeModulesCallEndpoint, switchExposureService, } from '@lynx-js/web-constants';
|
|
5
|
-
export function createNativeModules(rpc,
|
|
5
|
+
export async function createNativeModules(rpc, nativeModulesMap) {
|
|
6
6
|
const switchExposure = rpc.createCall(switchExposureService);
|
|
7
7
|
const nativeModulesCall = rpc.createCall(nativeModulesCallEndpoint);
|
|
8
8
|
const lynxExposureModule = {
|
|
@@ -18,35 +18,13 @@ export function createNativeModules(rpc, customNativeModules) {
|
|
|
18
18
|
nativeModulesCall(name, data, 'bridge').then(callback);
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const nativeModules = {};
|
|
22
|
+
const customNativeModules = {};
|
|
23
|
+
await Promise.all(Object.entries(nativeModulesMap).map(([moduleName, moduleStr]) => import(/* webpackIgnore: true */ moduleStr).then(module => customNativeModules[moduleName] = module?.default?.(nativeModules, (name, data) => nativeModulesCall(name, data, moduleName)))));
|
|
24
|
+
return Object.assign(nativeModules, {
|
|
22
25
|
bridge: bridgeModule,
|
|
23
26
|
LynxExposureModule: lynxExposureModule,
|
|
24
|
-
...
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function recursiveFunctionCallBinder(nativeModulesCall, customNativeModules) {
|
|
28
|
-
const newObj = Object.fromEntries(Object.entries(customNativeModules).map(([moduleName, moduleImpl]) => {
|
|
29
|
-
if (typeof moduleImpl === 'object') {
|
|
30
|
-
for (const [property, value] of Object.entries(moduleImpl)) {
|
|
31
|
-
if (typeof value === 'function') {
|
|
32
|
-
moduleImpl[property] = bindThisContext({
|
|
33
|
-
nativeModulesCall,
|
|
34
|
-
moduleName,
|
|
35
|
-
func: value,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return [moduleName, moduleImpl];
|
|
41
|
-
}));
|
|
42
|
-
return newObj;
|
|
43
|
-
}
|
|
44
|
-
function bindThisContext({ nativeModulesCall, moduleName, func }) {
|
|
45
|
-
const context = {
|
|
46
|
-
nativeModulesCall(name, data) {
|
|
47
|
-
return nativeModulesCall(name, data, moduleName);
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
return func.bind(context);
|
|
27
|
+
...customNativeModules,
|
|
28
|
+
});
|
|
51
29
|
}
|
|
52
30
|
//# sourceMappingURL=createNativeModules.js.map
|
|
@@ -17,16 +17,11 @@ export function startBackgroundThread(uiThreadPort, mainThreadPort) {
|
|
|
17
17
|
markTimingInternal('load_core_start');
|
|
18
18
|
mainThreadRpc.registerHandler(BackgroundThreadStartEndpoint, async (config) => {
|
|
19
19
|
markTimingInternal('load_core_end');
|
|
20
|
-
const
|
|
21
|
-
? (await import(
|
|
22
|
-
/* webpackIgnore: true */ config.nativeModulesUrl))?.default ?? {}
|
|
23
|
-
: {};
|
|
24
|
-
const nativeApp = createNativeApp({
|
|
20
|
+
const nativeApp = await createNativeApp({
|
|
25
21
|
...config,
|
|
26
22
|
uiThreadRpc,
|
|
27
23
|
mainThreadRpc,
|
|
28
24
|
markTimingInternal,
|
|
29
|
-
customNativeModules,
|
|
30
25
|
});
|
|
31
26
|
globalThis['napiLoaderOnRT' + nativeApp.id] =
|
|
32
27
|
await createNapiLoader(uiThreadRpc, config.napiModulesMap);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
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
|
-
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint, flushElementTreeEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { BackgroundThreadStartEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, onLifecycleEventEndpoint, flushElementTreeEndpoint, reportErrorEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { MainThreadRuntime } from '@lynx-js/web-mainthread-apis';
|
|
7
7
|
import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCallLepusMethodHandler.js';
|
|
@@ -17,16 +17,17 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
17
17
|
const __OnLifecycleEvent = backgroundThreadRpc.createCall(onLifecycleEventEndpoint);
|
|
18
18
|
const mainThreadChunkReady = uiThreadRpc.createCall(mainThreadChunkReadyEndpoint);
|
|
19
19
|
const flushElementTree = uiThreadRpc.createCall(flushElementTreeEndpoint);
|
|
20
|
+
const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
|
|
20
21
|
markTimingInternal('lepus_excute_start');
|
|
21
22
|
uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
|
|
22
|
-
const { globalProps, template,
|
|
23
|
+
const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, } = config;
|
|
23
24
|
const { styleInfo, pageConfig, customSections, cardType, lepusCode } = template;
|
|
24
25
|
markTimingInternal('decode_start');
|
|
25
26
|
await import(
|
|
26
27
|
/* webpackIgnore: true */ template.lepusCode.root);
|
|
27
28
|
const entry = globalThis.module.exports;
|
|
28
29
|
const runtime = new MainThreadRuntime({
|
|
29
|
-
|
|
30
|
+
tagMap,
|
|
30
31
|
browserConfig,
|
|
31
32
|
customSections,
|
|
32
33
|
globalProps,
|
|
@@ -51,16 +52,14 @@ export function startMainThread(uiThreadPort, backgroundThreadPort) {
|
|
|
51
52
|
template,
|
|
52
53
|
cardType: cardType ?? 'react',
|
|
53
54
|
customSections: Object.fromEntries(Object.entries(customSections).filter(([, value]) => value.type !== 'lazy').map(([k, v]) => [k, v.content])),
|
|
54
|
-
|
|
55
|
+
nativeModulesMap,
|
|
55
56
|
napiModulesMap,
|
|
56
57
|
});
|
|
57
58
|
runtime.renderPage(initData);
|
|
58
59
|
runtime.__FlushElementTree(undefined, {});
|
|
59
60
|
},
|
|
60
61
|
flushElementTree,
|
|
61
|
-
_ReportError:
|
|
62
|
-
console.error('main-thread:', error, info);
|
|
63
|
-
},
|
|
62
|
+
_ReportError: reportError,
|
|
64
63
|
__OnLifecycleEvent,
|
|
65
64
|
/**
|
|
66
65
|
* Note :
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-worker-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@lynx-js/web-constants": "0.
|
|
26
|
-
"@lynx-js/web-
|
|
27
|
-
"@lynx-js/web-
|
|
25
|
+
"@lynx-js/web-constants": "0.9.1",
|
|
26
|
+
"@lynx-js/web-worker-rpc": "0.9.1",
|
|
27
|
+
"@lynx-js/web-mainthread-apis": "0.9.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@lynx-js/lynx-core": "0.1.0"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
|
-
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
-
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { reportErrorEndpoint } from '@lynx-js/web-constants';
|
|
5
|
-
export function createReportError(rpc) {
|
|
6
|
-
return (error, info) => {
|
|
7
|
-
rpc.invoke(reportErrorEndpoint, ['main-thread', error.toString(), info]);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=createReportError.js.map
|