miaoda-expo-devkit 0.1.1-beta.121 → 0.1.1-beta.124
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 +1 -1
- package/dist/cli/lint.js +100 -44
- package/dist/rules/no-typeof-window-check.js +85 -3
- package/docs/devkit-lint.md +62 -2
- package/docs/patches.md +5 -4
- package/docs/stubs.md +2 -0
- package/package.json +1 -1
- package/pnpm-patches/@expo__metro-runtime@55.0.11-55.0.12.patch +26 -0
- package/pnpm-patches/expo@55.0.6.patch +158 -47
- package/pnpm-patches/react-native@0.83.2.patch +99 -10
- package/pnpmfile.cjs +18 -6
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ Sentry.init({
|
|
|
78
78
|
|
|
79
79
|
- `console.warn`、`console.error` 不再弹出 LogBox 底部通知;
|
|
80
80
|
- 原始日志仍会输出到 Metro、ADB 或 Xcode 控制台;
|
|
81
|
-
- 未捕获的 JavaScript
|
|
81
|
+
- 未捕获的 JavaScript 异常继续展示错误详情;未处理的 Promise 拒绝由 RN 与 Expo runtime 托管补丁单独自动打开详情,不受普通通知隐藏影响;
|
|
82
82
|
- 如需临时恢复 LogBox,可在应用调试代码中调用 `LogBox.ignoreAllLogs(false)`。
|
|
83
83
|
|
|
84
84
|
该策略属于 JavaScript Bundle 的公共启动注入,不修改业务页面,也不需要在每个应用中重复配置。未使用
|
package/dist/cli/lint.js
CHANGED
|
@@ -17173,9 +17173,9 @@ var require_build = __commonJS({
|
|
|
17173
17173
|
|
|
17174
17174
|
// src/cli/lint.ts
|
|
17175
17175
|
var import_node_child_process = require("child_process");
|
|
17176
|
-
var
|
|
17177
|
-
var
|
|
17178
|
-
var
|
|
17176
|
+
var import_node_fs3 = require("fs");
|
|
17177
|
+
var import_node_module2 = require("module");
|
|
17178
|
+
var import_node_path4 = require("path");
|
|
17179
17179
|
var import_schemer = __toESM(require_build());
|
|
17180
17180
|
|
|
17181
17181
|
// src/schemas/app-config-schema-v55.json
|
|
@@ -17383,12 +17383,93 @@ function getOxlintIgnoreArgs() {
|
|
|
17383
17383
|
return OXLINT_IGNORE_PATTERNS.flatMap((pattern) => ["--ignore-pattern", pattern]);
|
|
17384
17384
|
}
|
|
17385
17385
|
|
|
17386
|
+
// src/checks/expo-config.ts
|
|
17387
|
+
var import_node_fs2 = require("fs");
|
|
17388
|
+
var import_node_module = require("module");
|
|
17389
|
+
var import_node_path3 = require("path");
|
|
17390
|
+
function record(value) {
|
|
17391
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
17392
|
+
}
|
|
17393
|
+
function isAbsoluteHttpUrl(value) {
|
|
17394
|
+
if (typeof value !== "string") return false;
|
|
17395
|
+
const lower = value.toLowerCase();
|
|
17396
|
+
if (!lower.startsWith("https://") && !lower.startsWith("http://")) return false;
|
|
17397
|
+
try {
|
|
17398
|
+
const url = new URL(value);
|
|
17399
|
+
return (url.protocol === "https:" || url.protocol === "http:") && url.hostname !== "";
|
|
17400
|
+
} catch {
|
|
17401
|
+
return false;
|
|
17402
|
+
}
|
|
17403
|
+
}
|
|
17404
|
+
function collectExpoRouterConfigIssues(exp) {
|
|
17405
|
+
const config = record(exp);
|
|
17406
|
+
const router = record(record(config?.extra)?.router);
|
|
17407
|
+
if (!router) return [];
|
|
17408
|
+
const issues = [];
|
|
17409
|
+
for (const field of ["origin", "headOrigin", "generatedOrigin"]) {
|
|
17410
|
+
const value = router[field];
|
|
17411
|
+
if (value == null || field === "origin" && value === false) continue;
|
|
17412
|
+
if (!isAbsoluteHttpUrl(value)) {
|
|
17413
|
+
issues.push({
|
|
17414
|
+
field: "extra.router." + field,
|
|
17415
|
+
value,
|
|
17416
|
+
reason: "\u5FC5\u987B\u662F\u5B8C\u6574\u7684 HTTP/HTTPS URL\uFF0C\u4E0D\u80FD\u4F7F\u7528\u76F8\u5BF9\u8DEF\u5F84\u3001\u65E0\u534F\u8BAE\u57DF\u540D\u3001\u7A7A\u5B57\u7B26\u4E32\u6216 true\u3002Expo SDK 55 \u7684 Location/Head/RSC \u4F1A\u6D88\u8D39\u8FD9\u4E9B\u503C\uFF1B\u65E0\u6548 origin \u53EF\u80FD\u5728\u9996\u5C4F\u6CE8\u518C\u524D\u5BFC\u81F4 Invalid URL \u6216 replace is not a function\uFF0CheadOrigin \u4F1A\u5F71\u54CD Head/RSC\u3002"
|
|
17417
|
+
});
|
|
17418
|
+
}
|
|
17419
|
+
}
|
|
17420
|
+
const experiments = record(config?.experiments);
|
|
17421
|
+
if (router.origin === false && (experiments?.reactServerComponentRoutes || experiments?.reactServerFunctions)) {
|
|
17422
|
+
issues.push({
|
|
17423
|
+
field: "extra.router.origin",
|
|
17424
|
+
value: false,
|
|
17425
|
+
reason: "Expo SDK 55 \u542F\u7528 reactServerComponentRoutes/reactServerFunctions \u65F6\u4E0D\u80FD\u5173\u95ED origin\uFF1B\u8BF7\u5220\u9664 origin: false\uFF0C\u8BA9 Expo \u81EA\u52A8\u5904\u7406\uFF0C\u6216\u914D\u7F6E\u5B9E\u9645\u670D\u52A1\u7684\u5B8C\u6574 URL\u3002"
|
|
17426
|
+
});
|
|
17427
|
+
}
|
|
17428
|
+
return issues;
|
|
17429
|
+
}
|
|
17430
|
+
var CONFIG_FILES = [
|
|
17431
|
+
"app.json",
|
|
17432
|
+
"app.config.json",
|
|
17433
|
+
...["ts", "mts", "cts", "mjs", "cjs", "js"].map((ext) => "app.config." + ext)
|
|
17434
|
+
];
|
|
17435
|
+
function checkExpoConfig(projectRoot) {
|
|
17436
|
+
if (!CONFIG_FILES.some((file) => (0, import_node_fs2.existsSync)((0, import_node_path3.join)(projectRoot, file)))) return true;
|
|
17437
|
+
try {
|
|
17438
|
+
const projectRequire = (0, import_node_module.createRequire)((0, import_node_path3.join)(projectRoot, "package.json"));
|
|
17439
|
+
const expoDir = (0, import_node_path3.dirname)(projectRequire.resolve("expo/package.json"));
|
|
17440
|
+
const req = (0, import_node_module.createRequire)((0, import_node_path3.join)(expoDir, "index.js"));
|
|
17441
|
+
const { getConfig } = req("@expo/config");
|
|
17442
|
+
const config = getConfig(projectRoot, { skipSDKVersionRequirement: true });
|
|
17443
|
+
const issues = collectExpoRouterConfigIssues(config.exp);
|
|
17444
|
+
if (issues.length === 0) return true;
|
|
17445
|
+
console.error("\n[expo-router-config]");
|
|
17446
|
+
console.error(config.dynamicConfigPath ?? config.staticConfigPath ?? projectRoot);
|
|
17447
|
+
for (const issue of issues) {
|
|
17448
|
+
console.error(" " + issue.field + " = " + JSON.stringify(issue.value) + " \u2014 " + issue.reason);
|
|
17449
|
+
}
|
|
17450
|
+
console.error('\u5982\u65E0\u81EA\u5B9A\u4E49\u751F\u4EA7\u7AD9\u70B9\u9700\u6C42\uFF0C\u8BF7\u5220\u9664 expo-router \u63D2\u4EF6\u53C2\u6570\u548C extra.router \u4E2D\u7684\u9519\u8BEF origin/headOrigin\uFF0C\u6062\u590D\u6A21\u677F\u9ED8\u8BA4\u7684 "expo-router" \u63D2\u4EF6\u3002generatedOrigin \u901A\u5E38\u7531 Expo \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u5DE5\u586B\u76F8\u5BF9\u8DEF\u5F84\u3002');
|
|
17451
|
+
return false;
|
|
17452
|
+
} catch (e) {
|
|
17453
|
+
console.error("\n[expo-config]");
|
|
17454
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
17455
|
+
try {
|
|
17456
|
+
const appJson = JSON.parse((0, import_node_fs2.readFileSync)((0, import_node_path3.join)(projectRoot, "app.json"), "utf8"));
|
|
17457
|
+
if (appJson?.expo?.plugins) {
|
|
17458
|
+
console.error("\napp.json plugins:");
|
|
17459
|
+
console.error(JSON.stringify(appJson.expo.plugins, null, 2));
|
|
17460
|
+
}
|
|
17461
|
+
} catch {
|
|
17462
|
+
}
|
|
17463
|
+
return false;
|
|
17464
|
+
}
|
|
17465
|
+
}
|
|
17466
|
+
|
|
17386
17467
|
// src/cli/lint.ts
|
|
17387
|
-
var devkitRoot = (0,
|
|
17388
|
-
var oxlintConfig = (0,
|
|
17389
|
-
var biomeConfig = (0,
|
|
17390
|
-
var projectBiomeConfig = (0,
|
|
17391
|
-
var activeBiomeConfig = (0,
|
|
17468
|
+
var devkitRoot = (0, import_node_path4.resolve)(__dirname, "../..");
|
|
17469
|
+
var oxlintConfig = (0, import_node_path4.join)(devkitRoot, "oxlint-config.json");
|
|
17470
|
+
var biomeConfig = (0, import_node_path4.join)(devkitRoot, "biome-config.json");
|
|
17471
|
+
var projectBiomeConfig = (0, import_node_path4.join)(process.cwd(), "biome.json");
|
|
17472
|
+
var activeBiomeConfig = (0, import_node_fs3.existsSync)(projectBiomeConfig) ? projectBiomeConfig : biomeConfig;
|
|
17392
17473
|
var targets = process.argv.slice(2);
|
|
17393
17474
|
var lintTargets = targets.length > 0 ? targets : ["."];
|
|
17394
17475
|
var oxlintIgnoreArgs = getOxlintIgnoreArgs();
|
|
@@ -17400,13 +17481,13 @@ function run(name, cmd, args) {
|
|
|
17400
17481
|
function generateTypedRoutes() {
|
|
17401
17482
|
const projectRoot = process.cwd();
|
|
17402
17483
|
try {
|
|
17403
|
-
const appJson = JSON.parse((0,
|
|
17484
|
+
const appJson = JSON.parse((0, import_node_fs3.readFileSync)((0, import_node_path4.join)(projectRoot, "app.json"), "utf8"));
|
|
17404
17485
|
const routerRoot = appJson?.expo?.router?.root ?? "src";
|
|
17405
|
-
process.env.EXPO_ROUTER_APP_ROOT = (0,
|
|
17406
|
-
const expoRouterDir = (0,
|
|
17486
|
+
process.env.EXPO_ROUTER_APP_ROOT = (0, import_node_path4.join)(projectRoot, routerRoot, "app");
|
|
17487
|
+
const expoRouterDir = (0, import_node_path4.dirname)(
|
|
17407
17488
|
require.resolve("expo-router/package.json", { paths: [projectRoot] })
|
|
17408
17489
|
);
|
|
17409
|
-
const req = (0,
|
|
17490
|
+
const req = (0, import_node_module2.createRequire)((0, import_node_path4.join)(expoRouterDir, "index.js"));
|
|
17410
17491
|
const { getTypedRoutesDeclarationFile } = req("@expo/router-server/build/typed-routes/generate");
|
|
17411
17492
|
const ctx = req("expo-router/internal/testing").requireContext(
|
|
17412
17493
|
process.env.EXPO_ROUTER_APP_ROOT,
|
|
@@ -17414,44 +17495,19 @@ function generateTypedRoutes() {
|
|
|
17414
17495
|
req("expo-router/_ctx-shared").EXPO_ROUTER_CTX_IGNORE
|
|
17415
17496
|
);
|
|
17416
17497
|
const content = getTypedRoutesDeclarationFile(ctx);
|
|
17417
|
-
const typesDir = (0,
|
|
17418
|
-
(0,
|
|
17419
|
-
(0,
|
|
17498
|
+
const typesDir = (0, import_node_path4.join)(projectRoot, ".expo/types");
|
|
17499
|
+
(0, import_node_fs3.mkdirSync)(typesDir, { recursive: true });
|
|
17500
|
+
(0, import_node_fs3.writeFileSync)((0, import_node_path4.join)(typesDir, "router.d.ts"), content);
|
|
17420
17501
|
} catch {
|
|
17421
17502
|
}
|
|
17422
17503
|
}
|
|
17423
|
-
function validateExpoConfig() {
|
|
17424
|
-
const projectRoot = process.cwd();
|
|
17425
|
-
if (!(0, import_node_fs2.existsSync)((0, import_node_path3.join)(projectRoot, "app.json"))) return true;
|
|
17426
|
-
try {
|
|
17427
|
-
const expoDir = (0, import_node_path3.dirname)(require.resolve("expo/package.json", { paths: [projectRoot] }));
|
|
17428
|
-
const req = (0, import_node_module.createRequire)((0, import_node_path3.join)(expoDir, "index.js"));
|
|
17429
|
-
const { getConfig } = req("@expo/config");
|
|
17430
|
-
getConfig(projectRoot, { skipSDKVersionRequirement: true });
|
|
17431
|
-
return true;
|
|
17432
|
-
} catch (e) {
|
|
17433
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
17434
|
-
console.error("\n[expo-config]");
|
|
17435
|
-
console.error(message);
|
|
17436
|
-
try {
|
|
17437
|
-
const appJson = JSON.parse((0, import_node_fs2.readFileSync)((0, import_node_path3.join)(projectRoot, "app.json"), "utf8"));
|
|
17438
|
-
const plugins = appJson?.expo?.plugins;
|
|
17439
|
-
if (plugins) {
|
|
17440
|
-
console.error("\napp.json plugins:");
|
|
17441
|
-
console.error(JSON.stringify(plugins, null, 2));
|
|
17442
|
-
}
|
|
17443
|
-
} catch {
|
|
17444
|
-
}
|
|
17445
|
-
return false;
|
|
17446
|
-
}
|
|
17447
|
-
}
|
|
17448
17504
|
async function validateAppJsonSchema() {
|
|
17449
17505
|
const projectRoot = process.cwd();
|
|
17450
|
-
const appJsonPath = (0,
|
|
17451
|
-
if (!(0,
|
|
17506
|
+
const appJsonPath = (0, import_node_path4.join)(projectRoot, "app.json");
|
|
17507
|
+
if (!(0, import_node_fs3.existsSync)(appJsonPath)) return true;
|
|
17452
17508
|
let appJson;
|
|
17453
17509
|
try {
|
|
17454
|
-
appJson = JSON.parse((0,
|
|
17510
|
+
appJson = JSON.parse((0, import_node_fs3.readFileSync)(appJsonPath, "utf8"));
|
|
17455
17511
|
} catch {
|
|
17456
17512
|
console.error(`[app.json] Failed to parse ${appJsonPath}`);
|
|
17457
17513
|
return false;
|
|
@@ -17479,7 +17535,7 @@ async function main() {
|
|
|
17479
17535
|
run("biome", "biome", ["lint", "--config-path", activeBiomeConfig, ...lintTargets]);
|
|
17480
17536
|
generateTypedRoutes();
|
|
17481
17537
|
run("tsc", "tsc", ["--noEmit"]);
|
|
17482
|
-
const expoConfigOk =
|
|
17538
|
+
const expoConfigOk = checkExpoConfig(process.cwd());
|
|
17483
17539
|
results.push({ name: "expo-config", ok: expoConfigOk });
|
|
17484
17540
|
const appJsonOk = await validateAppJsonSchema();
|
|
17485
17541
|
results.push({ name: "app.json", ok: appJsonOk });
|
|
@@ -27,6 +27,7 @@ var SNIFF_GLOBALS = /* @__PURE__ */ new Set(["window", "document"]);
|
|
|
27
27
|
var HOST_GLOBALS = /* @__PURE__ */ new Set(["global", "globalThis"]);
|
|
28
28
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
29
29
|
var WEB_ONLY_FILE = /\.web\.[jt]sx?$/;
|
|
30
|
+
var NODE_CONFIG_FILE = /(?:^|[/\\])[^/\\]*\.config\.[cm]?[jt]s$/;
|
|
30
31
|
function sniffedGlobalName(node) {
|
|
31
32
|
if (!node) return null;
|
|
32
33
|
if (node.type === "Identifier" && node.name && SNIFF_GLOBALS.has(node.name)) {
|
|
@@ -49,14 +50,91 @@ var noTypeofWindowCheckRule = {
|
|
|
49
50
|
},
|
|
50
51
|
schema: [],
|
|
51
52
|
messages: {
|
|
52
|
-
unreliableEnvCheck: "'typeof {{name}}' cannot detect the browser in React Native \u2014 RN sets global.window = global (and some libraries install incomplete window/document shims), so this check also passes on native, and browser-only APIs will crash at runtime. Use Platform.OS from 'react-native' or process.env.EXPO_OS === 'web' instead."
|
|
53
|
+
unreliableEnvCheck: "'typeof {{name}}' cannot detect the browser in React Native \u2014 RN sets global.window = global (and some libraries install incomplete window/document shims), so this check also passes on native, and browser-only APIs will crash at runtime. Use Platform.OS from 'react-native' or process.env.EXPO_OS === 'web' instead. SSR capability checks are allowed inside an explicit web-only branch."
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
create(context) {
|
|
56
|
-
const isWebOnlyFile = typeof context.filename === "string" && WEB_ONLY_FILE.test(context.filename);
|
|
57
|
+
const isWebOnlyFile = typeof context.filename === "string" && (WEB_ONLY_FILE.test(context.filename) || NODE_CONFIG_FILE.test(context.filename));
|
|
58
|
+
let isDomComponent = false;
|
|
59
|
+
const platformBindings = /* @__PURE__ */ new Set();
|
|
60
|
+
function binding(name, at) {
|
|
61
|
+
let scope = context.sourceCode.getScope(at);
|
|
62
|
+
for (; ; ) {
|
|
63
|
+
const variable = scope.set.get(name);
|
|
64
|
+
if (variable) return variable;
|
|
65
|
+
if (!scope.upper) return void 0;
|
|
66
|
+
scope = scope.upper;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function member(node, property) {
|
|
70
|
+
return node?.type === "MemberExpression" && !node.computed && node.property?.name === property ? node.object : void 0;
|
|
71
|
+
}
|
|
72
|
+
function isPlatformOS(node) {
|
|
73
|
+
const platform = member(node, "OS");
|
|
74
|
+
if (platform?.type === "Identifier" && platform.name) {
|
|
75
|
+
return binding(platform.name, node)?.identifiers.some((id) => platformBindings.has(id)) ?? false;
|
|
76
|
+
}
|
|
77
|
+
const process = member(member(node, "EXPO_OS"), "env");
|
|
78
|
+
return process?.type === "Identifier" && process.name === "process" && !binding("process", node)?.defs.length;
|
|
79
|
+
}
|
|
80
|
+
function webFacts(node) {
|
|
81
|
+
if (!node) return [false, false];
|
|
82
|
+
if (node.type === "UnaryExpression" && node.operator === "!") {
|
|
83
|
+
const [yes, no] = webFacts(node.argument);
|
|
84
|
+
return [no, yes];
|
|
85
|
+
}
|
|
86
|
+
if (node.type === "LogicalExpression") {
|
|
87
|
+
const [ly, ln] = webFacts(node.left);
|
|
88
|
+
const [ry, rn] = webFacts(node.right);
|
|
89
|
+
if (node.operator === "&&") return [ly || ry, ln && rn];
|
|
90
|
+
if (node.operator === "||") return [ly && ry, ln || rn];
|
|
91
|
+
}
|
|
92
|
+
if (node.type === "BinaryExpression" && (node.operator === "===" || node.operator === "!==")) {
|
|
93
|
+
for (const [a, b] of [[node.left, node.right], [node.right, node.left]]) {
|
|
94
|
+
if (a && b?.type === "Literal" && b.value === "web" && isPlatformOS(a)) {
|
|
95
|
+
return node.operator === "===" ? [true, false] : [false, true];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return [false, false];
|
|
100
|
+
}
|
|
101
|
+
function isInsideWebBranch(node) {
|
|
102
|
+
const ancestors = context.sourceCode.getAncestors(node);
|
|
103
|
+
let child = node;
|
|
104
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
105
|
+
const parent = ancestors[i];
|
|
106
|
+
if ([
|
|
107
|
+
"FunctionDeclaration",
|
|
108
|
+
"FunctionExpression",
|
|
109
|
+
"ArrowFunctionExpression",
|
|
110
|
+
"ClassDeclaration",
|
|
111
|
+
"ClassExpression"
|
|
112
|
+
].includes(parent.type)) break;
|
|
113
|
+
if ((parent.type === "IfStatement" || parent.type === "ConditionalExpression") && (parent.consequent === child && webFacts(parent.test)[0] || parent.alternate === child && webFacts(parent.test)[1])) return true;
|
|
114
|
+
if (parent.type === "LogicalExpression" && parent.right === child && (parent.operator === "&&" && webFacts(parent.left)[0] || parent.operator === "||" && webFacts(parent.left)[1])) return true;
|
|
115
|
+
child = parent;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
57
119
|
return {
|
|
120
|
+
Program(node) {
|
|
121
|
+
const program = node;
|
|
122
|
+
for (const statement of program.body ?? []) {
|
|
123
|
+
if (statement.type === "ExpressionStatement" && typeof statement.directive === "string") {
|
|
124
|
+
if (statement.directive === "use dom") isDomComponent = true;
|
|
125
|
+
} else break;
|
|
126
|
+
}
|
|
127
|
+
for (const statement of program.body ?? []) {
|
|
128
|
+
if (statement.type !== "ImportDeclaration" || statement.source?.value !== "react-native" || statement.importKind === "type") continue;
|
|
129
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
130
|
+
if (specifier.type === "ImportSpecifier" && specifier.imported?.name === "Platform" && specifier.importKind !== "type") {
|
|
131
|
+
platformBindings.add(specifier.local);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
58
136
|
BinaryExpression(node) {
|
|
59
|
-
if (isWebOnlyFile) return;
|
|
137
|
+
if (isWebOnlyFile || isDomComponent) return;
|
|
60
138
|
const binary = node;
|
|
61
139
|
if (!binary.operator || !EQUALITY_OPERATORS.has(binary.operator)) return;
|
|
62
140
|
for (const [typeofSide, otherSide] of [
|
|
@@ -66,6 +144,10 @@ var noTypeofWindowCheckRule = {
|
|
|
66
144
|
const name = typeofSniffedGlobal(typeofSide);
|
|
67
145
|
if (!name) continue;
|
|
68
146
|
if (otherSide?.type !== "Literal" || typeof otherSide.value !== "string") continue;
|
|
147
|
+
const target = typeofSide.argument;
|
|
148
|
+
const root = target.type === "Identifier" ? target : target.object;
|
|
149
|
+
if (root.name && binding(root.name, binary)?.defs.length) continue;
|
|
150
|
+
if (isInsideWebBranch(binary)) continue;
|
|
69
151
|
context.report({
|
|
70
152
|
node: typeofSide,
|
|
71
153
|
messageId: "unreliableEnvCheck",
|
package/docs/devkit-lint.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# devkit-lint
|
|
2
2
|
|
|
3
|
-
`devkit-lint`
|
|
3
|
+
`devkit-lint` 是内置的检查命令,一次执行包含源码、配置和资源检查:
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
oxlint
|
|
6
|
+
oxlint → biome → tsc --noEmit → Expo 插件/Router 配置 → app.json schema → 资源检查
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
所有阶段都会跑完再退出,最终汇总哪个阶段失败。
|
|
@@ -37,6 +37,66 @@ bun run lint
|
|
|
37
37
|
RESULT: FAILED — Found errors in: app.json
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Expo Router 生产 URL 保护(Expo SDK 55)
|
|
41
|
+
|
|
42
|
+
配置检查阶段在执行官方插件校验后,检查最终的 `exp.extra.router`,而不是锁死
|
|
43
|
+
`plugins` 数组。支持 `app.json`、`app.config.json` 和 Expo 55 支持的动态配置文件;
|
|
44
|
+
以动态配置和插件处理后的值为准,同一配置只报告一次,不自动改写。
|
|
45
|
+
|
|
46
|
+
- `origin`:生产站点/服务地址。原生 runtime 用它建立 `window.location`,并为以 `/`
|
|
47
|
+
开头的 fetch 地址补齐 origin;开发环境通常使用 Metro 地址。它不是相对资源路径。
|
|
48
|
+
- `headOrigin`:Head/iOS Handoff 使用的站点地址;Expo Router 55 的 Head/RSC
|
|
49
|
+
URL helper 也会优先读取它。没有单独需求时不设置。
|
|
50
|
+
- `generatedOrigin`:Expo 部署时生成的地址,作为未指定 origin 时的回退;一般不手工设置。
|
|
51
|
+
|
|
52
|
+
这些 URL 必须是可解析的完整 HTTP/HTTPS URL。允许 localhost、IP、端口和合法子路径,
|
|
53
|
+
不检查域名可达性,也不禁止其他合法 Router 参数。`./`、`/`、无协议域名、空字符串、
|
|
54
|
+
`origin: true` 等按错误拦截。`origin: false` 在普通客户端项目中允许,但不能与
|
|
55
|
+
`experiments.reactServerComponentRoutes` / `reactServerFunctions` 一起使用。
|
|
56
|
+
未指定或 nullish 的运行时值允许由 Expo 回退,插件参数本身仍须通过官方 schema。
|
|
57
|
+
|
|
58
|
+
真实故障是 `origin: "./"` 在原生正式包中先被去掉末尾斜杠,再传给 `new URL(".")`,
|
|
59
|
+
在应用注册前触发 `Invalid URL: .`。官方插件 schema 仅要求字符串/布尔值,无法拦截。
|
|
60
|
+
|
|
61
|
+
默认模板保持 `"expo-router"`,不强制添加 origin,不用 `origin: false` 替代默认配置。
|
|
62
|
+
报错示例:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
[expo-router-config]
|
|
66
|
+
/path/to/app.json
|
|
67
|
+
extra.router.origin = "./" — 必须是完整的 HTTP/HTTPS URL……
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
这是 `devkit-lint` 的 CLI 配置检查,不是遍历每个源码文件的 Oxlint 规则。
|
|
71
|
+
跳过 lint 仍然可能漏检;发布流水线应在相同的生产配置环境下运行 lint。
|
|
72
|
+
配置检查不执行部署,未设置的 generatedOrigin 可在后续部署中产生。
|
|
73
|
+
源码依据见 `src/checks/expo-config.ts`;升级 SDK 时须复核对应运行时行为。
|
|
74
|
+
已对照 Expo 仓库 `origin/sdk-55`(`abf258e20`)的 runtime、Router plugin、
|
|
75
|
+
Head/RSC、CLI 配置合并代码,并用当前安装的 Expo 55 源码做隔离执行回归。
|
|
76
|
+
注意:上游源码仓库 main 可能已是 SDK 56,不能用 main 替代 SDK 55 的行为依据。
|
|
77
|
+
|
|
78
|
+
允许 URL 包含子路径不代表支持将它用作部署前缀:原生相对 fetch 使用
|
|
79
|
+
`window.location.origin`,Head/RSC helper 会去掉 pathname、query、hash。
|
|
80
|
+
Web 子路径部署应使用适用的 `experiments.baseUrl`,不要把 origin 改成 `./` 或 `/subpath`。
|
|
81
|
+
|
|
82
|
+
### 浏览器环境检查的边界
|
|
83
|
+
|
|
84
|
+
`no-typeof-window-check` 继续禁止用 `typeof window/document` 单独推断 Web 平台,
|
|
85
|
+
但不应误报明确 Web 分支里的 SSR 能力防御,例如:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
if (process.env.EXPO_OS === 'web') {
|
|
89
|
+
if (typeof window !== 'undefined') {
|
|
90
|
+
// 此处仍需按需检查 API 能力,并处理 localStorage 权限异常。
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
支持直接的 Expo 平台条件及从 `react-native` 导入的 Platform(含导入别名),
|
|
96
|
+
识别 if/else、三元表达式、短路保护和逻辑取反;按词法作用域处理遮蔽。
|
|
97
|
+
`.web.*`、Node 配置文件、`use dom` 组件及局部同名变量不按宿主环境误报。
|
|
98
|
+
不做布尔变量别名、提前 return 或跨函数/类控制流推断,不能以一个 Web 判断豁免整个文件。
|
|
99
|
+
|
|
40
100
|
### Schema 来源与存储
|
|
41
101
|
|
|
42
102
|
Expo 随每个 SDK 版本在其文档站发布版本化 JSON Schema(位于 `docs/public/static/schemas/v{VERSION}/app-config-schema.json`)。devkit 将对应版本的 schema 文件复制到 `src/schemas/app-config-schema-v55.json`,随 CLI bundle(`dist/cli/lint.js`)一起内联打包。
|
package/docs/patches.md
CHANGED
|
@@ -24,7 +24,7 @@ dependency 路径,并写入精确版本和完整性校验;无需在生成产
|
|
|
24
24
|
|
|
25
25
|
## 托管补丁清单
|
|
26
26
|
|
|
27
|
-
DevKit 当前管理以下补丁(
|
|
27
|
+
DevKit 当前管理以下补丁(12 个托管补丁、19 个补丁文件,覆盖 20 个包版本):
|
|
28
28
|
|
|
29
29
|
**当前版本:**
|
|
30
30
|
|
|
@@ -32,7 +32,8 @@ DevKit 当前管理以下补丁(11 个托管补丁、18 个补丁文件,覆
|
|
|
32
32
|
- `expo@55.0.6`(HMR 批量编辑控制的客户端;并固定 `expo-audio@55.0.6` 和 `expo-video@55.0.5` 的 Expo 兼容版本表)
|
|
33
33
|
- `metro-runtime@0.83.3`(HMRClient 透传 `miaoda-hmr-control` 控制消息,并在执行增量前支持异步原生能力检查)
|
|
34
34
|
- `metro-file-map@0.83.3`(`miaodaFlushChanges` 文件监听栅栏,保证恢复时 watcher 已看到全部写入)
|
|
35
|
-
- `react-native@0.83.2`(LogBox
|
|
35
|
+
- `react-native@0.83.2`(LogBox 错误页增强:错误标题映射、一键复制及未处理 Promise 拒绝独立展示)
|
|
36
|
+
- `@expo/metro-runtime@55.0.11-55.0.12`(Expo 覆盖 RN Promise 跟踪器时保留拒绝来源标记;与 RN 补丁配套,不影响普通 console.error 的隐藏策略)
|
|
36
37
|
- `expo-modules-core@55.0.15`(Android CMake 打包 worklets 原生库)
|
|
37
38
|
- `react-native-reanimated@4.2.1`(Android 打包 `libworklets.so` 并关联 worklets 构建任务)
|
|
38
39
|
- `react-native-worklets@0.7.4`(Babel 插件规范化 TypeScript 函数类型)
|
|
@@ -74,8 +75,8 @@ pnpm --dir packages/devkit test:patches
|
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
该命令会自动构建并打包 DevKit,在临时项目中模拟 pnpm 安装 Config Dependency 后的
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
目录布局,安装受支持版本范围内的目标依赖,检查全部托管补丁及 lockfile(数量与
|
|
79
|
+
「托管补丁清单」一节一致,含 CSS interop、Worklets、Skia 的历史 legacy 版本),
|
|
79
80
|
然后执行 frozen-lockfile 复装,并运行真实 Metro 文件监听、HTTP 控制接口和 `/hot`
|
|
80
81
|
WebSocket 回归,最后清理临时目录。它不会运行 Expo Prebuild、Gradle 或 Android 编译。
|
|
81
82
|
|
package/docs/stubs.md
CHANGED
|
@@ -26,6 +26,8 @@ stub 文件位于 `dist/stubs/`,wrapper 的完整清单与组合关系见
|
|
|
26
26
|
|
|
27
27
|
由 iOS/Android 的原生入口 stub 在业务代码前加载,调用 `LogBox.ignoreAllLogs(true)` 隐藏普通错误和警告
|
|
28
28
|
通知。它不删除日志,也不阻止未捕获异常进入自定义错误处理链路。
|
|
29
|
+
RN 托管补丁会为未处理的 Promise 拒绝单独自动打开错误详情,保留非致命级别与调用栈;
|
|
30
|
+
普通 `console.error` 不会自动弹出,即使消息包含 Promise 错误前缀也不例外。
|
|
29
31
|
|
|
30
32
|
### expo-router-entry-native-stub.js
|
|
31
33
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
diff --git a/src/promiseRejectionTracking.native.ts b/src/promiseRejectionTracking.native.ts
|
|
2
|
+
index b730115..fd2ec08 100644
|
|
3
|
+
--- a/src/promiseRejectionTracking.native.ts
|
|
4
|
+
+++ b/src/promiseRejectionTracking.native.ts
|
|
5
|
+
@@ -52,7 +52,7 @@ export function enablePromiseRejectionTracking() {
|
|
6
|
+
const rejectionError = new Error(`${rejectionPrefix} ${message ?? ''}`, {
|
|
7
|
+
cause: rejection,
|
|
8
|
+
});
|
|
9
|
+
- if (typeof rejection === 'object' && 'stack' in rejection) {
|
|
10
|
+
+ if (rejection !== null && typeof rejection === 'object' && 'stack' in rejection) {
|
|
11
|
+
// If original rejection stack exists, use it
|
|
12
|
+
rejectionError.stack = `${rejectionPrefix} ${rejection.stack ?? ''}`;
|
|
13
|
+
} else {
|
|
14
|
+
@@ -60,7 +60,11 @@ export function enablePromiseRejectionTracking() {
|
|
15
|
+
// Stack of the error created here won't be any useful to the user
|
|
16
|
+
rejectionError.stack = `${rejectionPrefix} ${message ?? ''}`;
|
|
17
|
+
}
|
|
18
|
+
- ExceptionsManager.handleException(rejectionError);
|
|
19
|
+
+ // Expo 的原生异常管理器直接转发 RN,使用相同的额外数据键标记拒绝来源。
|
|
20
|
+
+ (rejectionError as Error & { 'RN$ErrorExtraDataKey': Record<string, boolean> })[
|
|
21
|
+
+ 'RN$ErrorExtraDataKey'
|
|
22
|
+
+ ] = { miaodaUnhandledPromiseRejection: true };
|
|
23
|
+
+ ExceptionsManager.handleException(rejectionError, false);
|
|
24
|
+
},
|
|
25
|
+
onHandled: (id) => {
|
|
26
|
+
const warning =
|
|
@@ -21,7 +21,7 @@ index e2b8941..355deae 100644
|
|
|
21
21
|
"jest-expo": "~55.0.9",
|
|
22
22
|
"lottie-react-native": "~7.3.4",
|
|
23
23
|
diff --git a/src/async-require/hmr.ts b/src/async-require/hmr.ts
|
|
24
|
-
index c0ea71e..
|
|
24
|
+
index c0ea71e..b899cb0 100644
|
|
25
25
|
--- a/src/async-require/hmr.ts
|
|
26
26
|
+++ b/src/async-require/hmr.ts
|
|
27
27
|
@@ -11,12 +11,25 @@
|
|
@@ -50,7 +50,7 @@ index c0ea71e..e1789cc 100644
|
|
|
50
50
|
showLoading,
|
|
51
51
|
} from './hmrUtils';
|
|
52
52
|
|
|
53
|
-
@@ -29,8 +42,
|
|
53
|
+
@@ -29,8 +42,246 @@ let hmrClient: MetroHMRClient | null = null;
|
|
54
54
|
let hmrUnavailableReason: string | null = null;
|
|
55
55
|
const buildErrorQueue = new Set<unknown>();
|
|
56
56
|
let didConnect: boolean = false;
|
|
@@ -58,35 +58,73 @@ index c0ea71e..e1789cc 100644
|
|
|
58
58
|
+// miaodaPaused 是 Agent 的编辑闸门,与用户自己的 Fast Refresh 开关
|
|
59
59
|
+// (fastRefreshRequested)相互独立:放行后只有用户开着 Fast Refresh 才恢复更新。
|
|
60
60
|
+let miaodaPaused = false;
|
|
61
|
-
+//
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
+// 展示与执行闸门独立:resume 仅放开闸门,最终增量注入完成才撤罩。
|
|
62
|
+
+let miaodaPresentationVisible = false;
|
|
63
|
+
+// 仅恢复确实因断线让出的遮罩;错误/暂缓等主动让位必须清除此标记。
|
|
64
|
+
+let miaodaPresentationHiddenByDisconnect = false;
|
|
65
|
+
+let miaodaBatchPending = false;
|
|
66
|
+
+let miaodaControlEpoch = 0;
|
|
67
|
+
+const miaodaPresentationListeners = new Set<(visible: boolean) => void>();
|
|
68
|
+
+
|
|
69
|
+
+function setMiaodaPresentation(visible: boolean) {
|
|
70
|
+
+ miaodaPresentationHiddenByDisconnect = false;
|
|
71
|
+
+ if (miaodaPresentationVisible === visible) return;
|
|
72
|
+
+ miaodaPresentationVisible = visible;
|
|
73
|
+
+ for (const listener of miaodaPresentationListeners) {
|
|
74
|
+
+ try { listener(visible); } catch {}
|
|
75
|
+
+ }
|
|
76
|
+
+}
|
|
77
|
+
+
|
|
78
|
+
+function hideMiaodaPresentationForDisconnect() {
|
|
79
|
+
+ const restore = miaodaPresentationVisible || miaodaPresentationHiddenByDisconnect;
|
|
80
|
+
+ setMiaodaPresentation(false);
|
|
81
|
+
+ miaodaPresentationHiddenByDisconnect = restore;
|
|
82
|
+
+}
|
|
83
|
+
+
|
|
84
|
+
+function showMiaodaPausedPresentation() {
|
|
85
|
+
+ setMiaodaPresentation(!miaodaServerDisconnected);
|
|
86
|
+
+ // 新 pause 即使发生于断线中,恢复后也应展示;不能继承旧批次的错误让位。
|
|
87
|
+
+ miaodaPresentationHiddenByDisconnect = miaodaServerDisconnected;
|
|
88
|
+
+}
|
|
64
89
|
+
|
|
65
|
-
+// miaodaPaused 的唯一写入入口:值真正变化时才广播,订阅者异常不能
|
|
66
|
-
+// 反过来打断 HMR 控制链路(ack、reload 等时序敏感操作)。
|
|
67
90
|
+function setMiaodaPaused(paused: boolean) {
|
|
68
91
|
+ if (miaodaPaused === paused) return;
|
|
69
92
|
+ miaodaPaused = paused;
|
|
70
|
-
+
|
|
71
|
-
+
|
|
72
|
-
+
|
|
73
|
-
+ } catch {}
|
|
93
|
+
+ if (paused) {
|
|
94
|
+
+ miaodaBatchPending = true;
|
|
95
|
+
+ showMiaodaPausedPresentation();
|
|
74
96
|
+ }
|
|
75
97
|
+}
|
|
76
98
|
+
|
|
77
|
-
|
|
78
|
-
+
|
|
79
|
-
+
|
|
80
|
-
+
|
|
81
|
-
+
|
|
82
|
-
+
|
|
99
|
+
+export function subscribeMiaodaPresentation(listener: (visible: boolean) => void): () => void {
|
|
100
|
+
+ miaodaPresentationListeners.add(listener);
|
|
101
|
+
+ return () => { miaodaPresentationListeners.delete(listener); };
|
|
102
|
+
+}
|
|
103
|
+
+
|
|
104
|
+
+export function isMiaodaPresentationVisible(): boolean {
|
|
105
|
+
+ return miaodaPresentationVisible;
|
|
83
106
|
+}
|
|
84
107
|
+
|
|
85
|
-
+// 遮罩挂载时读取当前值,避免错过订阅注册之前发生的迁移。
|
|
86
108
|
+export function isMiaodaPaused(): boolean {
|
|
87
109
|
+ return miaodaPaused;
|
|
88
110
|
+}
|
|
89
111
|
+
|
|
112
|
+
+function finishMiaodaBatch() {
|
|
113
|
+
+ // 新 pause 与完整重载优先,迟到的 applied 不能结束它们。
|
|
114
|
+
+ if (miaodaPaused || miaodaReloadIntent || miaodaReloadCommitted) return;
|
|
115
|
+
+ miaodaBatchPending = false;
|
|
116
|
+
+ setMiaodaPresentation(false);
|
|
117
|
+
+}
|
|
118
|
+
+
|
|
119
|
+
+function resumeMiaodaPresentation() {
|
|
120
|
+
+ if (!miaodaBatchPending) return;
|
|
121
|
+
+ if (!fastRefreshRequested && !miaodaReloadIntent) {
|
|
122
|
+
+ finishMiaodaBatch();
|
|
123
|
+
+ return;
|
|
124
|
+
+ }
|
|
125
|
+
+ setMiaodaPresentation(!miaodaServerDisconnected);
|
|
126
|
+
+}
|
|
127
|
+
+
|
|
90
128
|
+let miaodaServerDisconnected = false;
|
|
91
129
|
+// 开发服务器断线状态订阅者:launch/ 里的回退横幅(旧客户端)据此提示用户
|
|
92
130
|
+// Metro 已不可达。新客户端上阻断 UI 由原生阻断页渲染,JS 只上报状态。
|
|
@@ -97,6 +135,7 @@ index c0ea71e..e1789cc 100644
|
|
|
97
135
|
+function setMiaodaServerDisconnected(disconnected: boolean) {
|
|
98
136
|
+ if (miaodaServerDisconnected === disconnected) return;
|
|
99
137
|
+ miaodaServerDisconnected = disconnected;
|
|
138
|
+
+ if (disconnected) hideMiaodaPresentationForDisconnect();
|
|
100
139
|
+ // 新客户端:断线挂原生阻断页(重新尝试 / 退出),恢复时收起。
|
|
101
140
|
+ // 同一时刻只保留一个阻断页且连接优先:热更新确认页已在展示时不再切换
|
|
102
141
|
+ //(该页本身已阻断交互,确认或退出后断线状态仍由轮询驱动重新挂出)。
|
|
@@ -196,6 +235,10 @@ index c0ea71e..e1789cc 100644
|
|
|
196
235
|
+// 避免 Metro 快速重启时闪烁误报;WebSocket close 本身不触发横幅。
|
|
197
236
|
+let miaodaPollFailureCount = 0;
|
|
198
237
|
+const MIAODA_POLL_FAILURE_THRESHOLD = 3;
|
|
238
|
+
+// 轮询单调序号:重试按钮或 WebSocket 重连会与在途定时轮询并发,
|
|
239
|
+
+// 响应可能乱序返回。序号小于最新一轮的响应直接丢弃,防止旧快照
|
|
240
|
+
+// 反向解除新一轮 pause 或触发多余 reload。
|
|
241
|
+
+let miaodaPollSequence = 0;
|
|
199
242
|
const pendingLogs: [LogLevel, any[]][] = [];
|
|
200
243
|
|
|
201
244
|
+// 完整重载是独立于增量的待执行意图。轮询会反复返回同一个版本,用户暂缓后
|
|
@@ -208,6 +251,7 @@ index c0ea71e..e1789cc 100644
|
|
|
208
251
|
+function requestMiaodaReload(key: string) {
|
|
209
252
|
+ if (miaodaReloadCommitted) return;
|
|
210
253
|
+ if (!isMiaodaHmrCompatibilityEnabled()) {
|
|
254
|
+
+ miaodaReloadCommitted = true;
|
|
211
255
|
+ reload();
|
|
212
256
|
+ return;
|
|
213
257
|
+ }
|
|
@@ -224,6 +268,7 @@ index c0ea71e..e1789cc 100644
|
|
|
224
268
|
+ if (!intent || intent.attempted || miaodaReloadChecking || miaodaReloadCommitted || miaodaPaused) return;
|
|
225
269
|
+ // 连接优先于能力:断线期间检查只会得到 unknown,等恢复后由轮询重新驱动。
|
|
226
270
|
+ if (miaodaServerDisconnected) return;
|
|
271
|
+
+ if (miaodaBatchPending) setMiaodaPresentation(true);
|
|
227
272
|
+ intent.attempted = true;
|
|
228
273
|
+ miaodaReloadChecking = true;
|
|
229
274
|
+ const epoch = miaodaReloadEpoch;
|
|
@@ -231,13 +276,17 @@ index c0ea71e..e1789cc 100644
|
|
|
231
276
|
+ try {
|
|
232
277
|
+ if (await checkMiaodaHmrCompatibility(isCurrent) && isCurrent()) {
|
|
233
278
|
+ miaodaReloadCommitted = true;
|
|
279
|
+
+ // 保留旧 JS 遮罩直到树卸载,不把原生启动遮罩误当作 reload 完成信号。
|
|
234
280
|
+ reload();
|
|
281
|
+
+ } else if (isCurrent()) {
|
|
282
|
+
+ setMiaodaPresentation(false);
|
|
235
283
|
+ }
|
|
236
284
|
+ } catch {
|
|
237
285
|
+ // 检查失败保留意图,用户可通过运行中的提示重试;不自动执行新 Bundle。
|
|
286
|
+
+ if (isCurrent()) setMiaodaPresentation(false);
|
|
238
287
|
+ } finally {
|
|
239
288
|
+ miaodaReloadChecking = false;
|
|
240
|
-
+ hideLoading();
|
|
289
|
+
+ if (miaodaReloadIntent === intent && miaodaReloadEpoch === epoch) hideLoading();
|
|
241
290
|
+ // 检查过程中收到更新的重载指令时,旧授权无效,新指令需要自己的检查。
|
|
242
291
|
+ if (miaodaReloadIntent !== intent || miaodaReloadEpoch !== epoch) {
|
|
243
292
|
+ void attemptMiaodaReload();
|
|
@@ -248,7 +297,7 @@ index c0ea71e..e1789cc 100644
|
|
|
248
297
|
type LogLevel =
|
|
249
298
|
| 'trace'
|
|
250
299
|
| 'info'
|
|
251
|
-
@@ -42,6 +
|
|
300
|
+
@@ -42,6 +293,148 @@ type LogLevel =
|
|
252
301
|
| 'groupEnd'
|
|
253
302
|
| 'debug';
|
|
254
303
|
|
|
@@ -275,6 +324,8 @@ index c0ea71e..e1789cc 100644
|
|
|
275
324
|
+
|
|
276
325
|
+async function pollMiaodaStatus() {
|
|
277
326
|
+ if (process.env.EXPO_OS === 'web' || !miaodaStatusHost || miaodaStatusPollingStopped) return;
|
|
327
|
+
+ const controlEpoch = miaodaControlEpoch;
|
|
328
|
+
+ const sequence = ++miaodaPollSequence;
|
|
278
329
|
+ let protocol = miaodaStatusProtocol ?? miaodaStatusInitialProtocol;
|
|
279
330
|
+ try {
|
|
280
331
|
+ let response;
|
|
@@ -288,6 +339,8 @@ index c0ea71e..e1789cc 100644
|
|
|
288
339
|
+ response = await fetch(miaodaStatusUrl(protocol), {headers: {'Cache-Control': 'no-cache'}});
|
|
289
340
|
+ }
|
|
290
341
|
+
|
|
342
|
+
+ // 已有更新一轮轮询发出:本轮的 404/5xx 也是过期结论,不能停止轮询或计入断线。
|
|
343
|
+
+ if (sequence !== miaodaPollSequence) return;
|
|
291
344
|
+ if (response.status === 404) {
|
|
292
345
|
+ // 404 是确定性信号:这个 Metro 实例没有挂载控制路由(未开启
|
|
293
346
|
+ // EXPO_MIAODA_HMR_CONTROL)。停止探测直到 WebSocket 重连,
|
|
@@ -318,6 +371,9 @@ index c0ea71e..e1789cc 100644
|
|
|
318
371
|
+ const state = (await response.json()) as {
|
|
319
372
|
+ paused?: boolean; reloadPending?: boolean; stateVersion?: number; lastMode?: string | null;
|
|
320
373
|
+ };
|
|
374
|
+
+ // HTTP 请求期间若已有新控制帧,或已有更新一轮轮询在途/完成,
|
|
375
|
+
+ // 旧快照不能反向解除新 pause 或触发多余的 reload。
|
|
376
|
+
+ if (controlEpoch !== miaodaControlEpoch || sequence !== miaodaPollSequence) return;
|
|
321
377
|
+ // 拿到合法状态响应说明开发服务器存活:清零失败计数并撤下断线提示。
|
|
322
378
|
+ miaodaPollFailureCount = 0;
|
|
323
379
|
+ setMiaodaServerDisconnected(false);
|
|
@@ -334,6 +390,7 @@ index c0ea71e..e1789cc 100644
|
|
|
334
390
|
+ if (miaodaReloadIntent) miaodaReloadIntent.attempted = false;
|
|
335
391
|
+ }
|
|
336
392
|
+ setMiaodaPaused(true);
|
|
393
|
+
+ if (miaodaPresentationHiddenByDisconnect) setMiaodaPresentation(true);
|
|
337
394
|
+ hmrClient?.disable();
|
|
338
395
|
+ // 把观察到的这次暂停作为本地基线版本。之后若出现没有对应 WebSocket
|
|
339
396
|
+ // 控制消息的新版本,说明错过了状态迁移,必须完整 Bundle reload。
|
|
@@ -351,6 +408,7 @@ index c0ea71e..e1789cc 100644
|
|
|
351
408
|
+ setMiaodaPaused(false);
|
|
352
409
|
+ miaodaLastControlVersion = version;
|
|
353
410
|
+ if (shouldReload) {
|
|
411
|
+
+ if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
|
|
354
412
|
+ requestMiaodaReload(`state:${version}`);
|
|
355
413
|
+ return;
|
|
356
414
|
+ }
|
|
@@ -358,12 +416,24 @@ index c0ea71e..e1789cc 100644
|
|
|
358
416
|
+ void attemptMiaodaReload();
|
|
359
417
|
+ return;
|
|
360
418
|
+ }
|
|
419
|
+
+ // 轮询观察到 paused=false 时按 resume 语义收尾展示:关闭 Fast Refresh
|
|
420
|
+
+ // 或没有待应用增量时撤罩,避免无版本号的状态迁移让遮罩永久残留。
|
|
421
|
+
+ // 只撤不挂:错误/能力暂缓的主动让位不能被轮询重新盖住。
|
|
422
|
+
+ if (miaodaBatchPending) {
|
|
423
|
+
+ if (!fastRefreshRequested && !miaodaReloadIntent) {
|
|
424
|
+
+ finishMiaodaBatch();
|
|
425
|
+
+ } else if (hmrClient != null && !hmrClient.hasPendingUpdates()) {
|
|
426
|
+
+ finishMiaodaBatch();
|
|
427
|
+
+ }
|
|
428
|
+
+ }
|
|
361
429
|
+ if (fastRefreshRequested) HMRClient.enable();
|
|
362
430
|
+ }
|
|
363
431
|
+ } catch {
|
|
364
432
|
+ // 网络错误、超时、响应解析失败都属于暂时故障:不解除编辑闸门,
|
|
365
433
|
+ // 也不停止轮询,下一轮继续。同时计入断线判定:连续多个周期都
|
|
366
434
|
+ // 无法获得可用响应,就广播给顶部横幅提示用户开发服务器不可达。
|
|
435
|
+
+ // 被更新一轮轮询取代的失败同样不计数。
|
|
436
|
+
+ if (sequence !== miaodaPollSequence) return;
|
|
367
437
|
+ miaodaPollFailureCount += 1;
|
|
368
438
|
+ if (miaodaPollFailureCount >= MIAODA_POLL_FAILURE_THRESHOLD) {
|
|
369
439
|
+ setMiaodaServerDisconnected(true);
|
|
@@ -376,7 +446,7 @@ index c0ea71e..e1789cc 100644
|
|
|
376
446
|
function assert(foo: any, msg: string): asserts foo {
|
|
377
447
|
if (!foo) throw new Error(msg);
|
|
378
448
|
}
|
|
379
|
-
@@ -52,6 +
|
|
449
|
+
@@ -52,6 +445,9 @@ function assert(foo: any, msg: string): asserts foo {
|
|
380
450
|
*/
|
|
381
451
|
const HMRClient = {
|
|
382
452
|
enable() {
|
|
@@ -386,15 +456,29 @@ index c0ea71e..e1789cc 100644
|
|
|
386
456
|
if (hmrUnavailableReason !== null) {
|
|
387
457
|
// If HMR became unavailable while you weren't using it,
|
|
388
458
|
// explain why when you try to turn it on.
|
|
389
|
-
@@ -
|
|
459
|
+
@@ -75,6 +471,10 @@ const HMRClient = {
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
hmrClient.enable();
|
|
463
|
+
+ } catch (error) {
|
|
464
|
+
+ // 未启用异步能力 gate 时注入会同步抛错;让错误界面可见但不重放增量。
|
|
465
|
+
+ if (!miaodaPaused) setMiaodaPresentation(false);
|
|
466
|
+
+ throw error;
|
|
467
|
+
} finally {
|
|
468
|
+
if (hasUpdates) {
|
|
469
|
+
hideLoading();
|
|
470
|
+
@@ -87,8 +487,10 @@ const HMRClient = {
|
|
390
471
|
},
|
|
391
472
|
|
|
392
473
|
disable() {
|
|
393
474
|
+ fastRefreshRequested = false;
|
|
394
475
|
assert(hmrClient, 'Expected HMRClient.setup() call at startup.');
|
|
395
476
|
hmrClient.disable();
|
|
477
|
+
+ if (!miaodaPaused && !miaodaReloadIntent) finishMiaodaBatch();
|
|
396
478
|
},
|
|
397
|
-
|
|
479
|
+
|
|
480
|
+
registerBundle(requestUrl: string) {
|
|
481
|
+
@@ -180,6 +582,55 @@ const HMRClient = {
|
|
398
482
|
const origin = `${serverScheme}://${serverHost}`;
|
|
399
483
|
const client = new MetroHMRClient(`${origin}/hot`);
|
|
400
484
|
hmrClient = client;
|
|
@@ -404,15 +488,25 @@ index c0ea71e..e1789cc 100644
|
|
|
404
488
|
+ setUpdateGate: (gate: (isCurrent: () => boolean) => Promise<boolean>) => void;
|
|
405
489
|
+ retryPendingUpdate: () => void;
|
|
406
490
|
+ };
|
|
407
|
-
+ gatedClient.setUpdateGate((isCurrent) =>
|
|
408
|
-
+ () => isCurrent() && hmrClient === client && !miaodaPaused && !miaodaReloadIntent && !miaodaReloadCommitted
|
|
409
|
-
+
|
|
491
|
+
+ gatedClient.setUpdateGate(async (isCurrent) => {
|
|
492
|
+
+ const current = () => isCurrent() && hmrClient === client && !miaodaPaused && !miaodaReloadIntent && !miaodaReloadCommitted;
|
|
493
|
+
+ try {
|
|
494
|
+
+ const allowed = await checkMiaodaHmrCompatibility(current);
|
|
495
|
+
+ // 暂缓让出遮罩给确认/重试入口,但不放行 runtime 缓存的代码。
|
|
496
|
+
+ if (!allowed && current()) setMiaodaPresentation(false);
|
|
497
|
+
+ return allowed;
|
|
498
|
+
+ } catch (error) {
|
|
499
|
+
+ if (current()) setMiaodaPresentation(false);
|
|
500
|
+
+ throw error;
|
|
501
|
+
+ }
|
|
502
|
+
+ });
|
|
410
503
|
+ setMiaodaHmrCompatibilityRetry(() => {
|
|
411
504
|
+ if (miaodaPaused || miaodaReloadCommitted) return;
|
|
412
505
|
+ if (miaodaReloadIntent) {
|
|
413
506
|
+ miaodaReloadIntent.attempted = false;
|
|
414
507
|
+ void attemptMiaodaReload();
|
|
415
508
|
+ } else if (fastRefreshRequested) {
|
|
509
|
+
+ if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
|
|
416
510
|
+ gatedClient.retryPendingUpdate();
|
|
417
511
|
+ }
|
|
418
512
|
+ });
|
|
@@ -423,10 +517,13 @@ index c0ea71e..e1789cc 100644
|
|
|
423
517
|
+ client.on('update-gate-error', () => hideLoading());
|
|
424
518
|
+ client.on('update-apply-error', (error: Error) => {
|
|
425
519
|
+ hideLoading();
|
|
520
|
+
+ if (!miaodaPaused) setMiaodaPresentation(false);
|
|
426
521
|
+ // 模块可能已经部分执行,不能自动重放同一增量;显示错误并保留完整重载入口。
|
|
427
522
|
+ handleCompileError(error);
|
|
428
523
|
+ });
|
|
429
524
|
+ }
|
|
525
|
+
+ // 所有客户端都监听真实注入完成,不限于启用了能力检查的设备。
|
|
526
|
+
+ client.on('update-applied', () => finishMiaodaBatch());
|
|
430
527
|
+ if (process.env.EXPO_OS !== 'web') {
|
|
431
528
|
+ // 仅 native 客户端启用状态轮询。初始协议跟随 bundle URL 的 scheme:
|
|
432
529
|
+ // 设备可能拿到证书无效的 HTTPS 开发地址,也有环境只暴露 HTTPS,
|
|
@@ -437,7 +534,7 @@ index c0ea71e..e1789cc 100644
|
|
|
437
534
|
|
|
438
535
|
pendingEntryPoints.push(
|
|
439
536
|
// HMRServer understands regular bundle URLs, so prefer that in case
|
|
440
|
-
@@ -193,6 +
|
|
537
|
+
@@ -193,6 +644,72 @@ const HMRClient = {
|
|
441
538
|
})
|
|
442
539
|
);
|
|
443
540
|
|
|
@@ -458,6 +555,8 @@ index c0ea71e..e1789cc 100644
|
|
|
458
555
|
+ version: number; action: string; id?: number; error?: any; stateVersion?: number;
|
|
459
556
|
+ }) => {
|
|
460
557
|
+ if (message.version !== 1) return;
|
|
558
|
+
+ if (typeof message.stateVersion === 'number' && miaodaLastControlVersion !== null && message.stateVersion < miaodaLastControlVersion) return;
|
|
559
|
+
+ miaodaControlEpoch += 1;
|
|
461
560
|
+ if (Number.isInteger(message.stateVersion)) {
|
|
462
561
|
+ if (miaodaSessionBaseVersion === null) miaodaSessionBaseVersion = message.stateVersion!;
|
|
463
562
|
+ miaodaStateVersion = message.stateVersion!;
|
|
@@ -470,6 +569,8 @@ index c0ea71e..e1789cc 100644
|
|
|
470
569
|
+ miaodaReloadEpoch += 1;
|
|
471
570
|
+ if (miaodaReloadIntent) miaodaReloadIntent.attempted = false;
|
|
472
571
|
+ setMiaodaPaused(true);
|
|
572
|
+
+ miaodaBatchPending = true;
|
|
573
|
+
+ showMiaodaPausedPresentation();
|
|
473
574
|
+ client.disable();
|
|
474
575
|
+ hideLoading();
|
|
475
576
|
+ client.send(JSON.stringify({type: 'miaoda-hmr-ack', version: 1, id: message.id}));
|
|
@@ -478,19 +579,26 @@ index c0ea71e..e1789cc 100644
|
|
|
478
579
|
+ // 解除 Agent 闸门;用户自己的 Fast Refresh 开关保持独立,
|
|
479
580
|
+ // 只有它开着才真正恢复更新。
|
|
480
581
|
+ setMiaodaPaused(false);
|
|
582
|
+
+ resumeMiaodaPresentation();
|
|
481
583
|
+ if (miaodaReloadIntent) void attemptMiaodaReload();
|
|
482
|
-
+ else if (fastRefreshRequested)
|
|
584
|
+
+ else if (fastRefreshRequested) {
|
|
585
|
+
+ HMRClient.enable();
|
|
586
|
+
+ // resume 是缓存投递屏障;无 graph/空批次不能等待未来事件永挡。
|
|
587
|
+
+ if (!client.hasPendingUpdates()) finishMiaodaBatch();
|
|
588
|
+
+ }
|
|
483
589
|
+ break;
|
|
484
590
|
+ case 'reload':
|
|
485
|
-
+ //
|
|
591
|
+
+ // 完整重载仍保持增量闸门;能力检查暂缓时才让出遮罩。
|
|
486
592
|
+ setMiaodaPaused(false);
|
|
487
593
|
+ client.disable();
|
|
594
|
+
+ if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
|
|
488
595
|
+ requestMiaodaReload(`state:${message.stateVersion ?? 'socket'}`);
|
|
489
596
|
+ break;
|
|
490
597
|
+ case 'error':
|
|
491
598
|
+ // 批次最终编译失败:闸门仍然关着(服务端等 Agent 修好重试),
|
|
492
599
|
+ // 但错误本身要展示出来,因为它在设备端是可行动的。
|
|
493
600
|
+ hideLoading();
|
|
601
|
+
+ setMiaodaPresentation(false);
|
|
494
602
|
+ handleCompileError(message.error);
|
|
495
603
|
+ break;
|
|
496
604
|
+ }
|
|
@@ -499,7 +607,7 @@ index c0ea71e..e1789cc 100644
|
|
|
499
607
|
client.on('connection-error', (e: Error) => {
|
|
500
608
|
setHMRUnavailableReason(getConnectionError(serverHost, e));
|
|
501
609
|
});
|
|
502
|
-
@@ -221,7 +
|
|
610
|
+
@@ -221,7 +738,13 @@ const HMRClient = {
|
|
503
611
|
}) => {
|
|
504
612
|
// NOTE(@krystofwoldrich): I don't know why sometimes empty updates are sent. But they should not reset the overlay.
|
|
505
613
|
const isEmpty = added.length === 0 && modified.length === 0 && deleted.length === 0;
|
|
@@ -514,18 +622,19 @@ index c0ea71e..e1789cc 100644
|
|
|
514
622
|
resetErrorOverlay();
|
|
515
623
|
}
|
|
516
624
|
}
|
|
517
|
-
@@ -234,6 +
|
|
625
|
+
@@ -234,6 +757,11 @@ const HMRClient = {
|
|
518
626
|
client.on('error', (data) => this._onMetroError(data));
|
|
519
627
|
|
|
520
628
|
client.on('close', (closeEvent?: { code: number; reason: string }) => {
|
|
521
629
|
+ // 控制通道断开:之后的版本变化都无法通过 socket 同步,
|
|
522
630
|
+ // 启动轮询兜底直到重连。
|
|
523
631
|
+ miaodaWebSocketDisconnected = true;
|
|
632
|
+
+ hideMiaodaPresentationForDisconnect();
|
|
524
633
|
+ scheduleMiaodaStatusPoll();
|
|
525
634
|
hideLoading();
|
|
526
635
|
const reason = closeEvent?.reason;
|
|
527
636
|
const code = closeEvent?.code || 1000;
|
|
528
|
-
@@ -318,7 +
|
|
637
|
+
@@ -318,7 +846,8 @@ function setHMRUnavailableReason(reason: string) {
|
|
529
638
|
function registerBundleEntryPoints(client: MetroHMRClient | null) {
|
|
530
639
|
if (hmrUnavailableReason != null) {
|
|
531
640
|
// "Bundle Splitting – Metro disconnected"
|
|
@@ -535,7 +644,7 @@ index c0ea71e..e1789cc 100644
|
|
|
535
644
|
return;
|
|
536
645
|
}
|
|
537
646
|
|
|
538
|
-
@@ -326,6 +
|
|
647
|
+
@@ -326,6 +855,9 @@ function registerBundleEntryPoints(client: MetroHMRClient | null) {
|
|
539
648
|
client?.send(
|
|
540
649
|
JSON.stringify({
|
|
541
650
|
type: 'register-entrypoints',
|
|
@@ -1034,35 +1143,37 @@ index 0000000..4aecd61
|
|
|
1034
1143
|
+});
|
|
1035
1144
|
diff --git a/src/launch/MiaodaHmrOverlay.tsx b/src/launch/MiaodaHmrOverlay.tsx
|
|
1036
1145
|
new file mode 100644
|
|
1037
|
-
index 0000000..
|
|
1146
|
+
index 0000000..6d47443
|
|
1038
1147
|
--- /dev/null
|
|
1039
1148
|
+++ b/src/launch/MiaodaHmrOverlay.tsx
|
|
1040
|
-
@@ -0,0 +1,
|
|
1149
|
+
@@ -0,0 +1,60 @@
|
|
1041
1150
|
+import * as React from 'react';
|
|
1042
1151
|
+import { ActivityIndicator, StyleSheet, Text, View } from 'react-native';
|
|
1043
1152
|
+
|
|
1044
|
-
+import {
|
|
1153
|
+
+import { isMiaodaPresentationVisible, subscribeMiaodaPresentation } from '../async-require/hmr';
|
|
1045
1154
|
+
|
|
1046
1155
|
+// Miaoda HMR 批量编辑期间的「更新中」全屏遮罩。
|
|
1047
1156
|
+//
|
|
1048
1157
|
+// Agent 通过 `/_hmr/off` 暂停 HMR 后会连续改写工程文件,这期间设备仍在运行
|
|
1049
1158
|
+// 上一份完好的 JS,但用户看到的是一个随时会被替换掉的界面,继续操作会产生
|
|
1050
1159
|
+// 基于旧代码的困惑交互。遮罩在暂停期间盖住整个应用并吃掉所有触摸,
|
|
1051
|
-
+//
|
|
1160
|
+
+// 最终增量注入完成(或 reload 导致的整树卸载)后自动消失。
|
|
1052
1161
|
+//
|
|
1053
|
-
+// 状态源是 async-require/hmr 里的
|
|
1162
|
+
+// 状态源是 async-require/hmr 里的 独立展示状态广播:WebSocket 控制帧到达时
|
|
1054
1163
|
+// 同步触发,2 秒轮询兜底路径同样走该广播,因此两种通道下遮罩行为一致。
|
|
1055
1164
|
+// 纯 JS 实现,挂在 withDevTools 里,只在开发模式出现,不需要原生改动。
|
|
1056
1165
|
+export default function MiaodaHmrOverlay(): React.ReactElement | null {
|
|
1057
|
-
+ //
|
|
1058
|
-
+ const
|
|
1059
|
-
+
|
|
1060
|
-
+
|
|
1166
|
+
+ // 外部状态订阅同时校验 render 到 commit 的快照,避免这段间隙漏掉完成事件。
|
|
1167
|
+
+ const visible = React.useSyncExternalStore(
|
|
1168
|
+
+ subscribeMiaodaPresentation,
|
|
1169
|
+
+ isMiaodaPresentationVisible,
|
|
1170
|
+
+ isMiaodaPresentationVisible
|
|
1171
|
+
+ );
|
|
1061
1172
|
+
|
|
1062
|
-
+ if (!
|
|
1173
|
+
+ if (!visible) return null;
|
|
1063
1174
|
+
|
|
1064
1175
|
+ // absoluteFill + 默认的 pointerEvents="auto":作为根组件的最后一个兄弟节点
|
|
1065
|
-
+ //
|
|
1176
|
+
+ // 渲染在用户界面之上,拦截全部触摸,直到最终更新完成。
|
|
1066
1177
|
+ return (
|
|
1067
1178
|
+ <View style={styles.container}>
|
|
1068
1179
|
+ <ActivityIndicator color="#ffffff" size="large" />
|
|
@@ -1098,7 +1209,7 @@ index 0000000..8b8cef4
|
|
|
1098
1209
|
+});
|
|
1099
1210
|
diff --git a/src/launch/miaodaPromptCopy.ts b/src/launch/miaodaPromptCopy.ts
|
|
1100
1211
|
new file mode 100644
|
|
1101
|
-
index 0000000..
|
|
1212
|
+
index 0000000..3b829e4
|
|
1102
1213
|
--- /dev/null
|
|
1103
1214
|
+++ b/src/launch/miaodaPromptCopy.ts
|
|
1104
1215
|
@@ -0,0 +1,41 @@
|
|
@@ -1121,9 +1232,9 @@ index 0000000..d2556eb
|
|
|
1121
1232
|
+ disconnectedBody: '当前应用已暂停使用,恢复连接后将自动返回。也可以重新尝试,或退出开发客户端。',
|
|
1122
1233
|
+
|
|
1123
1234
|
+ // 能力问题(热更新前确认)。
|
|
1124
|
-
+ incompatibleTitle: '
|
|
1235
|
+
+ incompatibleTitle: '当前调试包已过期,需重新构建',
|
|
1125
1236
|
+ incompatibleBody:
|
|
1126
|
-
+ '
|
|
1237
|
+
+ '当前调试包不支持部分新增能力,强制加载可能导致部分功能不可用或运行异常,请前往电脑端重新构建并安装新的调试包。',
|
|
1127
1238
|
+ unknownTitle: '无法确认当前开发构建是否适用',
|
|
1128
1239
|
+ unknownBody:
|
|
1129
1240
|
+ '暂时无法完成原生能力检查,继续使用可能导致应用无法运行。建议检查网络后重新进入,或重新构建开发客户端。',
|
|
@@ -144,29 +144,55 @@ index 0000000..9b01194
|
|
|
144
144
|
+ };
|
|
145
145
|
+}
|
|
146
146
|
diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js
|
|
147
|
-
index 2ce92e0..
|
|
147
|
+
index 2ce92e0..da840bd 100644
|
|
148
148
|
--- a/Libraries/LogBox/Data/LogBoxData.js
|
|
149
149
|
+++ b/Libraries/LogBox/Data/LogBoxData.js
|
|
150
|
-
@@ -
|
|
150
|
+
@@ -139,24 +139,50 @@ function handleUpdate(): void {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
-function appendNewLog(newLog: LogBoxLog) {
|
|
155
|
+
+// Promise 拒绝仍保留 error 级别,仅改变展示策略;弱引用不延长日志生命周期。
|
|
156
|
+
+const promiseRejectionLogs: WeakSet<LogBoxLog> = new WeakSet();
|
|
157
|
+
+
|
|
158
|
+
+function appendNewLog(newLog: LogBoxLog, isPromiseRejection: boolean = false) {
|
|
159
|
+
// Don't want store these logs because they trigger a
|
|
160
|
+
// state update when we add them to the store.
|
|
161
|
+
if (isMessageIgnored(newLog.message.content)) {
|
|
151
162
|
return;
|
|
152
163
|
}
|
|
153
164
|
|
|
154
165
|
- // If the next log has the same category as the previous one
|
|
155
166
|
- // then roll it up into the last log in the list by incrementing
|
|
156
167
|
- // the count (similar to how Chrome does it).
|
|
157
|
-
+
|
|
158
|
-
+
|
|
168
|
+
+ if (isPromiseRejection) {
|
|
169
|
+
+ promiseRejectionLogs.add(newLog);
|
|
170
|
+
+ }
|
|
171
|
+
+ const shouldOpenInspector = newLog.level === 'fatal' || isPromiseRejection;
|
|
172
|
+
+ // 致命错误优先于已打开的非致命详情,但不抢占其他致命错误或语法错误。
|
|
173
|
+
+ const shouldSelectLog = () => {
|
|
174
|
+
+ const selectedLog = Array.from(logs)[_selectedIndex];
|
|
175
|
+
+ return (
|
|
176
|
+
+ _selectedIndex < 0 ||
|
|
177
|
+
+ (newLog.level === 'fatal' &&
|
|
178
|
+
+ selectedLog != null &&
|
|
179
|
+
+ selectedLog.level !== 'fatal' &&
|
|
180
|
+
+ selectedLog.level !== 'syntax')
|
|
181
|
+
+ );
|
|
182
|
+
+ };
|
|
183
|
+
+ // 相同消息还需匹配级别及来源,避免普通日志吞掉应弹出的 Promise 拒绝。
|
|
159
184
|
const lastLog = Array.from(logs).pop();
|
|
160
185
|
- if (lastLog && lastLog.category === newLog.category) {
|
|
161
186
|
+ if (
|
|
162
187
|
+ lastLog &&
|
|
163
188
|
+ lastLog.category === newLog.category &&
|
|
164
|
-
+ lastLog.level === newLog.level
|
|
189
|
+
+ lastLog.level === newLog.level &&
|
|
190
|
+
+ promiseRejectionLogs.has(lastLog) === isPromiseRejection
|
|
165
191
|
+ ) {
|
|
166
192
|
lastLog.incrementCount();
|
|
167
193
|
- handleUpdate();
|
|
168
|
-
+ //
|
|
169
|
-
+ if (
|
|
194
|
+
+ // 关闭详情后,同类未捕获异常再次发生时也应重新展示。
|
|
195
|
+
+ if (shouldOpenInspector && shouldSelectLog()) {
|
|
170
196
|
+ setSelectedLog(logs.size - 1);
|
|
171
197
|
+ } else {
|
|
172
198
|
+ handleUpdate();
|
|
@@ -174,9 +200,35 @@ index 2ce92e0..56eb4f8 100644
|
|
|
174
200
|
return;
|
|
175
201
|
}
|
|
176
202
|
|
|
203
|
+
- if (newLog.level === 'fatal') {
|
|
204
|
+
+ if (shouldOpenInspector) {
|
|
205
|
+
// If possible, to avoid jank, we don't want to open the error before
|
|
206
|
+
// it's symbolicated. To do that, we optimistically wait for
|
|
207
|
+
// symbolication for up to a second before adding the log.
|
|
208
|
+
@@ -164,7 +190,7 @@ function appendNewLog(newLog: LogBoxLog) {
|
|
209
|
+
|
|
210
|
+
let addPendingLog: ?() => void = () => {
|
|
211
|
+
logs.add(newLog);
|
|
212
|
+
- if (_selectedIndex < 0) {
|
|
213
|
+
+ if (shouldSelectLog()) {
|
|
214
|
+
setSelectedLog(logs.size - 1);
|
|
215
|
+
} else {
|
|
216
|
+
handleUpdate();
|
|
217
|
+
@@ -251,7 +277,10 @@ export function addException(error: ExtendedExceptionData): void {
|
|
218
|
+
// otherwise spammy logs would pause rendering.
|
|
219
|
+
setImmediate(() => {
|
|
220
|
+
try {
|
|
221
|
+
- appendNewLog(new LogBoxLog(parseLogBoxException(error)));
|
|
222
|
+
+ appendNewLog(
|
|
223
|
+
+ new LogBoxLog(parseLogBoxException(error)),
|
|
224
|
+
+ error.extraData?.miaodaUnhandledPromiseRejection === true,
|
|
225
|
+
+ );
|
|
226
|
+
} catch (loggingError) {
|
|
227
|
+
reportLogBoxError(loggingError);
|
|
228
|
+
}
|
|
177
229
|
diff --git a/Libraries/LogBox/Data/LogBoxPromptCopy.js b/Libraries/LogBox/Data/LogBoxPromptCopy.js
|
|
178
230
|
new file mode 100644
|
|
179
|
-
index 0000000..
|
|
231
|
+
index 0000000..19105cb
|
|
180
232
|
--- /dev/null
|
|
181
233
|
+++ b/Libraries/LogBox/Data/LogBoxPromptCopy.js
|
|
182
234
|
@@ -0,0 +1,28 @@
|
|
@@ -193,9 +245,9 @@ index 0000000..ceab0e7
|
|
|
193
245
|
+
|
|
194
246
|
+export const LOGBOX_PROMPT_COPY = {
|
|
195
247
|
+ // 能力问题(复制错误前确认弹窗)。
|
|
196
|
-
+ incompatibleTitle: '
|
|
248
|
+
+ incompatibleTitle: '当前调试包已过期,需重新构建',
|
|
197
249
|
+ incompatibleBody:
|
|
198
|
-
+ '
|
|
250
|
+
+ '当前调试包不支持部分新增能力,强制加载可能导致部分功能不可用或运行异常,请前往电脑端重新构建并安装新的调试包。',
|
|
199
251
|
+ unknownTitle: '无法确认当前开发构建是否适用',
|
|
200
252
|
+ unknownBody:
|
|
201
253
|
+ '暂时无法完成原生能力检查,继续使用可能导致应用无法运行。建议检查网络后重新进入,或重新构建开发客户端。',
|
|
@@ -681,3 +733,40 @@ index 48c1b84..41b308d 100644
|
|
|
681
733
|
</Text>
|
|
682
734
|
</View>
|
|
683
735
|
)}
|
|
736
|
+
diff --git a/Libraries/promiseRejectionTrackingOptions.js b/Libraries/promiseRejectionTrackingOptions.js
|
|
737
|
+
index c14719d..6393f11 100644
|
|
738
|
+
--- a/Libraries/promiseRejectionTrackingOptions.js
|
|
739
|
+
+++ b/Libraries/promiseRejectionTrackingOptions.js
|
|
740
|
+
@@ -36,15 +36,24 @@ let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
- ExceptionsManager.handleException(
|
|
745
|
+
- new Error(
|
|
746
|
+
- `Uncaught (in promise, id: ${id})${message ? `: "${message}"` : ''}`,
|
|
747
|
+
- {
|
|
748
|
+
- cause: rejection,
|
|
749
|
+
- },
|
|
750
|
+
- ),
|
|
751
|
+
- false /* isFatal */,
|
|
752
|
+
+ const error = new Error(
|
|
753
|
+
+ `Uncaught (in promise, id: ${id})${message ? `: "${message}"` : ''}`,
|
|
754
|
+
+ {cause: rejection},
|
|
755
|
+
);
|
|
756
|
+
+ // 优先保留拒绝发生处的调用栈,而不是跟踪器延迟回调的内部调用栈。
|
|
757
|
+
+ if (
|
|
758
|
+
+ rejection != null &&
|
|
759
|
+
+ typeof rejection === 'object' &&
|
|
760
|
+
+ typeof rejection.stack === 'string'
|
|
761
|
+
+ ) {
|
|
762
|
+
+ error.stack = `${error.message}\n${rejection.stack}`;
|
|
763
|
+
+ }
|
|
764
|
+
+ // 标记真实来源,不能根据消息前缀把普通 console.error 误判为 Promise 拒绝。
|
|
765
|
+
+ // $FlowFixMe[prop-missing] RN 通过此键将扩展元数据传递给 JS 和 C++ 异常处理链路。
|
|
766
|
+
+ error[ExceptionsManager.decoratedExtraDataKey] = {
|
|
767
|
+
+ miaodaUnhandledPromiseRejection: true,
|
|
768
|
+
+ };
|
|
769
|
+
+ ExceptionsManager.handleException(error, false /* isFatal */);
|
|
770
|
+
},
|
|
771
|
+
onHandled: id => {
|
|
772
|
+
const warning =
|
package/pnpmfile.cjs
CHANGED
|
@@ -11,6 +11,10 @@ const managedPatches = {
|
|
|
11
11
|
[REACT_NATIVE_PATCH_SELECTOR]: {
|
|
12
12
|
filename: 'react-native@0.83.2.patch',
|
|
13
13
|
legacyHashes: new Set([
|
|
14
|
+
'5506d130966fbe0539c3a7de1b4b0dac4f39fe21efde52307bb3c4b99837c01c',
|
|
15
|
+
'd7f25406e993a4d0f2a0f0ee508769ffc630e293456348492f5a1ffa000271d0',
|
|
16
|
+
'a5cb4e26aa64ec29e7a81bbec0f9ea36bcac15e2eea53b15491cd01095885296',
|
|
17
|
+
'4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
|
|
14
18
|
'12e2defd1f201b8fd05b318f4f157323f15d25e94358de24e4f03ddad2157023',
|
|
15
19
|
'bc87e66a7a5c2e0fbe5d1be5c20d1c6b8456e84ea287a1acb15202264b4f2c37',
|
|
16
20
|
'c03c7638b6393e9876df08f7e9160a9122f00d6e1f1e76e8f4adb4cba3c3b539',
|
|
@@ -25,6 +29,11 @@ const managedPatches = {
|
|
|
25
29
|
'9a0d662675fba8088396c6cdbab7d36d81fbe9acb3727144a50826ff3500b093',
|
|
26
30
|
]),
|
|
27
31
|
},
|
|
32
|
+
'@expo/metro-runtime@>=55.0.11 <55.0.13': {
|
|
33
|
+
filename: '@expo__metro-runtime@55.0.11-55.0.12.patch',
|
|
34
|
+
legacyHashes: new Set([
|
|
35
|
+
]),
|
|
36
|
+
},
|
|
28
37
|
'metro-runtime@0.83.3': {
|
|
29
38
|
filename: 'metro-runtime@0.83.3.patch',
|
|
30
39
|
legacyHashes: new Set([
|
|
@@ -53,6 +62,15 @@ const managedPatches = {
|
|
|
53
62
|
'expo@55.0.6': {
|
|
54
63
|
filename: 'expo@55.0.6.patch',
|
|
55
64
|
legacyHashes: new Set([
|
|
65
|
+
'573ac35a3a68be0d5eefd1e958929082bcfcf3efc233b6e18e7466b4f33fadbb',
|
|
66
|
+
'4f93951e5181dd109fb84a1a0549cf26aee37e0a8077e77bb4df82f674ff6da9',
|
|
67
|
+
'53974f8fd1e682b4da10cbcf0f395996c3734eae2372a9516dee067a3c5ade48',
|
|
68
|
+
'87d5b36485c1e64c4843444aaaf81a37c63eeceb5e3fd49ebf9464f709836da9',
|
|
69
|
+
'9c01c660c3bf23a1d00fd9d3ceb902e256d9241224227acf3ae4c13b6ff499f4',
|
|
70
|
+
'be8acb91becb6d4a3c9a898d75aef71d06d208bc370bf576aa786286a00ccda7',
|
|
71
|
+
'83ae82f4dbe0ead362f24d891310a129a72df6fc3d1450aa0697c5f3151e4e9a',
|
|
72
|
+
'fd9ffc51138fad126266f1f786671201cdd793a7e2386c0dc311e097dcdfdf62',
|
|
73
|
+
'8e63bb43a9edc12a4b0839346a1fa211fee64933aa8d4a8711e0ced434516fb5',
|
|
56
74
|
'8918e9d5c443bf0d5149e5fff2714bf241447d3448e5f568a6669a3cdbf220ac',
|
|
57
75
|
'612203c64a1fa24a2dd6a402bc3dad8cccdcbfa1185c4535abed741a31e18d12',
|
|
58
76
|
// 0.1.1-dev.development-build.8 发布时的哈希;合并远端遮罩文案修正后迁移。
|
|
@@ -81,12 +99,6 @@ const managedPatches = {
|
|
|
81
99
|
'b2c55038b2fa525ad5e84bd4940ddd2b7298b559de2d0d1709f32ced57e929e9',
|
|
82
100
|
]),
|
|
83
101
|
},
|
|
84
|
-
'react-native@0.83.2': {
|
|
85
|
-
filename: 'react-native@0.83.2.patch',
|
|
86
|
-
legacyHashes: new Set([
|
|
87
|
-
'4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
|
|
88
|
-
]),
|
|
89
|
-
},
|
|
90
102
|
'react-native-worklets@0.7.4': {
|
|
91
103
|
filename: 'react-native-worklets@0.7.4.patch',
|
|
92
104
|
legacyHashes: new Set([
|