@open-wxa/wxa-runner-core 0.10.0 → 0.10.1
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/dist/runtime/host.js +18 -4
- package/dist/runtime/host.js.map +1 -1
- package/package.json +3 -3
package/dist/runtime/host.js
CHANGED
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
var MINI_PROGRAM_ERROR = /^(\(in promise\) )?MiniProgramError\n/;
|
|
9
9
|
var MODULE_URL = /\bhttps?:\/\/[^/\s]+\/__wxa__\/module\/([^?\s)]+?)(?:\?[^:\s)]*)?:(\d+):(\d+)/;
|
|
10
10
|
var ConsoleForwarder = class {
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @param pageOf 出错的页面路径,不知道时返回 undefined
|
|
13
|
+
* @param hintsOf 附在报错后面的提示,帮开发者认出 wxa-runner 和真机不同造成的错误
|
|
14
|
+
*/
|
|
15
|
+
constructor(mode, send, pageOf, hintsOf = () => []) {
|
|
13
16
|
this.mode = mode;
|
|
14
17
|
this.send = send;
|
|
15
18
|
this.pageOf = pageOf;
|
|
19
|
+
this.hintsOf = hintsOf;
|
|
16
20
|
this.recentErrors = /* @__PURE__ */ new Map();
|
|
17
21
|
}
|
|
18
22
|
/** 运行时错误:全局 error、未处理的 Promise 拒绝、基础库捕获的业务代码错误 */
|
|
@@ -20,8 +24,10 @@
|
|
|
20
24
|
const frames = businessFrames(stack);
|
|
21
25
|
if (!this.mode || this.isRepeated(`${kind}:${webviewId}:${message}
|
|
22
26
|
${frames}`)) return;
|
|
27
|
+
const hints = this.hintsOf(kind).map((hint) => `
|
|
28
|
+
\u63D0\u793A\uFF1A${hint}`).join("");
|
|
23
29
|
this.post("error", `${this.origin(kind, webviewId)}\u62A5\u9519\uFF1A${message}${frames ? `
|
|
24
|
-
${frames}` : ""}`);
|
|
30
|
+
${frames}` : ""}${hints}`);
|
|
25
31
|
}
|
|
26
32
|
/** 运行时自己的提醒,如调用了未实现的 wx API */
|
|
27
33
|
warn(text) {
|
|
@@ -2568,7 +2574,8 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2568
2574
|
this.forwarder = new ConsoleForwarder(
|
|
2569
2575
|
info.forwardConsole ?? false,
|
|
2570
2576
|
sendReport,
|
|
2571
|
-
(kind, webviewId) => kind === "service" ? this.currentPage()?.path : this.pages.get(webviewId)?.path
|
|
2577
|
+
(kind, webviewId) => kind === "service" ? this.currentPage()?.path : this.pages.get(webviewId)?.path,
|
|
2578
|
+
(kind) => this.launchHints(kind)
|
|
2572
2579
|
);
|
|
2573
2580
|
this.shell = new PhoneShell(root, info.device);
|
|
2574
2581
|
this.tabPaths = new Set((info.wxConfig.tabBar?.list || []).map((item) => stripHtml(item.pagePath)));
|
|
@@ -2719,6 +2726,13 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2719
2726
|
this.errors.push({ kind: "service", webviewId: 0, api, message });
|
|
2720
2727
|
this.forwarder.warn(message);
|
|
2721
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* 逻辑层在首页创建前出错时的提示:onLaunch、启动阶段的接口回调里读 getCurrentPages()[0] 是常见原因,
|
|
2731
|
+
* 而报错本身只说读不到某个属性。被拦截的请求立即返回,比真机更容易在首页创建前执行回调
|
|
2732
|
+
*/
|
|
2733
|
+
launchHints(kind) {
|
|
2734
|
+
return kind === "service" && !this.currentPage() ? ["\u51FA\u9519\u65F6\u9996\u9875\u8FD8\u6CA1\u521B\u5EFA\uFF0CgetCurrentPages() \u8FD4\u56DE\u7684\u662F\u7A7A\u6570\u7EC4"] : [];
|
|
2735
|
+
}
|
|
2722
2736
|
// ---------------------------------------------------------------------------
|
|
2723
2737
|
// 路由
|
|
2724
2738
|
// ---------------------------------------------------------------------------
|