@kuafucloud/repo-kit 0.0.0-stage → 0.2.2-alpha.4
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/LICENSE.md +9 -0
- package/README.md +6 -2
- package/assets/git-hooks/check-push.cjs +21 -0
- package/assets/git-hooks/pre-push +7 -0
- package/assets/git-hooks/prepare-commit-msg +5 -0
- package/assets/verification/heavy-test-admission-core.d.mts +1 -0
- package/assets/verification/heavy-test-admission-core.mjs +10 -0
- package/assets/verification/host-process-lock.d.mts +24 -0
- package/assets/verification/host-process-lock.mjs +140 -0
- package/assets/verification/test-heavy-admission.d.mts +4 -0
- package/assets/verification/test-heavy-admission.mjs +34 -0
- package/bin/kuafu-guard.mjs +3 -0
- package/bin/kuafu-verify.mjs +3 -0
- package/dist/cli/guard.d.ts +1 -0
- package/dist/cli/guard.js +59 -0
- package/dist/cli/verify.d.ts +1 -0
- package/dist/cli/verify.js +58 -0
- package/dist/guard/core/config.d.ts +7 -0
- package/dist/guard/core/config.js +159 -0
- package/dist/guard/core/engine.d.ts +2 -0
- package/dist/guard/core/engine.js +151 -0
- package/dist/guard/core/formatters/sarif-rules.d.ts +2 -0
- package/dist/guard/core/formatters/sarif-rules.js +67 -0
- package/dist/guard/core/formatters/sarif.d.ts +2 -0
- package/dist/guard/core/formatters/sarif.js +3 -0
- package/dist/guard/core/formatters/text.d.ts +2 -0
- package/dist/guard/core/formatters/text.js +22 -0
- package/dist/guard/core/index.d.ts +5 -0
- package/dist/guard/core/index.js +5 -0
- package/dist/guard/core/types.d.ts +94 -0
- package/dist/guard/core/types.js +1 -0
- package/dist/guard/hooks/install-rules.d.ts +2 -0
- package/dist/guard/hooks/install-rules.js +5 -0
- package/dist/guard/hooks/install.d.ts +36 -0
- package/dist/guard/hooks/install.js +212 -0
- package/dist/guard/hooks/push.d.ts +1 -0
- package/dist/guard/hooks/push.js +5 -0
- package/dist/guard/index.d.ts +16 -0
- package/dist/guard/index.js +16 -0
- package/dist/guard/product-roots.d.ts +12 -0
- package/dist/guard/product-roots.js +37 -0
- package/dist/guard/repo-args.d.ts +8 -0
- package/dist/guard/repo-args.js +75 -0
- package/dist/guard/repo-output-rules.d.ts +12 -0
- package/dist/guard/repo-output-rules.js +44 -0
- package/dist/guard/repo.d.ts +21 -0
- package/dist/guard/repo.js +74 -0
- package/dist/guard/rules/external/api/collect-orphan-tests.d.ts +2 -0
- package/dist/guard/rules/external/api/collect-orphan-tests.js +34 -0
- package/dist/guard/rules/external/api/collect.d.ts +2 -0
- package/dist/guard/rules/external/api/collect.js +419 -0
- package/dist/guard/rules/external/api/validate-orphan-tests.d.ts +2 -0
- package/dist/guard/rules/external/api/validate-orphan-tests.js +10 -0
- package/dist/guard/rules/external/api/validate.d.ts +2 -0
- package/dist/guard/rules/external/api/validate.js +278 -0
- package/dist/guard/rules/external/app/native-source-rules.d.ts +6 -0
- package/dist/guard/rules/external/app/native-source-rules.js +164 -0
- package/dist/guard/rules/external/app/validate-native-source-boundary.d.ts +2 -0
- package/dist/guard/rules/external/app/validate-native-source-boundary.js +187 -0
- package/dist/guard/rules/external/boundary/check.d.ts +4 -0
- package/dist/guard/rules/external/boundary/check.js +198 -0
- package/dist/guard/rules/external/extension/collect.d.ts +1 -0
- package/dist/guard/rules/external/extension/collect.js +1 -0
- package/dist/guard/rules/external/extension/electron-boundary-rules.d.ts +6 -0
- package/dist/guard/rules/external/extension/electron-boundary-rules.js +10 -0
- package/dist/guard/rules/external/extension/index.d.ts +6 -0
- package/dist/guard/rules/external/extension/index.js +29 -0
- package/dist/guard/rules/external/extension/manual-cross-call-rules.d.ts +19 -0
- package/dist/guard/rules/external/extension/manual-cross-call-rules.js +19 -0
- package/dist/guard/rules/external/extension/resolve-import.d.ts +1 -0
- package/dist/guard/rules/external/extension/resolve-import.js +43 -0
- package/dist/guard/rules/external/extension/scan-relative-dependencies.d.ts +5 -0
- package/dist/guard/rules/external/extension/scan-relative-dependencies.js +53 -0
- package/dist/guard/rules/external/extension/scan-source.d.ts +11 -0
- package/dist/guard/rules/external/extension/scan-source.js +25 -0
- package/dist/guard/rules/external/extension/source-import-boundary-rules.d.ts +26 -0
- package/dist/guard/rules/external/extension/source-import-boundary-rules.js +40 -0
- package/dist/guard/rules/external/extension/test-layer-import-rules.d.ts +1 -0
- package/dist/guard/rules/external/extension/test-layer-import-rules.js +16 -0
- package/dist/guard/rules/external/extension/types.d.ts +51 -0
- package/dist/guard/rules/external/extension/types.js +1 -0
- package/dist/guard/rules/external/extension/unused-export-rules.d.ts +23 -0
- package/dist/guard/rules/external/extension/unused-export-rules.js +119 -0
- package/dist/guard/rules/external/extension/unused-module-rules.d.ts +6 -0
- package/dist/guard/rules/external/extension/unused-module-rules.js +90 -0
- package/dist/guard/rules/external/extension/validate-admin.d.ts +8 -0
- package/dist/guard/rules/external/extension/validate-admin.js +73 -0
- package/dist/guard/rules/external/extension/validate-database.d.ts +3 -0
- package/dist/guard/rules/external/extension/validate-database.js +4 -0
- package/dist/guard/rules/external/extension/validate-electron-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-electron-boundary.js +18 -0
- package/dist/guard/rules/external/extension/validate-empty-dirs.d.ts +9 -0
- package/dist/guard/rules/external/extension/validate-empty-dirs.js +44 -0
- package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-extension-kit-server-boundary.js +116 -0
- package/dist/guard/rules/external/extension/validate-features.d.ts +7 -0
- package/dist/guard/rules/external/extension/validate-features.js +27 -0
- package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-manual-cross-extension-call.js +131 -0
- package/dist/guard/rules/external/extension/validate-peer-extension-import.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-peer-extension-import.js +41 -0
- package/dist/guard/rules/external/extension/validate-server-cross-domain-import.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-server-cross-domain-import.js +48 -0
- package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.d.ts +1 -0
- package/dist/guard/rules/external/extension/validate-server-index-api-entry-satisfies.js +1 -0
- package/dist/guard/rules/external/extension/validate-shared-import-boundary.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-shared-import-boundary.js +40 -0
- package/dist/guard/rules/external/extension/validate-shared.d.ts +1 -0
- package/dist/guard/rules/external/extension/validate-shared.js +1 -0
- package/dist/guard/rules/external/extension/validate-test-layer-boundary.d.ts +8 -0
- package/dist/guard/rules/external/extension/validate-test-layer-boundary.js +59 -0
- package/dist/guard/rules/external/extension/validate-test-mirror.d.ts +4 -0
- package/dist/guard/rules/external/extension/validate-test-mirror.js +32 -0
- package/dist/guard/rules/external/extension/validate-top-level.d.ts +7 -0
- package/dist/guard/rules/external/extension/validate-top-level.js +76 -0
- package/dist/guard/rules/external/extension/validate-unused-export.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-unused-export.js +187 -0
- package/dist/guard/rules/external/extension/validate-unused-module.d.ts +2 -0
- package/dist/guard/rules/external/extension/validate-unused-module.js +38 -0
- package/dist/guard/rules/external/index.d.ts +1 -0
- package/dist/guard/rules/external/index.js +1 -0
- package/dist/guard/rules/external/npm-dependency-policy.d.ts +14 -0
- package/dist/guard/rules/external/npm-dependency-policy.js +216 -0
- package/dist/guard/rules/external/rules.d.ts +2 -0
- package/dist/guard/rules/external/rules.js +222 -0
- package/dist/guard/rules/external/shared/config.d.ts +3 -0
- package/dist/guard/rules/external/shared/config.js +14 -0
- package/dist/guard/rules/external/shared/diagnostic.d.ts +4 -0
- package/dist/guard/rules/external/shared/diagnostic.js +12 -0
- package/dist/guard/rules/external/shared/records.d.ts +4 -0
- package/dist/guard/rules/external/shared/records.js +46 -0
- package/dist/guard/rules/external/shared/ts-ast.d.ts +8 -0
- package/dist/guard/rules/external/shared/ts-ast.js +103 -0
- package/dist/guard/rules/external/shared/types.d.ts +159 -0
- package/dist/guard/rules/external/shared/types.js +1 -0
- package/dist/guard/rules/external/shared/validate-layer-key.d.ts +2 -0
- package/dist/guard/rules/external/shared/validate-layer-key.js +35 -0
- package/dist/guard/rules/external/story-rules.d.ts +15 -0
- package/dist/guard/rules/external/story-rules.js +59 -0
- package/dist/guard/rules/shared/extension/api-entry-tuple-rules.d.ts +7 -0
- package/dist/guard/rules/shared/extension/api-entry-tuple-rules.js +6 -0
- package/dist/guard/rules/shared/extension/collect.d.ts +5 -0
- package/dist/guard/rules/shared/extension/collect.js +231 -0
- package/dist/guard/rules/shared/extension/database-reference-rules.d.ts +4 -0
- package/dist/guard/rules/shared/extension/database-reference-rules.js +5 -0
- package/dist/guard/rules/shared/extension/database-source-rules.d.ts +17 -0
- package/dist/guard/rules/shared/extension/database-source-rules.js +595 -0
- package/dist/guard/rules/shared/extension/database-structure-rules.d.ts +3 -0
- package/dist/guard/rules/shared/extension/database-structure-rules.js +63 -0
- package/dist/guard/rules/shared/extension/server-index-source-rules.d.ts +2 -0
- package/dist/guard/rules/shared/extension/server-index-source-rules.js +91 -0
- package/dist/guard/rules/shared/extension/shared-consumer-rules.d.ts +23 -0
- package/dist/guard/rules/shared/extension/shared-consumer-rules.js +158 -0
- package/dist/guard/rules/shared/extension/shared-structure-rules.d.ts +6 -0
- package/dist/guard/rules/shared/extension/shared-structure-rules.js +27 -0
- package/dist/guard/rules/shared/extension/validate-database.d.ts +4 -0
- package/dist/guard/rules/shared/extension/validate-database.js +15 -0
- package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.d.ts +2 -0
- package/dist/guard/rules/shared/extension/validate-server-index-api-entry-satisfies.js +9 -0
- package/dist/guard/rules/shared/extension/validate-shared.d.ts +18 -0
- package/dist/guard/rules/shared/extension/validate-shared.js +149 -0
- package/dist/host-protocol.d.ts +2 -0
- package/dist/host-protocol.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/verify/artifact-recovery-rules.d.ts +39 -0
- package/dist/verify/artifact-recovery-rules.js +48 -0
- package/dist/verify/artifact-session.d.ts +91 -0
- package/dist/verify/artifact-session.js +443 -0
- package/dist/verify/checkout-environment-rules.d.ts +2 -0
- package/dist/verify/checkout-environment-rules.js +25 -0
- package/dist/verify/checkout-environment.d.ts +8 -0
- package/dist/verify/checkout-environment.js +24 -0
- package/dist/verify/commit-candidate-rules.d.ts +3 -0
- package/dist/verify/commit-candidate-rules.js +33 -0
- package/dist/verify/commit-gate.d.ts +64 -0
- package/dist/verify/commit-gate.js +144 -0
- package/dist/verify/delivery-verification.d.ts +3 -0
- package/dist/verify/delivery-verification.js +21 -0
- package/dist/verify/e2e-registry-rules.d.ts +21 -0
- package/dist/verify/e2e-registry-rules.js +33 -0
- package/dist/verify/e2e-registry.d.ts +2 -0
- package/dist/verify/e2e-registry.js +45 -0
- package/dist/verify/full-command.d.ts +35 -0
- package/dist/verify/full-command.js +124 -0
- package/dist/verify/impact-plan-rules.d.ts +61 -0
- package/dist/verify/impact-plan-rules.js +185 -0
- package/dist/verify/impact-plan.d.ts +10 -0
- package/dist/verify/impact-plan.js +151 -0
- package/dist/verify/index.d.ts +22 -0
- package/dist/verify/index.js +22 -0
- package/dist/verify/repository-recipe-rules.d.ts +31 -0
- package/dist/verify/repository-recipe-rules.js +60 -0
- package/dist/verify/repository-recipe.d.ts +3 -0
- package/dist/verify/repository-recipe.js +58 -0
- package/dist/verify/static-validation-rules.d.ts +7 -0
- package/dist/verify/static-validation-rules.js +36 -0
- package/dist/verify/story-selection-rules.d.ts +57 -0
- package/dist/verify/story-selection-rules.js +125 -0
- package/dist/verify/types.d.ts +63 -0
- package/dist/verify/types.js +18 -0
- package/dist/verify/verification-candidate.d.ts +1 -0
- package/dist/verify/verification-candidate.js +20 -0
- package/dist/verify/verification-identity.d.ts +6 -0
- package/dist/verify/verification-identity.js +26 -0
- package/dist/verify/verification-proof-rules.d.ts +35 -0
- package/dist/verify/verification-proof-rules.js +45 -0
- package/dist/verify/verify-full-command-rules.d.ts +18 -0
- package/dist/verify/verify-full-command-rules.js +77 -0
- package/dist/verify/verify-full-runner.d.ts +32 -0
- package/dist/verify/verify-full-runner.js +251 -0
- package/package.json +115 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const BUILD_CONSUMED_ENTRY_FILES = [
|
|
3
|
+
"src/product.ts",
|
|
4
|
+
"src/simulation/index.ts",
|
|
5
|
+
"src/simulation/server/index.ts",
|
|
6
|
+
"src/simulation/database/index.ts",
|
|
7
|
+
"src/simulation/database/install.ts",
|
|
8
|
+
"src/simulation/database/bootstrap.ts",
|
|
9
|
+
"src/server/index.ts",
|
|
10
|
+
"src/database/index.ts",
|
|
11
|
+
"src/database/bootstrap.ts",
|
|
12
|
+
"src/database/install.ts",
|
|
13
|
+
"src/database/datasets/local.ts",
|
|
14
|
+
"src/database/datasets/demo.ts",
|
|
15
|
+
"src/server/database/schema/index.ts",
|
|
16
|
+
"src/server/database/bootstrap.ts",
|
|
17
|
+
"src/server/database/install.ts",
|
|
18
|
+
"src/admin/locales/index.ts",
|
|
19
|
+
"src/permissions.ts",
|
|
20
|
+
"src/events.ts",
|
|
21
|
+
"src/tasks.ts",
|
|
22
|
+
"src/hooks.ts",
|
|
23
|
+
"src/plugins.ts",
|
|
24
|
+
"src/define/permissions.ts",
|
|
25
|
+
"src/define/events.ts",
|
|
26
|
+
"src/define/tasks.ts",
|
|
27
|
+
"src/define/hooks.ts",
|
|
28
|
+
"src/define/plugins.ts",
|
|
29
|
+
];
|
|
30
|
+
export function addEdge(graph, from, to) {
|
|
31
|
+
const values = graph.get(from) ?? new Set();
|
|
32
|
+
values.add(to);
|
|
33
|
+
graph.set(from, values);
|
|
34
|
+
}
|
|
35
|
+
export function composeSymbolKey(filePath, symbolName) {
|
|
36
|
+
return `${filePath}::${symbolName}`;
|
|
37
|
+
}
|
|
38
|
+
export function parseSymbolKey(symbolKey) {
|
|
39
|
+
const index = symbolKey.lastIndexOf("::");
|
|
40
|
+
return {
|
|
41
|
+
filePath: symbolKey.slice(0, index),
|
|
42
|
+
symbolName: symbolKey.slice(index + 2),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function isConsumedSymbol(symbolKey, terminalSymbolKeys, terminalAllModules, namedReexportEdges, exportAllEdges) {
|
|
46
|
+
const visited = new Set();
|
|
47
|
+
const queue = [symbolKey];
|
|
48
|
+
while (queue.length > 0) {
|
|
49
|
+
const current = queue.shift();
|
|
50
|
+
if (!current || visited.has(current)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
visited.add(current);
|
|
54
|
+
const { filePath, symbolName } = parseSymbolKey(current);
|
|
55
|
+
if (terminalAllModules.has(filePath) ||
|
|
56
|
+
terminalSymbolKeys.has(current)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
for (const next of namedReexportEdges.get(current) ?? []) {
|
|
60
|
+
if (!visited.has(next)) {
|
|
61
|
+
queue.push(next);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const targetFile of exportAllEdges.get(filePath) ?? []) {
|
|
65
|
+
const next = composeSymbolKey(targetFile, symbolName);
|
|
66
|
+
if (!visited.has(next)) {
|
|
67
|
+
queue.push(next);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
export function isExportExemptFile(filePath, extensionRoot) {
|
|
74
|
+
const relativePath = toPosix(path.relative(extensionRoot, filePath));
|
|
75
|
+
return (relativePath === "src/index.ts" ||
|
|
76
|
+
relativePath === "src/server/index.ts" ||
|
|
77
|
+
/^src\/admin\/pages\/.+\/index\.tsx?$/u.test(relativePath) ||
|
|
78
|
+
relativePath === "src/database/index.ts");
|
|
79
|
+
}
|
|
80
|
+
export function resolveBuildConsumedModules(extensionRoot, allFiles) {
|
|
81
|
+
const modules = [];
|
|
82
|
+
for (const relativePath of BUILD_CONSUMED_ENTRY_FILES) {
|
|
83
|
+
const absolutePath = path.join(extensionRoot, relativePath);
|
|
84
|
+
if (allFiles.has(absolutePath)) {
|
|
85
|
+
modules.push(absolutePath);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return modules;
|
|
89
|
+
}
|
|
90
|
+
function toPosix(value) { return value.split(path.sep).join("/"); }
|
|
91
|
+
export function inspectUnusedExportGraph(input) {
|
|
92
|
+
const workspaceRoot = input.workspaceRoot;
|
|
93
|
+
const allFiles = new Set(input.exportedSymbolsByFile.keys());
|
|
94
|
+
const issues = [];
|
|
95
|
+
for (const buildEntry of resolveBuildConsumedModules(input.extensionRoot, allFiles)) {
|
|
96
|
+
input.terminalAllModules.add(buildEntry);
|
|
97
|
+
}
|
|
98
|
+
for (const [filePath, exportedSymbols] of input.exportedSymbolsByFile) {
|
|
99
|
+
if (filePath.endsWith(".tsx")) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (isExportExemptFile(filePath, input.extensionRoot)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
for (const symbol of exportedSymbols.values()) {
|
|
106
|
+
const symbolKey = composeSymbolKey(filePath, symbol.name);
|
|
107
|
+
if (isConsumedSymbol(symbolKey, input.terminalSymbolKeys, input.terminalAllModules, input.namedReexportEdges, input.exportAllEdges)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
issues.push({
|
|
111
|
+
rule: "extension-unused-export",
|
|
112
|
+
filePath: toPosix(path.relative(workspaceRoot, filePath)),
|
|
113
|
+
lineNumber: symbol.line,
|
|
114
|
+
message: `导出符号 "${symbol.name}" 未被任何模块消费(含 re-export 链)。请删除该导出或补充实际消费方。`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return issues;
|
|
119
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Issue } from "../shared/types.js";
|
|
2
|
+
export declare function resolveEntryFiles(extensionRoot: string, allFiles: Set<string>): string[];
|
|
3
|
+
export declare function isAdminPageEntryFile(extensionRoot: string, filePath: string): boolean;
|
|
4
|
+
export declare function isAdminOverlayEntryFile(extensionRoot: string, filePath: string): boolean;
|
|
5
|
+
export declare function traverseReachableFiles(entryFiles: string[], importGraph: Map<string, string[]>): Set<string>;
|
|
6
|
+
export declare function inspectUnusedModuleGraph(workspaceRoot: string, extensionRoot: string, files: string[], importGraph: Map<string, string[]>): Issue[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const SOURCE_ENTRIES = [
|
|
3
|
+
"src/index.ts",
|
|
4
|
+
"src/server/index.ts",
|
|
5
|
+
"src/admin/locales/index.ts",
|
|
6
|
+
"src/database/index.ts",
|
|
7
|
+
"src/database/bootstrap.ts",
|
|
8
|
+
"src/database/install.ts",
|
|
9
|
+
"src/database/datasets/local.ts",
|
|
10
|
+
"src/database/datasets/demo.ts",
|
|
11
|
+
"src/server/database/schema/index.ts",
|
|
12
|
+
"src/server/database/bootstrap.ts",
|
|
13
|
+
"src/server/database/install.ts",
|
|
14
|
+
"src/product.ts",
|
|
15
|
+
"src/simulation/index.ts",
|
|
16
|
+
"src/simulation/server/index.ts",
|
|
17
|
+
"src/simulation/database/index.ts",
|
|
18
|
+
"src/simulation/database/install.ts",
|
|
19
|
+
"src/simulation/database/bootstrap.ts",
|
|
20
|
+
"src/permissions.ts",
|
|
21
|
+
"src/events.ts",
|
|
22
|
+
"src/tasks.ts",
|
|
23
|
+
"src/hooks.ts",
|
|
24
|
+
"src/plugins.ts",
|
|
25
|
+
"src/define/permissions.ts",
|
|
26
|
+
"src/define/events.ts",
|
|
27
|
+
"src/define/tasks.ts",
|
|
28
|
+
"src/define/hooks.ts",
|
|
29
|
+
"src/define/plugins.ts",
|
|
30
|
+
];
|
|
31
|
+
export function resolveEntryFiles(extensionRoot, allFiles) {
|
|
32
|
+
const entries = [];
|
|
33
|
+
for (const relativeEntry of SOURCE_ENTRIES) {
|
|
34
|
+
const absolutePath = path.join(extensionRoot, relativeEntry);
|
|
35
|
+
if (allFiles.has(absolutePath)) {
|
|
36
|
+
entries.push(absolutePath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const filePath of allFiles) {
|
|
40
|
+
if (isAdminPageEntryFile(extensionRoot, filePath)
|
|
41
|
+
|| isAdminOverlayEntryFile(extensionRoot, filePath)) {
|
|
42
|
+
entries.push(filePath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return entries;
|
|
46
|
+
}
|
|
47
|
+
export function isAdminPageEntryFile(extensionRoot, filePath) {
|
|
48
|
+
const relativePath = toPosix(path.relative(extensionRoot, filePath));
|
|
49
|
+
return /^src\/admin\/pages\/.+\/index\.tsx?$/u.test(relativePath);
|
|
50
|
+
}
|
|
51
|
+
export function isAdminOverlayEntryFile(extensionRoot, filePath) {
|
|
52
|
+
const relativePath = toPosix(path.relative(extensionRoot, filePath));
|
|
53
|
+
return /^src\/admin\/overlays\/.+\/index\.tsx?$/u.test(relativePath);
|
|
54
|
+
}
|
|
55
|
+
export function traverseReachableFiles(entryFiles, importGraph) {
|
|
56
|
+
const visited = new Set();
|
|
57
|
+
const queue = [...entryFiles];
|
|
58
|
+
while (queue.length > 0) {
|
|
59
|
+
const current = queue.shift();
|
|
60
|
+
if (!current || visited.has(current)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
visited.add(current);
|
|
64
|
+
for (const dependency of importGraph.get(current) ?? []) {
|
|
65
|
+
if (!visited.has(dependency)) {
|
|
66
|
+
queue.push(dependency);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return visited;
|
|
71
|
+
}
|
|
72
|
+
function toPosix(value) { return value.split(path.sep).join("/"); }
|
|
73
|
+
export function inspectUnusedModuleGraph(workspaceRoot, extensionRoot, files, importGraph) {
|
|
74
|
+
const allFiles = new Set(files);
|
|
75
|
+
const issues = [];
|
|
76
|
+
const entryFiles = resolveEntryFiles(extensionRoot, allFiles);
|
|
77
|
+
const visited = traverseReachableFiles(entryFiles, importGraph);
|
|
78
|
+
for (const filePath of files) {
|
|
79
|
+
if (visited.has(filePath)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
issues.push({
|
|
83
|
+
rule: "extension-unused-module",
|
|
84
|
+
filePath: toPosix(path.relative(workspaceRoot, filePath)),
|
|
85
|
+
lineNumber: 1,
|
|
86
|
+
message: "该模块未从扩展入口链路被消费,属于死文件。请删除此文件或将其接入 src/index.ts、src/server/index.ts、src/admin/pages/**/index.tsx、src/admin/overlays/**/index.tsx、src/database/index.ts 等入口依赖图。",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return issues;
|
|
90
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExtensionStructureRecord } from "./types.js";
|
|
2
|
+
import type { Issue } from "../shared/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* 验证 admin/ 目录结构:
|
|
5
|
+
* - extension-admin-structure: admin/ 根目录只允许约定的模块目录,导航定义归 product.json 所有
|
|
6
|
+
* - extension-admin-forbidden-file: admin/ 不能包含 runtime.ts、ui.tsx、ui.ts、dev.tsx
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateAdmin(record: ExtensionStructureRecord, workspaceRoot: string): Issue[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* admin/ 允许的根目录
|
|
4
|
+
*/
|
|
5
|
+
const ALLOWED_ADMIN_DIRS = new Set([
|
|
6
|
+
"pages",
|
|
7
|
+
"components",
|
|
8
|
+
"hooks",
|
|
9
|
+
"lib",
|
|
10
|
+
"assets",
|
|
11
|
+
"styles",
|
|
12
|
+
"types",
|
|
13
|
+
"locales",
|
|
14
|
+
"overlays",
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* admin/ 禁止的文件
|
|
18
|
+
*/
|
|
19
|
+
const FORBIDDEN_ADMIN_FILES = new Set([
|
|
20
|
+
"runtime.ts",
|
|
21
|
+
"ui.tsx",
|
|
22
|
+
"ui.ts",
|
|
23
|
+
"dev.tsx",
|
|
24
|
+
]);
|
|
25
|
+
/**
|
|
26
|
+
* 验证 admin/ 目录结构:
|
|
27
|
+
* - extension-admin-structure: admin/ 根目录只允许约定的模块目录,导航定义归 product.json 所有
|
|
28
|
+
* - extension-admin-forbidden-file: admin/ 不能包含 runtime.ts、ui.tsx、ui.ts、dev.tsx
|
|
29
|
+
*/
|
|
30
|
+
export function validateAdmin(record, workspaceRoot) {
|
|
31
|
+
const issues = [];
|
|
32
|
+
const adminDir = path.join(record.extensionRoot, "src", "admin");
|
|
33
|
+
// 如果 admin/ 不存在则跳过
|
|
34
|
+
if (record.adminFiles.length === 0 && record.adminDirs.length === 0) {
|
|
35
|
+
return issues;
|
|
36
|
+
}
|
|
37
|
+
// 检查 admin/ 结构
|
|
38
|
+
for (const fileName of record.adminFiles) {
|
|
39
|
+
if (FORBIDDEN_ADMIN_FILES.has(fileName)) {
|
|
40
|
+
const filePath = path.relative(workspaceRoot, path.join(adminDir, fileName));
|
|
41
|
+
issues.push({
|
|
42
|
+
rule: "extension-admin-forbidden-file",
|
|
43
|
+
filePath: toPosix(filePath),
|
|
44
|
+
lineNumber: 1,
|
|
45
|
+
message: `admin/ 下不允许存在文件 "${fileName}"。此文件类型已被移除或不应存在。`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const filePath = path.relative(workspaceRoot, path.join(adminDir, fileName));
|
|
50
|
+
issues.push({
|
|
51
|
+
rule: "extension-admin-structure",
|
|
52
|
+
filePath: toPosix(filePath),
|
|
53
|
+
lineNumber: 1,
|
|
54
|
+
message: `admin/ 下不允许存在文件 "${fileName}"。Extension 导航请在 product.json#extension.admin.navigation 声明。`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const dirName of record.adminDirs) {
|
|
59
|
+
if (!ALLOWED_ADMIN_DIRS.has(dirName)) {
|
|
60
|
+
const dirPath = path.relative(workspaceRoot, path.join(adminDir, dirName));
|
|
61
|
+
issues.push({
|
|
62
|
+
rule: "extension-admin-structure",
|
|
63
|
+
filePath: toPosix(dirPath),
|
|
64
|
+
lineNumber: 1,
|
|
65
|
+
message: `admin/ 下不允许存在目录 "${dirName}/"。只允许 ${[...ALLOWED_ADMIN_DIRS].join("、")}。`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return issues;
|
|
70
|
+
}
|
|
71
|
+
function toPosix(value) {
|
|
72
|
+
return value.split(path.sep).join("/");
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { collectExtensionSourceRecords, toPosix } from "./scan-source.js";
|
|
4
|
+
const SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
|
|
5
|
+
import { inspectExtensionElectronSource } from "./electron-boundary-rules.js";
|
|
6
|
+
export async function collectExtensionElectronBoundaryIssues(workspaceRoot) {
|
|
7
|
+
const records = await collectExtensionSourceRecords(workspaceRoot, (filePath) => SOURCE_FILE.test(filePath));
|
|
8
|
+
const issues = [];
|
|
9
|
+
for (const record of records) {
|
|
10
|
+
for (const filePath of record.srcFiles) {
|
|
11
|
+
const relativeToSource = toPosix(path.relative(record.srcRoot, filePath));
|
|
12
|
+
if (!relativeToSource.startsWith("admin/"))
|
|
13
|
+
continue;
|
|
14
|
+
issues.push(...inspectExtensionElectronSource({ filePath: toPosix(path.relative(workspaceRoot, filePath)), relativeToSource, content: await readFile(filePath, "utf8") }));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return issues;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExtensionStructureRecord } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* 清理空目录(仅含 .gitkeep 或完全为空的目录)。
|
|
4
|
+
* 返回已清理的目录列表和警告信息。
|
|
5
|
+
*/
|
|
6
|
+
export declare function cleanEmptyDirs(records: ExtensionStructureRecord[], workspaceRoot: string): Promise<{
|
|
7
|
+
cleanedDirs: string[];
|
|
8
|
+
warnings: string[];
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* 清理空目录(仅含 .gitkeep 或完全为空的目录)。
|
|
5
|
+
* 返回已清理的目录列表和警告信息。
|
|
6
|
+
*/
|
|
7
|
+
export async function cleanEmptyDirs(records, workspaceRoot) {
|
|
8
|
+
const cleanedDirs = [];
|
|
9
|
+
const warnings = [];
|
|
10
|
+
for (const record of records) {
|
|
11
|
+
// 从深到浅排序,先删除最内层的空目录
|
|
12
|
+
const sortedEmptyDirs = [...record.emptyDirs].sort((a, b) => b.length - a.length);
|
|
13
|
+
for (const emptyDir of sortedEmptyDirs) {
|
|
14
|
+
// 再次检查是否仍然为空(可能已被父级清理删除)
|
|
15
|
+
try {
|
|
16
|
+
const entries = await fs.readdir(emptyDir);
|
|
17
|
+
const nonGitkeep = entries.filter((e) => e !== ".gitkeep");
|
|
18
|
+
if (nonGitkeep.length > 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
// 删除目录中的 .gitkeep 文件(如果有)
|
|
22
|
+
const gitkeepPath = path.join(emptyDir, ".gitkeep");
|
|
23
|
+
try {
|
|
24
|
+
await fs.unlink(gitkeepPath);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// .gitkeep 可能不存在,忽略
|
|
28
|
+
}
|
|
29
|
+
// 删除空目录
|
|
30
|
+
await fs.rmdir(emptyDir);
|
|
31
|
+
const relPath = path.relative(workspaceRoot, emptyDir);
|
|
32
|
+
cleanedDirs.push(toPosix(relPath));
|
|
33
|
+
warnings.push(`已清理空目录: ${toPosix(relPath)}。如需保留,请添加 .gitkeep 文件。`);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// 目录可能已被之前的清理操作删除,忽略
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { cleanedDirs, warnings };
|
|
41
|
+
}
|
|
42
|
+
function toPosix(value) {
|
|
43
|
+
return value.split(path.sep).join("/");
|
|
44
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { getLineNumber, parseSourceFile } from "../shared/ts-ast.js";
|
|
6
|
+
import { collectExtensionSourceRecords, toPosix } from "./scan-source.js";
|
|
7
|
+
const EXTENSION_KIT_SERVER_SPECIFIER = "@kuafucloud/extension-kit/server";
|
|
8
|
+
const RESTRICTED_SPECIFIERS = new Set([
|
|
9
|
+
"@kuafucloud/extension-kit/server/internal",
|
|
10
|
+
"@kuafucloud/extension-kit/server/system",
|
|
11
|
+
]);
|
|
12
|
+
const PLATFORM_EXTENSION_REPO_INTERNAL_CONSUMERS = new Set([
|
|
13
|
+
"products/im/src/shared/directory.ts",
|
|
14
|
+
]);
|
|
15
|
+
const PLATFORM_EXTENSION_REPO_SYSTEM_CONSUMERS = new Set([
|
|
16
|
+
"products/data/src/shared/system-sampling.ts",
|
|
17
|
+
"products/data/src/server/internal/home/run.ts",
|
|
18
|
+
"products/developer/src/server/develop/workspace-chat/register.ts",
|
|
19
|
+
"products/developer/src/server/internal/workspace-chat/register.ts",
|
|
20
|
+
"products/developer/src/shared/workspace-chat-membership.ts",
|
|
21
|
+
"products/developer/src/shared/workspace-chat-relay.ts",
|
|
22
|
+
"products/developer/src/server/develop/definition/query.ts",
|
|
23
|
+
"products/developer/src/shared/monitoring-catalog.ts",
|
|
24
|
+
"products/developer/src/shared/platform-repository-authority.ts",
|
|
25
|
+
"products/developer/src/server/develop/product/traffic/get.ts",
|
|
26
|
+
"products/developer/src/server/develop/release/product/deployment.ts",
|
|
27
|
+
"products/developer/src/server/develop/release/list.ts",
|
|
28
|
+
]);
|
|
29
|
+
const SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
|
|
30
|
+
async function isPlatformExtensionRepository(workspaceRoot) {
|
|
31
|
+
const pkgPath = path.join(workspaceRoot, "package.json");
|
|
32
|
+
if (!existsSync(pkgPath))
|
|
33
|
+
return false;
|
|
34
|
+
try {
|
|
35
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf8"));
|
|
36
|
+
return pkg.kuafucloud?.classification === "extension-repository";
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isAllowedPlatformExtensionRepoConsumer(relativeFilePath, specifier) {
|
|
43
|
+
if (relativeFilePath.startsWith("products/system/"))
|
|
44
|
+
return true;
|
|
45
|
+
if (specifier === "@kuafucloud/extension-kit/server/system") {
|
|
46
|
+
return PLATFORM_EXTENSION_REPO_SYSTEM_CONSUMERS.has(relativeFilePath);
|
|
47
|
+
}
|
|
48
|
+
return PLATFORM_EXTENSION_REPO_INTERNAL_CONSUMERS.has(relativeFilePath);
|
|
49
|
+
}
|
|
50
|
+
function isExtensionKitServerSpecifier(specifier) {
|
|
51
|
+
return (specifier === EXTENSION_KIT_SERVER_SPECIFIER
|
|
52
|
+
|| specifier.startsWith(`${EXTENSION_KIT_SERVER_SPECIFIER}/`));
|
|
53
|
+
}
|
|
54
|
+
function isBrowserSourcePath(relativeFilePath) {
|
|
55
|
+
return /\/src\/(?:admin|admin-ui|client)(?:\/|$)/u.test(relativeFilePath);
|
|
56
|
+
}
|
|
57
|
+
function collectModuleSpecifiers(sourceFile) {
|
|
58
|
+
const results = [];
|
|
59
|
+
const visit = (node) => {
|
|
60
|
+
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node))
|
|
61
|
+
&& node.moduleSpecifier
|
|
62
|
+
&& ts.isStringLiteral(node.moduleSpecifier)) {
|
|
63
|
+
results.push({
|
|
64
|
+
specifier: node.moduleSpecifier.text,
|
|
65
|
+
lineNumber: getLineNumber(sourceFile, node.moduleSpecifier),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else if (ts.isCallExpression(node)
|
|
69
|
+
&& node.arguments.length >= 1
|
|
70
|
+
&& ts.isStringLiteral(node.arguments[0])
|
|
71
|
+
&& (node.expression.kind === ts.SyntaxKind.ImportKeyword
|
|
72
|
+
|| (ts.isIdentifier(node.expression) && node.expression.text === "require"))) {
|
|
73
|
+
results.push({
|
|
74
|
+
specifier: node.arguments[0].text,
|
|
75
|
+
lineNumber: getLineNumber(sourceFile, node.arguments[0]),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
ts.forEachChild(node, visit);
|
|
79
|
+
};
|
|
80
|
+
visit(sourceFile);
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
export async function collectExternalExtensionKitServerBoundaryIssues(workspaceRoot) {
|
|
84
|
+
const platformExtRepo = await isPlatformExtensionRepository(workspaceRoot);
|
|
85
|
+
const records = await collectExtensionSourceRecords(workspaceRoot, (filePath) => SOURCE_FILE.test(filePath) && !filePath.endsWith(".d.ts"));
|
|
86
|
+
const issues = [];
|
|
87
|
+
for (const record of records) {
|
|
88
|
+
for (const filePath of record.srcFiles) {
|
|
89
|
+
const relativeFilePath = toPosix(path.relative(workspaceRoot, filePath));
|
|
90
|
+
const browserSource = isBrowserSourcePath(relativeFilePath);
|
|
91
|
+
const sourceFile = await parseSourceFile(filePath);
|
|
92
|
+
for (const { specifier, lineNumber } of collectModuleSpecifiers(sourceFile)) {
|
|
93
|
+
if (!isExtensionKitServerSpecifier(specifier))
|
|
94
|
+
continue;
|
|
95
|
+
if (browserSource) {
|
|
96
|
+
issues.push({
|
|
97
|
+
rule: "extension-kit-server-boundary",
|
|
98
|
+
filePath: relativeFilePath,
|
|
99
|
+
lineNumber,
|
|
100
|
+
message: "浏览器侧 admin、admin-ui、client 源码禁止导入 @kuafucloud/extension-kit/server 及其子路径。",
|
|
101
|
+
});
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (RESTRICTED_SPECIFIERS.has(specifier) && !(platformExtRepo && isAllowedPlatformExtensionRepoConsumer(relativeFilePath, specifier))) {
|
|
105
|
+
issues.push({
|
|
106
|
+
rule: "extension-kit-server-boundary",
|
|
107
|
+
filePath: relativeFilePath,
|
|
108
|
+
lineNumber,
|
|
109
|
+
message: `${specifier} 是受限 Server Runtime 入口,业务仓库禁止直接导入。`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return issues;
|
|
116
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExtensionStructureRecord } from "./types.js";
|
|
2
|
+
import type { Issue } from "../shared/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* 验证 admin/features/ 目录结构:
|
|
5
|
+
* - extension-admin-features-no-loose-files: features/ 下不允许散落文件,只允许子目录
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateFeatures(record: ExtensionStructureRecord, workspaceRoot: string): Issue[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* 验证 admin/features/ 目录结构:
|
|
4
|
+
* - extension-admin-features-no-loose-files: features/ 下不允许散落文件,只允许子目录
|
|
5
|
+
*/
|
|
6
|
+
export function validateFeatures(record, workspaceRoot) {
|
|
7
|
+
const issues = [];
|
|
8
|
+
// 如果 adminDirs 中没有 features,跳过
|
|
9
|
+
if (!record.adminDirs.includes("features")) {
|
|
10
|
+
return issues;
|
|
11
|
+
}
|
|
12
|
+
const featuresDir = path.join(record.extensionRoot, "src", "admin", "features");
|
|
13
|
+
// features/ 下不允许散落文件
|
|
14
|
+
for (const fileName of record.featuresFiles) {
|
|
15
|
+
const filePath = path.relative(workspaceRoot, path.join(featuresDir, fileName));
|
|
16
|
+
issues.push({
|
|
17
|
+
rule: "extension-admin-features-no-loose-files",
|
|
18
|
+
filePath: toPosix(filePath),
|
|
19
|
+
lineNumber: 1,
|
|
20
|
+
message: `admin/features/ 下不允许散落文件 "${fileName}"。只允许子目录(如 features/chat/)。`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return issues;
|
|
24
|
+
}
|
|
25
|
+
function toPosix(value) {
|
|
26
|
+
return value.split(path.sep).join("/");
|
|
27
|
+
}
|