@lark-apaas/fullstack-presets 1.1.5-alpha.1 → 1.1.5-alpha.3
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ESLint
|
|
2
|
+
* ESLint 规则:要求入口文件中必须包含 AppContainer 组件
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 此规则确保 client/src/index.tsx 和 client/src/app.tsx 文件中
|
|
5
|
+
* 包含 AppContainer 组件,以保证平台功能正常运行。
|
|
6
6
|
*/
|
|
7
7
|
import type { Rule } from 'eslint';
|
|
8
8
|
declare const rule: Rule.RuleModule;
|
|
@@ -34,16 +34,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
const path = __importStar(require("path"));
|
|
37
|
-
const DEFAULT_MESSAGE = '
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const DEFAULT_MESSAGE = 'Missing platform component AppContainer. Please ensure that App is wrapped with AppContainer to enable platform features.';
|
|
38
|
+
// 必须包含 AppContainer 的文件列表
|
|
39
|
+
// TODO: 后续放开 index.tsx 的校验
|
|
40
|
+
const REQUIRED_FILES = ['app.tsx'];
|
|
41
|
+
// 匹配 client/src/ 目录的正则表达式
|
|
41
42
|
const CLIENT_SRC_PATTERN = /[/\\]client[/\\]src[/\\]$/;
|
|
42
43
|
const rule = {
|
|
43
44
|
meta: {
|
|
44
45
|
type: 'problem',
|
|
45
46
|
docs: {
|
|
46
|
-
description: '
|
|
47
|
+
description: '要求入口文件中必须包含 AppContainer 组件',
|
|
47
48
|
category: 'Possible Errors',
|
|
48
49
|
recommended: true,
|
|
49
50
|
},
|
|
@@ -53,7 +54,7 @@ const rule = {
|
|
|
53
54
|
properties: {
|
|
54
55
|
message: {
|
|
55
56
|
type: 'string',
|
|
56
|
-
description: '
|
|
57
|
+
description: '自定义错误信息',
|
|
57
58
|
},
|
|
58
59
|
},
|
|
59
60
|
additionalProperties: false,
|
|
@@ -67,48 +68,38 @@ const rule = {
|
|
|
67
68
|
const options = context.options[0];
|
|
68
69
|
const customMessage = options?.message;
|
|
69
70
|
const filename = context.filename || context.getFilename();
|
|
70
|
-
//
|
|
71
|
+
// 获取文件名和目录名
|
|
71
72
|
const basename = path.basename(filename);
|
|
72
73
|
const dirname = path.dirname(filename);
|
|
73
|
-
//
|
|
74
|
+
// 判断是否为需要检查的文件:必须在 client/src/ 目录下且文件名匹配
|
|
74
75
|
const isRequiredFile = REQUIRED_FILES.includes(basename.toLowerCase()) &&
|
|
75
76
|
CLIENT_SRC_PATTERN.test(dirname + path.sep);
|
|
77
|
+
// 如果不是需要检查的文件,直接跳过
|
|
76
78
|
if (!isRequiredFile) {
|
|
77
79
|
return {};
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
// 标记是否在 JSX 中实际使用了 AppContainer
|
|
82
|
+
let hasAppContainerUsage = false;
|
|
80
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
84
|
let programNode = null;
|
|
82
85
|
return {
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
// Check for default or named import of AppContainer
|
|
86
|
-
for (const specifier of node.specifiers) {
|
|
87
|
-
if (specifier.type === 'ImportSpecifier' ||
|
|
88
|
-
specifier.type === 'ImportDefaultSpecifier') {
|
|
89
|
-
if (specifier.local.name === 'AppContainer') {
|
|
90
|
-
hasAppContainer = true;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
// Check for JSX usage of <AppContainer>
|
|
86
|
+
// 检查 JSX 中是否使用了 <AppContainer> 组件
|
|
87
|
+
// 注意:仅导入不使用不算通过,必须在 JSX 中实际使用
|
|
97
88
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
89
|
JSXOpeningElement(node) {
|
|
99
90
|
const elementName = node.name;
|
|
100
91
|
if (elementName?.type === 'JSXIdentifier' &&
|
|
101
92
|
elementName?.name === 'AppContainer') {
|
|
102
|
-
|
|
93
|
+
hasAppContainerUsage = true;
|
|
103
94
|
}
|
|
104
95
|
},
|
|
105
|
-
//
|
|
96
|
+
// 保存 Program 节点,用于在文件末尾报错时定位
|
|
106
97
|
Program(node) {
|
|
107
98
|
programNode = node;
|
|
108
99
|
},
|
|
109
|
-
//
|
|
100
|
+
// 文件解析完成后,检查是否在 JSX 中使用了 AppContainer
|
|
110
101
|
'Program:exit'() {
|
|
111
|
-
if (!
|
|
102
|
+
if (!hasAppContainerUsage && programNode) {
|
|
112
103
|
context.report({
|
|
113
104
|
node: programNode,
|
|
114
105
|
...(customMessage
|