@open-wxa/wxa-runner-core 0.3.2 → 0.4.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/README.md +2 -2
- package/dist/runtime/host.js +44 -0
- package/dist/runtime/host.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
[`@open-wxa/wxa-runner-playwright`](https://www.npmjs.com/package/@open-wxa/wxa-runner-playwright)。以下情况把它加为开发依赖:
|
|
7
7
|
|
|
8
8
|
- setup 文件要类型提示:`import { defineSetup } from '@open-wxa/wxa-runner-core/setup'`,见
|
|
9
|
-
[
|
|
9
|
+
[启动前准备(setup)](https://open-wxa.github.io/wxa-runner/setup)
|
|
10
10
|
- 不用 fixture、直接使用测试 API:`/// <reference types="@open-wxa/wxa-runner-core/test-api" />` 为
|
|
11
|
-
`window.__wxa_test_api__` 提供类型,见 [
|
|
11
|
+
`window.__wxa_test_api__` 提供类型,见 [测试 API](https://open-wxa.github.io/wxa-runner/test-api)
|
|
12
12
|
- 在 Node 里启动开发服务器:
|
|
13
13
|
|
|
14
14
|
```ts
|
package/dist/runtime/host.js
CHANGED
|
@@ -1250,6 +1250,46 @@
|
|
|
1250
1250
|
};
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
1253
|
+
// src/runtime/host/api/subpackages.ts
|
|
1254
|
+
function createSubpackageApis(options) {
|
|
1255
|
+
const names = /* @__PURE__ */ new Set(["__APP__"]);
|
|
1256
|
+
for (const pkg of options.subPackages) {
|
|
1257
|
+
names.add(normalizeName(pkg.root));
|
|
1258
|
+
if (pkg.name) names.add(normalizeName(pkg.name));
|
|
1259
|
+
}
|
|
1260
|
+
let taskSeq2 = 0;
|
|
1261
|
+
const createLoadSubPackageTask = (args, { api }) => {
|
|
1262
|
+
const moduleName = args.moduleName;
|
|
1263
|
+
if (typeof moduleName !== "string" || !moduleName || !names.has(normalizeName(moduleName))) {
|
|
1264
|
+
return fail(api, "module not found");
|
|
1265
|
+
}
|
|
1266
|
+
const loadTaskId = String(++taskSeq2);
|
|
1267
|
+
setTimeout(() => {
|
|
1268
|
+
const event = { taskId: loadTaskId, moduleName };
|
|
1269
|
+
options.emit("onLoadSubPackageTaskStateChange", {
|
|
1270
|
+
...event,
|
|
1271
|
+
state: "progressUpdate",
|
|
1272
|
+
progress: 100,
|
|
1273
|
+
// 没有网络下载,不伪造传输字节数。
|
|
1274
|
+
totalBytesWritten: 0,
|
|
1275
|
+
totalBytesExpectedToWrite: 0
|
|
1276
|
+
});
|
|
1277
|
+
options.emit("onLoadSubPackageTaskStateChange", { ...event, state: "success" });
|
|
1278
|
+
}, 0);
|
|
1279
|
+
return ok(api, { loadTaskId });
|
|
1280
|
+
};
|
|
1281
|
+
return {
|
|
1282
|
+
createLoadSubPackageTask,
|
|
1283
|
+
// 事件已由桥接广播,具体监听与回调由基础库管理,无需另建一套订阅状态。
|
|
1284
|
+
listenLoadSubPackageTaskStateChange: (_args, { api }) => ok(api),
|
|
1285
|
+
// 分包加载完成后渲染层请求注入分包的模板和样式,它们已经打进 page-frame.js,回调后基础库替换占位组件。
|
|
1286
|
+
injectSubPackages: (_args, { api }) => ok(api)
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
function normalizeName(name) {
|
|
1290
|
+
return name.replace(/^\.?\//, "").replace(/\/$/, "");
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1253
1293
|
// src/runtime/host/api/system.ts
|
|
1254
1294
|
var NAVIGATION_BAR_HEIGHT = 44;
|
|
1255
1295
|
var TAB_BAR_HEIGHT = 50;
|
|
@@ -2495,6 +2535,10 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2495
2535
|
reLaunch: routeApi((args) => this.reLaunch(args.url)),
|
|
2496
2536
|
switchTab: routeApi((args) => this.switchTab(args.url)),
|
|
2497
2537
|
...createStorageApis(this.storage),
|
|
2538
|
+
...createSubpackageApis({
|
|
2539
|
+
subPackages: this.info.wxConfig.subPackages || [],
|
|
2540
|
+
emit: (event, data) => this.emitToService(event, data)
|
|
2541
|
+
}),
|
|
2498
2542
|
...createSavedFileApis(this.storage),
|
|
2499
2543
|
...createFileSystemApis(),
|
|
2500
2544
|
...createSystemApis({
|