阶段四:完成 React Feature 化和异步状态修复
This commit is contained in:
1 parent
4227e3dd56
commit
e92549da48
176 files changed
+849
-650
No files matched your search
@@ -285,6 +285,9 @@ func checkReactArchitecture(root string) []violation {
|
||||
if strings.HasSuffix(specifier, "shared/api-contract") {
|
||||
violations = append(violations, violation{file: "frontend/" + relativePath, line: sourceLineAt(source, strings.Index(sourceText, match[0])), message: "feature 必须直接导入领域契约模块,禁止依赖 shared/api-contract barrel"})
|
||||
}
|
||||
if strings.Contains(specifier, "shared/api-contract/") && isFeatureTransportBypass(relativePath) {
|
||||
violations = append(violations, violation{file: "frontend/" + relativePath, line: sourceLineAt(source, strings.Index(sourceText, match[0])), message: "feature UI、Hook、状态和组件不得直接依赖 transport DTO;只能通过本 feature 的 api adapter"})
|
||||
}
|
||||
violations = append(violations, checkCrossFeatureImport(relativePath, specifier)...)
|
||||
}
|
||||
return nil
|
||||
@@ -317,6 +320,17 @@ func checkReactArchitecture(root string) []violation {
|
||||
return violations
|
||||
}
|
||||
|
||||
// isFeatureTransportBypass 判断 feature 内的生产文件是否绕过 api adapter 直接读取 HTTP DTO。
|
||||
func isFeatureTransportBypass(relativePath string) bool {
|
||||
// featureRoot 表示只有 feature 根 api.ts 可以承担传输契约读取和 UI model 转换职责。
|
||||
featureRoot := regexp.MustCompile(`^app/features/[^/]+/api\.ts$`)
|
||||
if featureRoot.MatchString(relativePath) {
|
||||
return false
|
||||
}
|
||||
// itemLocationAdapter 是 items feature 的外部地图协议 adapter;它不属于 UI、Hook 或页面层。
|
||||
return relativePath != "app/features/items/amapLocation.ts"
|
||||
}
|
||||
|
||||
// checkCrossFeatureImport 拒绝 feature 直接导入另一个 feature 的内部实现。
|
||||
func checkCrossFeatureImport(sourcePath, specifier string) []violation {
|
||||
// sourceFeature 是当前源码所属的直属 feature 名称。
|
||||
|
||||
@@ -134,6 +134,10 @@ func TestReactArchitectureGate(t *testing.T) {
|
||||
if writeErr := os.WriteFile(filepath.Join(frontendRoot, "app", "features", "items", "bad.ts"), []byte("import { x } from '../../../shared/api-contract';\nvoid fetch('/x');\n"), 0o600); writeErr != nil {
|
||||
t.Fatal(writeErr)
|
||||
}
|
||||
// writeErr 表示写入绕过 feature API adapter 的契约依赖样例失败的文件系统原因。
|
||||
if writeErr := os.WriteFile(filepath.Join(frontendRoot, "app", "features", "items", "ui.ts"), []byte("import type { Item } from '../../../shared/api-contract/items';\nexport type Row = Item;\n"), 0o600); writeErr != nil {
|
||||
t.Fatal(writeErr)
|
||||
}
|
||||
// writeErr 表示写入缺少严格选项的 TypeScript 配置失败的文件系统原因。
|
||||
if writeErr := os.WriteFile(filepath.Join(frontendRoot, "tsconfig.json"), []byte("{\"compilerOptions\":{}}\n"), 0o600); writeErr != nil {
|
||||
t.Fatal(writeErr)
|
||||
|
||||
Reference in new issue
Block a user