@lynx-js/web-worker-runtime 0.16.0 → 0.17.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,25 @@
1
1
  # @lynx-js/web-worker-runtime
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`721635d`](https://github.com/lynx-family/lynx-stack/commit/721635de6c1d2d617c7cbaa86e7d816c42d62930), [`93d707b`](https://github.com/lynx-family/lynx-stack/commit/93d707b82a59f7256952e21da6dcad2999f8233d), [`d150ed4`](https://github.com/lynx-family/lynx-stack/commit/d150ed440a4f1e9d9a3a2911adf6e6fa39a0c589)]:
8
+ - @lynx-js/web-mainthread-apis@0.17.0
9
+ - @lynx-js/web-constants@0.17.0
10
+ - @lynx-js/web-worker-rpc@0.17.0
11
+
12
+ ## 0.16.1
13
+
14
+ ### Patch Changes
15
+
16
+ - feat: supports lazy bundle. (This feature requires `@lynx-js/lynx-core >= 0.1.3`) ([#1235](https://github.com/lynx-family/lynx-stack/pull/1235))
17
+
18
+ - Updated dependencies [[`608f375`](https://github.com/lynx-family/lynx-stack/commit/608f375e20732cc4c9f141bfbf9800ba6896100b)]:
19
+ - @lynx-js/web-mainthread-apis@0.16.1
20
+ - @lynx-js/web-constants@0.16.1
21
+ - @lynx-js/web-worker-rpc@0.16.1
22
+
3
23
  ## 0.16.0
4
24
 
5
25
  ### Minor Changes
@@ -12,4 +12,12 @@ export declare function createBackgroundLynx(config: BackMainThreadContextConfig
12
12
  animate(operation: import("@lynx-js/web-constants").AnimationOperation, id: string, keyframes?: Record<string, any>[], timingOptions?: Record<string, any>): void;
13
13
  };
14
14
  getI18nResource: () => import("@lynx-js/web-constants").Cloneable;
15
+ QueryComponent: (source: string, callback: (ret: {
16
+ __hasReady: boolean;
17
+ } | {
18
+ code: number;
19
+ detail?: {
20
+ schema: string;
21
+ };
22
+ }) => void) => void;
15
23
  };
@@ -31,6 +31,7 @@ export function createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadR
31
31
  return createElement(id, uiThreadRpc);
32
32
  },
33
33
  getI18nResource: () => nativeApp.i18nResource.data,
34
+ QueryComponent: (source, callback) => nativeApp.queryComponent(source, callback),
34
35
  };
35
36
  }
36
37
  //# sourceMappingURL=createBackgroundLynx.js.map
@@ -1,4 +1,4 @@
1
- import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, I18nResource, reportErrorEndpoint, } from '@lynx-js/web-constants';
1
+ import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, I18nResource, reportErrorEndpoint, queryComponentEndpoint, updateBTSTemplateCacheEndpoint, } 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';
@@ -20,11 +20,18 @@ export async function createNativeApp(config) {
20
20
  const setNativeProps = uiThreadRpc.createCall(setNativePropsEndpoint);
21
21
  const triggerComponentEvent = uiThreadRpc.createCall(triggerComponentEventEndpoint);
22
22
  const selectComponent = uiThreadRpc.createCallbackify(selectComponentEndpoint, 3);
23
+ const queryComponent = mainThreadRpc.createCall(queryComponentEndpoint);
23
24
  const reportError = uiThreadRpc.createCall(reportErrorEndpoint);
24
25
  const createBundleInitReturnObj = () => {
25
- const entry = globalThis.module.exports;
26
- return entry;
26
+ const ret = globalThis.module.exports ?? globalThis.__bundle__holder;
27
+ globalThis.module.exports = null;
28
+ globalThis.__bundle__holder = null;
29
+ return ret;
27
30
  };
31
+ const templateCache = new Map([['__Card__', template]]);
32
+ mainThreadRpc.registerHandler(updateBTSTemplateCacheEndpoint, (url, template) => {
33
+ templateCache.set(url, template);
34
+ });
28
35
  const i18nResource = new I18nResource();
29
36
  let release = '';
30
37
  const nativeApp = {
@@ -35,20 +42,32 @@ export async function createNativeApp(config) {
35
42
  clearTimeout: clearTimeout,
36
43
  clearInterval: clearInterval,
37
44
  nativeModuleProxy: await createNativeModules(uiThreadRpc, mainThreadRpc, nativeModulesMap),
38
- loadScriptAsync: function (sourceURL, callback) {
39
- const manifestUrl = template.manifest[`/${sourceURL}`];
45
+ loadScriptAsync: function (sourceURL, callback, entryName) {
46
+ entryName = entryName ?? '__Card__';
47
+ const manifestUrl = templateCache.get(entryName)
48
+ ?.manifest[`/${sourceURL}`];
40
49
  if (manifestUrl)
41
50
  sourceURL = manifestUrl;
51
+ else
52
+ throw Error(`Cannot find ${sourceURL} in manifest`);
53
+ globalThis.module.exports = null;
54
+ globalThis.__bundle__holder = null;
42
55
  import(
43
56
  /* webpackIgnore: true */
44
57
  sourceURL).catch(callback).then(async () => {
45
58
  callback(null, createBundleInitReturnObj());
46
59
  });
47
60
  },
48
- loadScript: (sourceURL) => {
49
- const manifestUrl = template.manifest[`/${sourceURL}`];
61
+ loadScript: (sourceURL, entryName) => {
62
+ entryName = entryName ?? '__Card__';
63
+ const manifestUrl = templateCache.get(entryName)
64
+ ?.manifest[`/${sourceURL}`];
50
65
  if (manifestUrl)
51
66
  sourceURL = manifestUrl;
67
+ else
68
+ throw Error(`Cannot find ${sourceURL} in manifest`);
69
+ globalThis.module.exports = null;
70
+ globalThis.__bundle__holder = null;
52
71
  importScripts(sourceURL);
53
72
  return createBundleInitReturnObj();
54
73
  },
@@ -62,6 +81,7 @@ export async function createNativeApp(config) {
62
81
  setNativeProps,
63
82
  getPathInfo: createGetPathInfo(uiThreadRpc),
64
83
  invokeUIMethod: createInvokeUIMethod(uiThreadRpc),
84
+ tt: null,
65
85
  setCard(tt) {
66
86
  registerPublicComponentEventHandler(mainThreadRpc, tt);
67
87
  registerPublishEventHandler(mainThreadRpc, tt);
@@ -72,6 +92,7 @@ export async function createNativeApp(config) {
72
92
  registerUpdateI18nResource(uiThreadRpc, mainThreadRpc, i18nResource, tt);
73
93
  timingSystem.registerGlobalEmitter(tt.GlobalEventEmitter);
74
94
  tt.lynx.getCoreContext().__start();
95
+ nativeApp.tt = tt;
75
96
  },
76
97
  triggerComponentEvent,
77
98
  selectComponent,
@@ -85,6 +106,16 @@ export async function createNativeApp(config) {
85
106
  i18nResource,
86
107
  reportException: (err, _) => reportError(err, _, release),
87
108
  __SetSourceMapRelease: (err) => release = err.message,
109
+ queryComponent: (source, callback) => {
110
+ if (templateCache.has(source)) {
111
+ callback({ __hasReady: true });
112
+ }
113
+ else {
114
+ queryComponent(source).then(res => {
115
+ callback?.(res);
116
+ });
117
+ }
118
+ },
88
119
  };
89
120
  return nativeApp;
90
121
  }
@@ -26,7 +26,11 @@ export function startBackgroundThread(uiThreadPort, mainThreadPort) {
26
26
  globalThis['napiLoaderOnRT' + nativeApp.id] =
27
27
  await createNapiLoader(uiThreadRpc, config.napiModulesMap);
28
28
  const nativeLynx = createBackgroundLynx(config, nativeApp, mainThreadRpc, uiThreadRpc);
29
- lynxCore.then(({ loadCard, destroyCard, callDestroyLifetimeFun }) => {
29
+ lynxCore.then(({ loadCard, destroyCard, callDestroyLifetimeFun, nativeGlobal, loadDynamicComponent, }) => {
30
+ // @lynx-js/lynx-core >= 0.1.3 will export nativeGlobal and loadDynamicComponent
31
+ if (nativeGlobal && loadDynamicComponent) {
32
+ nativeGlobal.loadDynamicComponent = loadDynamicComponent;
33
+ }
30
34
  loadCard(nativeApp, {
31
35
  ...config,
32
36
  // @ts-ignore
@@ -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 { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, dispatchLynxViewEventEndpoint, i18nResourceMissedEventName, I18nResources, updateI18nResourcesEndpoint, multiThreadExposureChangedEndpoint, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
4
+ import { flushElementTreeEndpoint, mainThreadStartEndpoint, postOffscreenEventEndpoint, reportErrorEndpoint, dispatchLynxViewEventEndpoint, i18nResourceMissedEventName, I18nResources, updateI18nResourcesEndpoint, multiThreadExposureChangedEndpoint, lynxUniqueIdAttribute, loadTemplateMultiThread, } from '@lynx-js/web-constants';
5
5
  import { Rpc } from '@lynx-js/web-worker-rpc';
6
6
  import { createMarkTimingInternal } from './crossThreadHandlers/createMainthreadMarkTimingInternal.js';
7
7
  import { OffscreenDocument } from '@lynx-js/offscreen-document/webworker';
@@ -15,15 +15,19 @@ const { prepareMainThreadAPIs } = await import(
15
15
  /* webpackFetchPriority: "high" */
16
16
  '@lynx-js/web-mainthread-apis');
17
17
  function loadScriptSync(url) {
18
+ globalThis.module.exports = null;
18
19
  importScripts(url);
19
- return globalThis.module?.exports;
20
+ const ret = globalThis.module?.exports;
21
+ return ret;
20
22
  }
21
23
  function loadScript(url) {
22
24
  return new Promise((resolve, reject) => {
23
25
  fetch(url)
24
26
  .then(() => {
27
+ globalThis.module.exports = null;
25
28
  importScripts(url);
26
- resolve(globalThis.module?.exports);
29
+ const ret = globalThis.module?.exports;
30
+ resolve(ret);
27
31
  }).catch(reject);
28
32
  });
29
33
  }
@@ -56,6 +60,7 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
56
60
  const i18nResources = new I18nResources();
57
61
  uiThreadRpc.registerHandler(postOffscreenEventEndpoint, document[_onEvent]);
58
62
  const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
63
+ const loadTemplate = uiThreadRpc.createCall(loadTemplateMultiThread);
59
64
  const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, document, // rootDom
60
65
  document, mtsRealm, (exposureChangedElementUniqueIds) => {
61
66
  document.commit();
@@ -65,12 +70,12 @@ export async function startMainThreadWorker(uiThreadPort, backgroundThreadPort)
65
70
  }, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, (initI18nResources) => {
66
71
  i18nResources.setData(initI18nResources);
67
72
  return i18nResources;
68
- });
73
+ }, loadTemplate);
69
74
  uiThreadRpc.registerHandler(mainThreadStartEndpoint, async (config) => {
70
75
  await startMainThread(config);
71
76
  registerUpdateDataHandler(uiThreadRpc, globalThis);
72
77
  });
73
- uiThreadRpc?.registerHandler(updateI18nResourcesEndpoint, data => {
78
+ uiThreadRpc.registerHandler(updateI18nResourcesEndpoint, data => {
74
79
  i18nResources.setData(data);
75
80
  });
76
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-worker-runtime",
3
- "version": "0.16.0",
3
+ "version": "0.17.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/web-mainthread-apis": "0.16.0",
26
25
  "@lynx-js/offscreen-document": "0.1.4",
27
- "@lynx-js/web-constants": "0.16.0",
28
- "@lynx-js/web-worker-rpc": "0.16.0"
26
+ "@lynx-js/web-constants": "0.17.0",
27
+ "@lynx-js/web-mainthread-apis": "0.17.0",
28
+ "@lynx-js/web-worker-rpc": "0.17.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@lynx-js/lynx-core": "0.1.3"