miaoda-expo-devkit 0.1.1-beta.29 → 0.1.1-beta.30

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.
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/rules/no-invalid-tabs-screen.ts
31
+ var no_invalid_tabs_screen_exports = {};
32
+ __export(no_invalid_tabs_screen_exports, {
33
+ default: () => no_invalid_tabs_screen_default
34
+ });
35
+ module.exports = __toCommonJS(no_invalid_tabs_screen_exports);
36
+ var import_node_fs = __toESM(require("fs"));
37
+ var import_node_path = __toESM(require("path"));
38
+ function findProjectRoot(startPath) {
39
+ let dir = import_node_path.default.dirname(startPath);
40
+ while (dir !== import_node_path.default.dirname(dir)) {
41
+ if (import_node_fs.default.existsSync(import_node_path.default.join(dir, "package.json"))) return dir;
42
+ dir = import_node_path.default.dirname(dir);
43
+ }
44
+ return null;
45
+ }
46
+ function getRouterRoot(projectRoot) {
47
+ try {
48
+ const raw = JSON.parse(import_node_fs.default.readFileSync(import_node_path.default.join(projectRoot, "app.json"), "utf-8"));
49
+ return raw?.expo?.router?.root ?? ".";
50
+ } catch {
51
+ return ".";
52
+ }
53
+ }
54
+ var ROUTE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
55
+ function resolveScreenName(name, appDir) {
56
+ for (const ext of ROUTE_EXTS) {
57
+ if (import_node_fs.default.existsSync(import_node_path.default.join(appDir, name + ext))) {
58
+ return { exists: true, suggestion: null };
59
+ }
60
+ }
61
+ for (const ext of ROUTE_EXTS) {
62
+ if (import_node_fs.default.existsSync(import_node_path.default.join(appDir, name, "index" + ext))) {
63
+ return { exists: false, suggestion: `${name}/index` };
64
+ }
65
+ }
66
+ return { exists: false, suggestion: null };
67
+ }
68
+ function getStringAttr(attrs, attrName) {
69
+ for (const attr of attrs) {
70
+ if (attr.type !== "JSXAttribute") continue;
71
+ const n = attr.name;
72
+ if (n.type !== "JSXIdentifier" || n.name !== attrName) continue;
73
+ const v = attr.value;
74
+ if (!v) continue;
75
+ if (v.type === "Literal") {
76
+ return String(v.value);
77
+ }
78
+ if (v.type === "JSXExpressionContainer") {
79
+ const expr = v.expression;
80
+ if (expr.type === "Literal") return String(expr.value);
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+ function isHiddenTab(attrs) {
86
+ for (const attr of attrs) {
87
+ if (attr.type !== "JSXAttribute") continue;
88
+ const n = attr.name;
89
+ if (n.type !== "JSXIdentifier" || n.name !== "options") continue;
90
+ const v = attr.value;
91
+ if (!v) continue;
92
+ if (v.type !== "JSXExpressionContainer") continue;
93
+ const expr = v.expression;
94
+ if (!expr || expr.type !== "ObjectExpression") continue;
95
+ for (const prop of expr.properties ?? []) {
96
+ const p = prop;
97
+ if (p.type !== "Property") continue;
98
+ const key = p.key;
99
+ const keyName = key.type === "Identifier" ? key.name : String(key.value);
100
+ if (keyName !== "href") continue;
101
+ if (p.value.type === "Literal" && p.value.value === null) return true;
102
+ }
103
+ }
104
+ return false;
105
+ }
106
+ function hasTitle(attrs) {
107
+ for (const attr of attrs) {
108
+ if (attr.type !== "JSXAttribute") continue;
109
+ const n = attr.name;
110
+ if (n.type !== "JSXIdentifier" || n.name !== "options") continue;
111
+ const v = attr.value;
112
+ if (!v) continue;
113
+ if (v.type !== "JSXExpressionContainer") continue;
114
+ const expr = v.expression;
115
+ if (!expr || expr.type !== "ObjectExpression") continue;
116
+ for (const prop of expr.properties ?? []) {
117
+ const p = prop;
118
+ if (p.type !== "Property") continue;
119
+ const key = p.key;
120
+ const keyName = key.type === "Identifier" ? key.name : String(key.value);
121
+ if (keyName === "title") return true;
122
+ }
123
+ }
124
+ return false;
125
+ }
126
+ var noInvalidTabsScreenRule = {
127
+ meta: {
128
+ type: "problem",
129
+ docs: {
130
+ description: "Validate Tabs.Screen name (must match an existing route file) and options (visible tabs must have a title)."
131
+ },
132
+ schema: [],
133
+ messages: {
134
+ nameNotFound: 'Tabs.Screen name="{{name}}" does not match any route file in the app directory.',
135
+ nameShouldBeIndex: 'Tabs.Screen name="{{name}}" should be "{{suggestion}}" (add /index suffix).',
136
+ missingTitle: 'Visible Tabs.Screen name="{{name}}" is missing options.title.'
137
+ }
138
+ },
139
+ create(context) {
140
+ const base = import_node_path.default.basename(context.filename);
141
+ if (!base.startsWith("_layout.")) return {};
142
+ const projectRoot = findProjectRoot(context.filename);
143
+ if (!projectRoot) return {};
144
+ const routerRoot = getRouterRoot(projectRoot);
145
+ const appDir = import_node_path.default.join(projectRoot, routerRoot, "app");
146
+ const layoutDir = import_node_path.default.dirname(context.filename);
147
+ return {
148
+ JSXOpeningElement(node) {
149
+ const nameNode = node.name;
150
+ if (nameNode.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.object?.name !== "Tabs" || nameNode.property?.type !== "JSXIdentifier" || nameNode.property?.name !== "Screen") {
151
+ return;
152
+ }
153
+ const attrs = node.attributes;
154
+ const name = getStringAttr(attrs, "name");
155
+ if (!name) return;
156
+ const nameRelToApp = import_node_path.default.relative(appDir, import_node_path.default.join(layoutDir, name));
157
+ const result = resolveScreenName(nameRelToApp, appDir);
158
+ if (!result.exists) {
159
+ if (result.suggestion) {
160
+ const suggestedNameRelToLayout = import_node_path.default.relative(layoutDir, import_node_path.default.join(appDir, result.suggestion));
161
+ const suggestion = suggestedNameRelToLayout.replace(/\\/g, "/");
162
+ context.report({
163
+ node,
164
+ messageId: "nameShouldBeIndex",
165
+ data: { name, suggestion }
166
+ });
167
+ } else {
168
+ context.report({
169
+ node,
170
+ messageId: "nameNotFound",
171
+ data: { name }
172
+ });
173
+ }
174
+ }
175
+ if (!isHiddenTab(attrs) && !hasTitle(attrs)) {
176
+ context.report({
177
+ node,
178
+ messageId: "missingTitle",
179
+ data: { name }
180
+ });
181
+ }
182
+ }
183
+ };
184
+ }
185
+ };
186
+ var plugin = {
187
+ meta: { name: "expo-router-layout" },
188
+ rules: { "no-invalid-tabs-screen": noInvalidTabsScreenRule }
189
+ };
190
+ var no_invalid_tabs_screen_default = plugin;
191
+ module.exports = module.exports.default;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/rules/no-unregistered-dynamic-tab-route.ts
31
+ var no_unregistered_dynamic_tab_route_exports = {};
32
+ __export(no_unregistered_dynamic_tab_route_exports, {
33
+ default: () => no_unregistered_dynamic_tab_route_default
34
+ });
35
+ module.exports = __toCommonJS(no_unregistered_dynamic_tab_route_exports);
36
+ var import_node_fs = __toESM(require("fs"));
37
+ var import_node_path = __toESM(require("path"));
38
+ var ROUTE_EXTS = /* @__PURE__ */ new Set([".tsx", ".ts", ".jsx", ".js"]);
39
+ function findProjectRoot(startPath) {
40
+ let dir = import_node_path.default.dirname(startPath);
41
+ while (dir !== import_node_path.default.dirname(dir)) {
42
+ if (import_node_fs.default.existsSync(import_node_path.default.join(dir, "package.json"))) return dir;
43
+ dir = import_node_path.default.dirname(dir);
44
+ }
45
+ return null;
46
+ }
47
+ function getRouterRoot(projectRoot) {
48
+ try {
49
+ const raw = JSON.parse(
50
+ import_node_fs.default.readFileSync(import_node_path.default.join(projectRoot, "app.json"), "utf-8")
51
+ );
52
+ return raw?.expo?.router?.root ?? ".";
53
+ } catch {
54
+ return ".";
55
+ }
56
+ }
57
+ function collectRoutesNeedingHide(layoutDir) {
58
+ const results = [];
59
+ function scan(dir) {
60
+ for (const entry of import_node_fs.default.readdirSync(dir, { withFileTypes: true })) {
61
+ const fullPath = import_node_path.default.join(dir, entry.name);
62
+ if (entry.isDirectory()) {
63
+ scan(fullPath);
64
+ continue;
65
+ }
66
+ if (!entry.isFile()) continue;
67
+ const ext = import_node_path.default.extname(entry.name);
68
+ if (!ROUTE_EXTS.has(ext)) continue;
69
+ const basename = import_node_path.default.basename(entry.name, ext);
70
+ if (basename.startsWith("_") || basename.startsWith("+")) continue;
71
+ const rel = import_node_path.default.relative(layoutDir, fullPath).replace(/\\/g, "/").slice(0, -ext.length);
72
+ const segments = rel.split("/");
73
+ const lastSeg = segments[segments.length - 1];
74
+ const isDynamic = rel.includes("[");
75
+ const isNonIndexSubRoute = segments.length >= 2 && lastSeg !== "index";
76
+ if (isDynamic || isNonIndexSubRoute) {
77
+ results.push(rel);
78
+ }
79
+ }
80
+ }
81
+ if (import_node_fs.default.existsSync(layoutDir)) scan(layoutDir);
82
+ return results;
83
+ }
84
+ function getStringAttr(attrs, attrName) {
85
+ for (const attr of attrs) {
86
+ if (attr.type !== "JSXAttribute") continue;
87
+ const n = attr.name;
88
+ if (n.type !== "JSXIdentifier" || n.name !== attrName) continue;
89
+ const v = attr.value;
90
+ if (!v) continue;
91
+ if (v.type === "Literal") {
92
+ return String(v.value);
93
+ }
94
+ if (v.type === "JSXExpressionContainer") {
95
+ const expr = v.expression;
96
+ if (expr.type === "Literal") return String(expr.value);
97
+ }
98
+ }
99
+ return null;
100
+ }
101
+ function isHiddenTab(attrs) {
102
+ for (const attr of attrs) {
103
+ if (attr.type !== "JSXAttribute") continue;
104
+ const n = attr.name;
105
+ if (n.type !== "JSXIdentifier" || n.name !== "options") continue;
106
+ const v = attr.value;
107
+ if (!v || v.type !== "JSXExpressionContainer") continue;
108
+ const expr = v.expression;
109
+ if (!expr || expr.type !== "ObjectExpression") continue;
110
+ for (const prop of expr.properties ?? []) {
111
+ const p = prop;
112
+ if (p.type !== "Property") continue;
113
+ const keyName = p.key.type === "Identifier" ? p.key.name : String(p.key.value);
114
+ if (keyName !== "href") continue;
115
+ if (p.value.type === "Literal" && p.value.value === null) return true;
116
+ }
117
+ }
118
+ return false;
119
+ }
120
+ var noUnregisteredDynamicTabRouteRule = {
121
+ meta: {
122
+ type: "problem",
123
+ docs: {
124
+ description: 'Dynamic routes and non-index sub-routes inside a Tabs layout must be hidden with <Tabs.Screen name="..." options={{ href: null }} />.'
125
+ },
126
+ schema: [],
127
+ messages: {
128
+ missingHiddenScreen: 'Route "{{name}}" must be hidden \u2014 add <Tabs.Screen name="{{name}}" options={href_null} /> where href_null is { href: null }.'
129
+ }
130
+ },
131
+ create(context) {
132
+ const base = import_node_path.default.basename(context.filename);
133
+ if (!base.startsWith("_layout.")) return {};
134
+ const projectRoot = findProjectRoot(context.filename);
135
+ if (!projectRoot) return {};
136
+ const routerRoot = getRouterRoot(projectRoot);
137
+ const appDir = import_node_path.default.join(projectRoot, routerRoot, "app");
138
+ const layoutDir = import_node_path.default.dirname(context.filename);
139
+ if (import_node_path.default.relative(appDir, layoutDir).startsWith("..")) return {};
140
+ const hiddenNames = /* @__PURE__ */ new Set();
141
+ return {
142
+ JSXOpeningElement(node) {
143
+ const nameNode = node.name;
144
+ if (nameNode.type !== "JSXMemberExpression" || nameNode.object?.type !== "JSXIdentifier" || nameNode.object?.name !== "Tabs" || nameNode.property?.type !== "JSXIdentifier" || nameNode.property?.name !== "Screen") {
145
+ return;
146
+ }
147
+ const attrs = node.attributes;
148
+ const screenName = getStringAttr(attrs, "name");
149
+ if (screenName && isHiddenTab(attrs)) {
150
+ hiddenNames.add(screenName);
151
+ }
152
+ },
153
+ "Program:exit"() {
154
+ const routes = collectRoutesNeedingHide(layoutDir);
155
+ for (const name of routes) {
156
+ if (!hiddenNames.has(name)) {
157
+ context.report({
158
+ loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
159
+ messageId: "missingHiddenScreen",
160
+ data: { name }
161
+ });
162
+ }
163
+ }
164
+ }
165
+ };
166
+ }
167
+ };
168
+ var plugin = {
169
+ meta: { name: "expo-router-layout" },
170
+ rules: { "no-unregistered-dynamic-tab-route": noUnregisteredDynamicTabRouteRule }
171
+ };
172
+ var no_unregistered_dynamic_tab_route_default = plugin;
173
+ module.exports = module.exports.default;
@@ -6,7 +6,9 @@
6
6
  { "name": "expo-router", "specifier": "miaoda-expo-devkit/rules/no-unstable-expo-router" },
7
7
  { "name": "rn-web", "specifier": "miaoda-expo-devkit/rules/no-rn-alert" },
8
8
  { "name": "expo-router-url", "specifier": "miaoda-expo-devkit/rules/no-duplicate-expo-router-url" },
9
- { "name": "css-import", "specifier": "miaoda-expo-devkit/rules/no-missing-css-import" }
9
+ { "name": "css-import", "specifier": "miaoda-expo-devkit/rules/no-missing-css-import" },
10
+ { "name": "expo-router-layout", "specifier": "miaoda-expo-devkit/rules/no-invalid-tabs-screen" },
11
+ { "name": "expo-router-dynamic-tab", "specifier": "miaoda-expo-devkit/rules/no-unregistered-dynamic-tab-route" }
10
12
  ],
11
13
 
12
14
  "categories": {
@@ -19,6 +21,8 @@
19
21
  "rn-web/no-rn-alert": "error",
20
22
  "expo-router-url/no-duplicate-expo-router-url": "error",
21
23
  "css-import/no-missing-css-import": "error",
24
+ "expo-router-layout/no-invalid-tabs-screen": "error",
25
+ "expo-router-dynamic-tab/no-unregistered-dynamic-tab-route": "error",
22
26
 
23
27
  "expo/no-dynamic-env-var": "error",
24
28
  "expo/no-env-var-destructuring": "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-expo-devkit",
3
- "version": "0.1.1-beta.29",
3
+ "version": "0.1.1-beta.30",
4
4
  "description": "Expo 应用开发工具集:Sentry DSN 替换 stub、错误/网络捕获、Metro 符号化",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -51,6 +51,8 @@
51
51
  "./rules/no-rn-alert": "./dist/rules/no-rn-alert.js",
52
52
  "./rules/no-duplicate-expo-router-url": "./dist/rules/no-duplicate-expo-router-url.js",
53
53
  "./rules/no-missing-css-import": "./dist/rules/no-missing-css-import.js",
54
+ "./rules/no-invalid-tabs-screen": "./dist/rules/no-invalid-tabs-screen.js",
55
+ "./rules/no-unregistered-dynamic-tab-route": "./dist/rules/no-unregistered-dynamic-tab-route.js",
54
56
  "./biome": "./biome-config.json",
55
57
  "./oxlint": "./oxlint-config.json",
56
58
  "./tsconfig-base": "./tsconfig-base.json"