@lynx-js/template-webpack-plugin-canary 0.10.1-canary-20251226-f8b5be81 → 0.10.2-canary-20260116-ce265e8f
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,6 +1,12 @@
|
|
|
1
1
|
# @lynx-js/template-webpack-plugin
|
|
2
2
|
|
|
3
|
-
## 0.10.
|
|
3
|
+
## 0.10.2-canary-20260116085656-ce265e8ff3d1a19e2f5b1b689fcb136c18c7913d
|
|
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
|
+
|
|
9
|
+
## 0.10.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
6
12
|
|
package/lib/LynxEncodePlugin.js
CHANGED
|
@@ -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.
|
|
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
|
package/lib/WebEncodePlugin.js
CHANGED
|
@@ -57,27 +57,45 @@ export class WebEncodePlugin {
|
|
|
57
57
|
});
|
|
58
58
|
return encodeOptions;
|
|
59
59
|
});
|
|
60
|
-
hooks.encode.
|
|
60
|
+
hooks.encode.tapPromise({
|
|
61
61
|
name: WebEncodePlugin.name,
|
|
62
62
|
stage: WebEncodePlugin.ENCODE_HOOK_STAGE,
|
|
63
|
-
}, ({ encodeOptions }) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
lepusCode
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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.
|
|
3
|
+
"version": "0.10.2-canary-20260116-ce265e8f",
|
|
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.
|
|
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-ce265e8f",
|
|
49
50
|
"@lynx-js/vitest-setup": "0.0.0"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|