@lynx-js/web-worker-runtime 0.15.7 → 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,29 @@
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
+
3
27
  ## 0.15.7
4
28
 
5
29
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { callLepusMethodEndpoint, setNativePropsEndpoint, triggerComponentEventEndpoint, selectComponentEndpoint, systemInfo, I18nResource, reportErrorEndpoint, globalDisallowedVars, } from '@lynx-js/web-constants';
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, browserConfig, } = config;
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,33 +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
- if (typeof prop === 'string' && globalDisallowedVars.includes(prop)) {
32
- return undefined;
33
- }
34
- // @ts-expect-error
35
- return target[prop] ?? globalThis[prop];
36
- },
37
- set(target, prop, value) {
38
- // @ts-expect-error
39
- target[prop] = value;
40
- return true;
41
- },
42
- ownKeys(target) {
43
- return Reflect.ownKeys(target).filter((key) => key !== 'globalThis');
44
- },
45
- });
46
- Object.assign(lynxCoreInject.tt, {
47
- SystemInfo: { ...systemInfo, ...browserConfig },
48
- });
49
- const ret = entry?.(lynxCoreInject.tt);
50
- return ret;
51
- },
52
- };
26
+ return entry;
53
27
  };
54
28
  const i18nResource = new I18nResource();
55
29
  let release = '';
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export interface WorkerStartMessage {
2
2
  mode: 'main' | 'background';
3
3
  toPeerThread: MessagePort;
4
4
  toUIThread: MessagePort;
5
+ systemInfo?: Record<string, any>;
5
6
  }
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
- import { startMainThreadWorker } from './mainThread/startMainThread.js';
6
- globalThis.onmessage = (ev) => {
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 docu = new OffscreenDocument({
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, docu[_onEvent]);
57
+ uiThreadRpc.registerHandler(postOffscreenEventEndpoint, document[_onEvent]);
28
58
  const sendMultiThreadExposureChangedEndpoint = uiThreadRpc.createCall(multiThreadExposureChangedEndpoint);
29
- const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, docu, docu.createElement.bind(docu), (exposureChangedElementUniqueIds) => {
30
- docu.commit();
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).then((runtime) => {
40
- registerUpdateDataHandler(uiThreadRpc, runtime);
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.15.7",
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/offscreen-document": "0.1.3",
26
- "@lynx-js/web-constants": "0.15.7",
27
- "@lynx-js/web-mainthread-apis": "0.15.7",
28
- "@lynx-js/web-worker-rpc": "0.15.7"
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"