@lynx-js/template-webpack-plugin-canary 0.10.1 → 0.10.2-canary-20260116-ff5a5b09

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,11 @@
1
1
  # @lynx-js/template-webpack-plugin
2
2
 
3
+ ## 0.10.2-canary-20260116094314-ff5a5b09d069df0e851e0e84a33c2147d537309e
4
+
5
+ ### Patch Changes
6
+
7
+ - Polyfill `lynx.requireModuleAsync` to allow cache same parallel requests. ([#2108](https://github.com/lynx-family/lynx-stack/pull/2108))
8
+
3
9
  ## 0.10.1
4
10
 
5
11
  ### Patch Changes
@@ -106,16 +112,16 @@
106
112
  type InlineChunkConfig =
107
113
  | boolean
108
114
  | InlineChunkTest
109
- | { enable?: boolean | 'auto'; test: InlineChunkTest };
115
+ | { enable?: boolean | "auto"; test: InlineChunkTest };
110
116
  ```
111
117
 
112
118
  ```ts
113
- import { defineConfig } from '@lynx-js/rspeedy';
119
+ import { defineConfig } from "@lynx-js/rspeedy";
114
120
 
115
121
  export default defineConfig({
116
122
  output: {
117
123
  inlineScripts: ({ name, size }) => {
118
- return name.includes('foo') && size < 1000;
124
+ return name.includes("foo") && size < 1000;
119
125
  },
120
126
  },
121
127
  });
@@ -165,7 +171,7 @@
165
171
  example:
166
172
 
167
173
  ```js
168
- import { defineConfig } from '@lynx-js/rspeedy';
174
+ import { defineConfig } from "@lynx-js/rspeedy";
169
175
 
170
176
  export default defineConfig({
171
177
  output: {
@@ -260,7 +266,7 @@
260
266
  - Add `defaultOverflowVisible` option to `LynxTemplatePlugin`. ([#78](https://github.com/lynx-family/lynx-stack/pull/78))
261
267
 
262
268
  ```js
263
- import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
269
+ import { LynxTemplatePlugin } from "@lynx-js/template-webpack-plugin";
264
270
 
265
271
  new LynxTemplatePlugin({
266
272
  defaultOverflowVisible: false,
@@ -279,10 +285,10 @@
279
285
  - 1abf8f0: Add `entryNames` parameter to `beforeEncode` hook.
280
286
 
281
287
  ```js
282
- import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
288
+ import { LynxTemplatePlugin } from "@lynx-js/template-webpack-plugin";
283
289
 
284
290
  const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
285
- hooks.beforeEncode.tap('MyPlugin', ({ entryNames }) => {
291
+ hooks.beforeEncode.tap("MyPlugin", ({ entryNames }) => {
286
292
  console.log(entryNames);
287
293
  });
288
294
  ```
@@ -2,6 +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 { LynxTemplatePlugin } from './LynxTemplatePlugin.js';
5
+ import { getRequireModuleAsyncCachePolyfill } from './polyfill/requireModuleAsync.js';
5
6
  /**
6
7
  * LynxEncodePlugin
7
8
  *
@@ -176,6 +177,7 @@ export class LynxEncodePluginImpl {
176
177
  const parts = [];
177
178
  const externalKeys = Object.keys(externalManifest);
178
179
  if (externalKeys.length > 0) {
180
+ parts.push(getRequireModuleAsyncCachePolyfill());
179
181
  const externalRequires = externalKeys
180
182
  .map(name => `lynx.requireModuleAsync(${JSON.stringify(this.#formatJSName(name, publicPath))})`)
181
183
  .join(',');
@@ -36,7 +36,7 @@ export interface EncodeOptions {
36
36
  * compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
37
37
  * console.log("The compiler is starting a new compilation...");
38
38
  *
39
- * LynxTemplatePlugin.getCompilationHooks(compilation).beforeEmit.tapAsync(
39
+ * LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation).beforeEmit.tapAsync(
40
40
  * "MyPlugin", // <-- Set a meaningful name here for stacktraces
41
41
  * (data, cb) => {
42
42
  * // Manipulate the content
@@ -57,27 +57,45 @@ export class WebEncodePlugin {
57
57
  });
58
58
  return encodeOptions;
59
59
  });
60
- hooks.encode.tap({
60
+ hooks.encode.tapPromise({
61
61
  name: WebEncodePlugin.name,
62
62
  stage: WebEncodePlugin.ENCODE_HOOK_STAGE,
63
- }, ({ encodeOptions }) => {
64
- return {
65
- buffer: Buffer.from(JSON.stringify({
66
- styleInfo: genStyleInfo(encodeOptions['css'].cssMap),
67
- manifest: encodeOptions.manifest,
68
- cardType: encodeOptions['cardType'],
69
- appType: encodeOptions['appType'],
70
- pageConfig: encodeOptions['pageConfig'],
71
- lepusCode: {
72
- // flatten the lepusCode to a single object
73
- ...encodeOptions.lepusCode.lepusChunk,
74
- root: encodeOptions.lepusCode.root,
75
- },
76
- customSections: encodeOptions.customSections,
77
- elementTemplate: encodeOptions['elementTemplate'],
78
- })),
79
- debugInfo: '',
63
+ }, async ({ encodeOptions }) => {
64
+ const tasmJSONInfo = {
65
+ styleInfo: encodeOptions['css'].cssMap,
66
+ manifest: encodeOptions.manifest,
67
+ cardType: encodeOptions['cardType'],
68
+ appType: encodeOptions['appType'],
69
+ pageConfig: encodeOptions['pageConfig'],
70
+ lepusCode: {
71
+ // flatten the lepusCode to a single object
72
+ ...encodeOptions.lepusCode.lepusChunk,
73
+ root: encodeOptions.lepusCode.root,
74
+ },
75
+ customSections: encodeOptions.customSections ?? {},
76
+ elementTemplates: encodeOptions['elementTemplates'] ?? {},
80
77
  };
78
+ const isExperimentalWebBinary = !!process
79
+ .env['EXPERIMENTAL_USE_WEB_BINARY_TEMPLATE'];
80
+ if (isExperimentalWebBinary) {
81
+ const { encode } = await import('@lynx-js/web-core-wasm/encode')
82
+ .catch(() => {
83
+ throw new Error(`FLAG EXPERIMENTAL_USE_WEB_BINARY_TEMPLATE IS INTERNAL USED ONLY`);
84
+ });
85
+ return {
86
+ buffer: Buffer.from(encode(tasmJSONInfo)),
87
+ debugInfo: '',
88
+ };
89
+ }
90
+ else {
91
+ return {
92
+ buffer: Buffer.from(JSON.stringify({
93
+ ...tasmJSONInfo,
94
+ styleInfo: genStyleInfo(tasmJSONInfo['styleInfo']),
95
+ }), 'utf-8'),
96
+ debugInfo: '',
97
+ };
98
+ }
81
99
  });
82
100
  });
83
101
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A runtime polyfill for `lynx.requireModuleAsync` with cache.
3
+ * After polyfill, `lynx.requireModuleAsync()` call will be cached even if it is not finished.
4
+ *
5
+ * Eg.
6
+ * ```
7
+ * lynx.requireModuleAsync('module1', function (error, value) {
8
+ * console.log(error, value);
9
+ * });
10
+ * lynx.requireModuleAsync('module1', function (error, value) {
11
+ * console.log(error, value);
12
+ * });
13
+ * ```
14
+ * The second `lynx.requireModuleAsync('module1')` call will reuse the first call's result. And there will be only "EvalScript" call in lynx core
15
+ */
16
+ export declare function getRequireModuleAsyncCachePolyfill(): string;
@@ -0,0 +1,52 @@
1
+ // Copyright 2026 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
+ /**
5
+ * A runtime polyfill for `lynx.requireModuleAsync` with cache.
6
+ * After polyfill, `lynx.requireModuleAsync()` call will be cached even if it is not finished.
7
+ *
8
+ * Eg.
9
+ * ```
10
+ * lynx.requireModuleAsync('module1', function (error, value) {
11
+ * console.log(error, value);
12
+ * });
13
+ * lynx.requireModuleAsync('module1', function (error, value) {
14
+ * console.log(error, value);
15
+ * });
16
+ * ```
17
+ * The second `lynx.requireModuleAsync('module1')` call will reuse the first call's result. And there will be only "EvalScript" call in lynx core
18
+ */
19
+ export function getRequireModuleAsyncCachePolyfill() {
20
+ return `
21
+ {
22
+ var moduleCache = {};
23
+ var oldRequireModuleAsync = lynx.requireModuleAsync;
24
+ lynx.requireModuleAsync = function (moduleUrl, callback) {
25
+ var cacheEntry = moduleCache[moduleUrl];
26
+ if (cacheEntry) {
27
+ if (cacheEntry.status === 2)
28
+ return callback && callback(cacheEntry.error, cacheEntry.value);
29
+ if (cacheEntry.status === 1) {
30
+ if (callback) cacheEntry.callbacks.push(callback);
31
+ return;
32
+ }
33
+ }
34
+ moduleCache[moduleUrl] = {
35
+ status: 1,
36
+ callbacks: callback ? [callback] : [],
37
+ };
38
+ oldRequireModuleAsync.call(lynx, moduleUrl, function (error, value) {
39
+ var cacheEntry = moduleCache[moduleUrl];
40
+ cacheEntry.status = 2;
41
+ cacheEntry.error = error;
42
+ cacheEntry.value = value;
43
+ for (var i = 0; i < cacheEntry.callbacks.length; i++)
44
+ cacheEntry.callbacks[i](error, value);
45
+ cacheEntry.callbacks.length = 0;
46
+ });
47
+ };
48
+ Object.assign(lynx.requireModuleAsync, oldRequireModuleAsync);
49
+ }
50
+ ;`;
51
+ }
52
+ //# sourceMappingURL=requireModuleAsync.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/template-webpack-plugin-canary",
3
- "version": "0.10.1",
3
+ "version": "0.10.2-canary-20260116-ff5a5b09",
4
4
  "description": "Simplifies creation of Lynx template files to serve your webpack bundles",
5
5
  "keywords": [
6
6
  "webpack",
@@ -44,8 +44,9 @@
44
44
  "@types/css-tree": "^2.3.11",
45
45
  "@types/object.groupby": "^1.0.4",
46
46
  "css-loader": "^7.1.2",
47
- "webpack": "^5.102.0",
47
+ "webpack": "^5.104.1",
48
48
  "@lynx-js/test-tools": "0.0.0",
49
+ "@lynx-js/web-core-wasm": "npm:@lynx-js/web-core-wasm-canary@0.0.1-canary-20260116-ff5a5b09",
49
50
  "@lynx-js/vitest-setup": "0.0.0"
50
51
  },
51
52
  "engines": {