miaoda-expo-devkit 0.1.1-beta.123 → 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/dist/cli/lint.js +100 -44
- package/dist/rules/no-typeof-window-check.js +85 -3
- package/docs/devkit-lint.md +62 -2
- package/package.json +1 -1
- package/pnpm-patches/expo@55.0.6.patch +18 -14
- package/pnpm-patches/react-native@0.83.2.patch +3 -3
- package/pnpmfile.cjs +3 -0
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/package.json
CHANGED
|
@@ -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 @@
|
|
@@ -297,7 +297,7 @@ index c0ea71e..d696ac1 100644
|
|
|
297
297
|
type LogLevel =
|
|
298
298
|
| 'trace'
|
|
299
299
|
| 'info'
|
|
300
|
-
@@ -42,6 +293,
|
|
300
|
+
@@ -42,6 +293,148 @@ type LogLevel =
|
|
301
301
|
| 'groupEnd'
|
|
302
302
|
| 'debug';
|
|
303
303
|
|
|
@@ -339,6 +339,8 @@ index c0ea71e..d696ac1 100644
|
|
|
339
339
|
+ response = await fetch(miaodaStatusUrl(protocol), {headers: {'Cache-Control': 'no-cache'}});
|
|
340
340
|
+ }
|
|
341
341
|
+
|
|
342
|
+
+ // 已有更新一轮轮询发出:本轮的 404/5xx 也是过期结论,不能停止轮询或计入断线。
|
|
343
|
+
+ if (sequence !== miaodaPollSequence) return;
|
|
342
344
|
+ if (response.status === 404) {
|
|
343
345
|
+ // 404 是确定性信号:这个 Metro 实例没有挂载控制路由(未开启
|
|
344
346
|
+ // EXPO_MIAODA_HMR_CONTROL)。停止探测直到 WebSocket 重连,
|
|
@@ -430,6 +432,8 @@ index c0ea71e..d696ac1 100644
|
|
|
430
432
|
+ // 网络错误、超时、响应解析失败都属于暂时故障:不解除编辑闸门,
|
|
431
433
|
+ // 也不停止轮询,下一轮继续。同时计入断线判定:连续多个周期都
|
|
432
434
|
+ // 无法获得可用响应,就广播给顶部横幅提示用户开发服务器不可达。
|
|
435
|
+
+ // 被更新一轮轮询取代的失败同样不计数。
|
|
436
|
+
+ if (sequence !== miaodaPollSequence) return;
|
|
433
437
|
+ miaodaPollFailureCount += 1;
|
|
434
438
|
+ if (miaodaPollFailureCount >= MIAODA_POLL_FAILURE_THRESHOLD) {
|
|
435
439
|
+ setMiaodaServerDisconnected(true);
|
|
@@ -442,7 +446,7 @@ index c0ea71e..d696ac1 100644
|
|
|
442
446
|
function assert(foo: any, msg: string): asserts foo {
|
|
443
447
|
if (!foo) throw new Error(msg);
|
|
444
448
|
}
|
|
445
|
-
@@ -52,6 +
|
|
449
|
+
@@ -52,6 +445,9 @@ function assert(foo: any, msg: string): asserts foo {
|
|
446
450
|
*/
|
|
447
451
|
const HMRClient = {
|
|
448
452
|
enable() {
|
|
@@ -452,7 +456,7 @@ index c0ea71e..d696ac1 100644
|
|
|
452
456
|
if (hmrUnavailableReason !== null) {
|
|
453
457
|
// If HMR became unavailable while you weren't using it,
|
|
454
458
|
// explain why when you try to turn it on.
|
|
455
|
-
@@ -75,6 +
|
|
459
|
+
@@ -75,6 +471,10 @@ const HMRClient = {
|
|
456
460
|
}
|
|
457
461
|
try {
|
|
458
462
|
hmrClient.enable();
|
|
@@ -463,7 +467,7 @@ index c0ea71e..d696ac1 100644
|
|
|
463
467
|
} finally {
|
|
464
468
|
if (hasUpdates) {
|
|
465
469
|
hideLoading();
|
|
466
|
-
@@ -87,8 +
|
|
470
|
+
@@ -87,8 +487,10 @@ const HMRClient = {
|
|
467
471
|
},
|
|
468
472
|
|
|
469
473
|
disable() {
|
|
@@ -474,7 +478,7 @@ index c0ea71e..d696ac1 100644
|
|
|
474
478
|
},
|
|
475
479
|
|
|
476
480
|
registerBundle(requestUrl: string) {
|
|
477
|
-
@@ -180,6 +
|
|
481
|
+
@@ -180,6 +582,55 @@ const HMRClient = {
|
|
478
482
|
const origin = `${serverScheme}://${serverHost}`;
|
|
479
483
|
const client = new MetroHMRClient(`${origin}/hot`);
|
|
480
484
|
hmrClient = client;
|
|
@@ -530,7 +534,7 @@ index c0ea71e..d696ac1 100644
|
|
|
530
534
|
|
|
531
535
|
pendingEntryPoints.push(
|
|
532
536
|
// HMRServer understands regular bundle URLs, so prefer that in case
|
|
533
|
-
@@ -193,6 +
|
|
537
|
+
@@ -193,6 +644,72 @@ const HMRClient = {
|
|
534
538
|
})
|
|
535
539
|
);
|
|
536
540
|
|
|
@@ -603,7 +607,7 @@ index c0ea71e..d696ac1 100644
|
|
|
603
607
|
client.on('connection-error', (e: Error) => {
|
|
604
608
|
setHMRUnavailableReason(getConnectionError(serverHost, e));
|
|
605
609
|
});
|
|
606
|
-
@@ -221,7 +
|
|
610
|
+
@@ -221,7 +738,13 @@ const HMRClient = {
|
|
607
611
|
}) => {
|
|
608
612
|
// NOTE(@krystofwoldrich): I don't know why sometimes empty updates are sent. But they should not reset the overlay.
|
|
609
613
|
const isEmpty = added.length === 0 && modified.length === 0 && deleted.length === 0;
|
|
@@ -618,7 +622,7 @@ index c0ea71e..d696ac1 100644
|
|
|
618
622
|
resetErrorOverlay();
|
|
619
623
|
}
|
|
620
624
|
}
|
|
621
|
-
@@ -234,6 +
|
|
625
|
+
@@ -234,6 +757,11 @@ const HMRClient = {
|
|
622
626
|
client.on('error', (data) => this._onMetroError(data));
|
|
623
627
|
|
|
624
628
|
client.on('close', (closeEvent?: { code: number; reason: string }) => {
|
|
@@ -630,7 +634,7 @@ index c0ea71e..d696ac1 100644
|
|
|
630
634
|
hideLoading();
|
|
631
635
|
const reason = closeEvent?.reason;
|
|
632
636
|
const code = closeEvent?.code || 1000;
|
|
633
|
-
@@ -318,7 +
|
|
637
|
+
@@ -318,7 +846,8 @@ function setHMRUnavailableReason(reason: string) {
|
|
634
638
|
function registerBundleEntryPoints(client: MetroHMRClient | null) {
|
|
635
639
|
if (hmrUnavailableReason != null) {
|
|
636
640
|
// "Bundle Splitting – Metro disconnected"
|
|
@@ -640,7 +644,7 @@ index c0ea71e..d696ac1 100644
|
|
|
640
644
|
return;
|
|
641
645
|
}
|
|
642
646
|
|
|
643
|
-
@@ -326,6 +
|
|
647
|
+
@@ -326,6 +855,9 @@ function registerBundleEntryPoints(client: MetroHMRClient | null) {
|
|
644
648
|
client?.send(
|
|
645
649
|
JSON.stringify({
|
|
646
650
|
type: 'register-entrypoints',
|
|
@@ -1205,7 +1209,7 @@ index 0000000..6d47443
|
|
|
1205
1209
|
+});
|
|
1206
1210
|
diff --git a/src/launch/miaodaPromptCopy.ts b/src/launch/miaodaPromptCopy.ts
|
|
1207
1211
|
new file mode 100644
|
|
1208
|
-
index 0000000..
|
|
1212
|
+
index 0000000..3b829e4
|
|
1209
1213
|
--- /dev/null
|
|
1210
1214
|
+++ b/src/launch/miaodaPromptCopy.ts
|
|
1211
1215
|
@@ -0,0 +1,41 @@
|
|
@@ -1228,9 +1232,9 @@ index 0000000..d2556eb
|
|
|
1228
1232
|
+ disconnectedBody: '当前应用已暂停使用,恢复连接后将自动返回。也可以重新尝试,或退出开发客户端。',
|
|
1229
1233
|
+
|
|
1230
1234
|
+ // 能力问题(热更新前确认)。
|
|
1231
|
-
+ incompatibleTitle: '
|
|
1235
|
+
+ incompatibleTitle: '当前调试包已过期,需重新构建',
|
|
1232
1236
|
+ incompatibleBody:
|
|
1233
|
-
+ '
|
|
1237
|
+
+ '当前调试包不支持部分新增能力,强制加载可能导致部分功能不可用或运行异常,请前往电脑端重新构建并安装新的调试包。',
|
|
1234
1238
|
+ unknownTitle: '无法确认当前开发构建是否适用',
|
|
1235
1239
|
+ unknownBody:
|
|
1236
1240
|
+ '暂时无法完成原生能力检查,继续使用可能导致应用无法运行。建议检查网络后重新进入,或重新构建开发客户端。',
|
|
@@ -228,7 +228,7 @@ index 2ce92e0..da840bd 100644
|
|
|
228
228
|
}
|
|
229
229
|
diff --git a/Libraries/LogBox/Data/LogBoxPromptCopy.js b/Libraries/LogBox/Data/LogBoxPromptCopy.js
|
|
230
230
|
new file mode 100644
|
|
231
|
-
index 0000000..
|
|
231
|
+
index 0000000..19105cb
|
|
232
232
|
--- /dev/null
|
|
233
233
|
+++ b/Libraries/LogBox/Data/LogBoxPromptCopy.js
|
|
234
234
|
@@ -0,0 +1,28 @@
|
|
@@ -245,9 +245,9 @@ index 0000000..ceab0e7
|
|
|
245
245
|
+
|
|
246
246
|
+export const LOGBOX_PROMPT_COPY = {
|
|
247
247
|
+ // 能力问题(复制错误前确认弹窗)。
|
|
248
|
-
+ incompatibleTitle: '
|
|
248
|
+
+ incompatibleTitle: '当前调试包已过期,需重新构建',
|
|
249
249
|
+ incompatibleBody:
|
|
250
|
-
+ '
|
|
250
|
+
+ '当前调试包不支持部分新增能力,强制加载可能导致部分功能不可用或运行异常,请前往电脑端重新构建并安装新的调试包。',
|
|
251
251
|
+ unknownTitle: '无法确认当前开发构建是否适用',
|
|
252
252
|
+ unknownBody:
|
|
253
253
|
+ '暂时无法完成原生能力检查,继续使用可能导致应用无法运行。建议检查网络后重新进入,或重新构建开发客户端。',
|
package/pnpmfile.cjs
CHANGED
|
@@ -11,6 +11,7 @@ const managedPatches = {
|
|
|
11
11
|
[REACT_NATIVE_PATCH_SELECTOR]: {
|
|
12
12
|
filename: 'react-native@0.83.2.patch',
|
|
13
13
|
legacyHashes: new Set([
|
|
14
|
+
'5506d130966fbe0539c3a7de1b4b0dac4f39fe21efde52307bb3c4b99837c01c',
|
|
14
15
|
'd7f25406e993a4d0f2a0f0ee508769ffc630e293456348492f5a1ffa000271d0',
|
|
15
16
|
'a5cb4e26aa64ec29e7a81bbec0f9ea36bcac15e2eea53b15491cd01095885296',
|
|
16
17
|
'4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
|
|
@@ -61,6 +62,8 @@ const managedPatches = {
|
|
|
61
62
|
'expo@55.0.6': {
|
|
62
63
|
filename: 'expo@55.0.6.patch',
|
|
63
64
|
legacyHashes: new Set([
|
|
65
|
+
'573ac35a3a68be0d5eefd1e958929082bcfcf3efc233b6e18e7466b4f33fadbb',
|
|
66
|
+
'4f93951e5181dd109fb84a1a0549cf26aee37e0a8077e77bb4df82f674ff6da9',
|
|
64
67
|
'53974f8fd1e682b4da10cbcf0f395996c3734eae2372a9516dee067a3c5ade48',
|
|
65
68
|
'87d5b36485c1e64c4843444aaaf81a37c63eeceb5e3fd49ebf9464f709836da9',
|
|
66
69
|
'9c01c660c3bf23a1d00fd9d3ceb902e256d9241224227acf3ae4c13b6ff499f4',
|