@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,12 @@
|
|
|
1
|
+
export type GuardProductKind = "app" | "site" | "mini-program" | "extension" | "desktop";
|
|
2
|
+
export type GuardProductRoot = {
|
|
3
|
+
id: string;
|
|
4
|
+
kind: GuardProductKind;
|
|
5
|
+
root: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Guard 子规则共享的轻量 Product 枚举器。
|
|
9
|
+
*
|
|
10
|
+
* 非法或缺失 manifest 由 Product identity 规则统一报告;其它规则不猜测目录类型。
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectGuardProductRoots(workspaceRoot: string, kind?: GuardProductKind): Promise<GuardProductRoot[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Guard 子规则共享的轻量 Product 枚举器。
|
|
5
|
+
*
|
|
6
|
+
* 非法或缺失 manifest 由 Product identity 规则统一报告;其它规则不猜测目录类型。
|
|
7
|
+
*/
|
|
8
|
+
export async function collectGuardProductRoots(workspaceRoot, kind) {
|
|
9
|
+
const productsRoot = path.join(workspaceRoot, "products");
|
|
10
|
+
const entries = await readdir(productsRoot, { withFileTypes: true }).catch(() => []);
|
|
11
|
+
const products = [];
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
if (!entry.isDirectory())
|
|
14
|
+
continue;
|
|
15
|
+
const root = path.join(productsRoot, entry.name);
|
|
16
|
+
try {
|
|
17
|
+
const manifest = JSON.parse(await readFile(path.join(root, "product.json"), "utf8"));
|
|
18
|
+
if (manifest.id !== entry.name
|
|
19
|
+
|| !isProductKind(manifest.kind)
|
|
20
|
+
|| (kind !== undefined && manifest.kind !== kind)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
products.push({ id: entry.name, kind: manifest.kind, root });
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Product identity 规则负责非法 manifest;这里禁止基于目录名猜测 kind。
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return products.sort((left, right) => left.id.localeCompare(right.id));
|
|
30
|
+
}
|
|
31
|
+
function isProductKind(value) {
|
|
32
|
+
return value === "app"
|
|
33
|
+
|| value === "site"
|
|
34
|
+
|| value === "mini-program"
|
|
35
|
+
|| value === "extension"
|
|
36
|
+
|| value === "desktop";
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GuardOutputFormat } from "./core/types.js";
|
|
2
|
+
export type RepoGuardOptions = {
|
|
3
|
+
profile: string;
|
|
4
|
+
verifyFacades: boolean;
|
|
5
|
+
configPath: string | null;
|
|
6
|
+
formats: GuardOutputFormat[];
|
|
7
|
+
};
|
|
8
|
+
export declare function parseRepoGuardArgs(args: readonly string[]): RepoGuardOptions;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export function parseRepoGuardArgs(args) {
|
|
2
|
+
const options = {
|
|
3
|
+
profile: "all",
|
|
4
|
+
verifyFacades: false,
|
|
5
|
+
configPath: null,
|
|
6
|
+
formats: [],
|
|
7
|
+
};
|
|
8
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
9
|
+
const arg = args[index];
|
|
10
|
+
if (arg === "--verify-facades") {
|
|
11
|
+
options.verifyFacades = true;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (arg === "--profile") {
|
|
15
|
+
const value = args[index + 1];
|
|
16
|
+
if (!value) {
|
|
17
|
+
throw new Error("Missing value for --profile");
|
|
18
|
+
}
|
|
19
|
+
options.profile = value;
|
|
20
|
+
index += 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (arg.startsWith("--profile=")) {
|
|
24
|
+
const value = arg.slice("--profile=".length);
|
|
25
|
+
if (!value) {
|
|
26
|
+
throw new Error("Missing value for --profile");
|
|
27
|
+
}
|
|
28
|
+
options.profile = value;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (arg === "--config") {
|
|
32
|
+
const value = args[index + 1];
|
|
33
|
+
if (!value) {
|
|
34
|
+
throw new Error("Missing value for --config");
|
|
35
|
+
}
|
|
36
|
+
options.configPath = value;
|
|
37
|
+
index += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (arg.startsWith("--config=")) {
|
|
41
|
+
const value = arg.slice("--config=".length);
|
|
42
|
+
if (!value) {
|
|
43
|
+
throw new Error("Missing value for --config");
|
|
44
|
+
}
|
|
45
|
+
options.configPath = value;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (arg === "--format") {
|
|
49
|
+
const value = args[index + 1];
|
|
50
|
+
if (!value || !isGuardOutputFormat(value)) {
|
|
51
|
+
throw new Error("Missing or invalid value for --format");
|
|
52
|
+
}
|
|
53
|
+
if (!options.formats.includes(value)) {
|
|
54
|
+
options.formats.push(value);
|
|
55
|
+
}
|
|
56
|
+
index += 1;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (arg.startsWith("--format=")) {
|
|
60
|
+
const value = arg.slice("--format=".length);
|
|
61
|
+
if (!isGuardOutputFormat(value)) {
|
|
62
|
+
throw new Error("Missing or invalid value for --format");
|
|
63
|
+
}
|
|
64
|
+
if (!options.formats.includes(value)) {
|
|
65
|
+
options.formats.push(value);
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
70
|
+
}
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
function isGuardOutputFormat(value) {
|
|
74
|
+
return value === "text" || value === "sarif";
|
|
75
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GuardConfig, GuardRunResult } from "./core/types.js";
|
|
2
|
+
import type { RepoGuardOptions } from "./repo-args.js";
|
|
3
|
+
export declare function assertFacadeVerificationConfig(config: GuardConfig, profile: string): void;
|
|
4
|
+
export declare function emitRepoGuardResult(input: {
|
|
5
|
+
result: GuardRunResult;
|
|
6
|
+
config: GuardConfig;
|
|
7
|
+
options: RepoGuardOptions;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
platformVersion: string;
|
|
10
|
+
stdout(value: string): void;
|
|
11
|
+
stderr(value: string): void;
|
|
12
|
+
}): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { resolveProfileConfig } from "./core/config.js";
|
|
2
|
+
import { formatGuardSarifValue } from "./core/formatters/sarif-rules.js";
|
|
3
|
+
import { formatGuardText } from "./core/formatters/text.js";
|
|
4
|
+
export function assertFacadeVerificationConfig(config, profile) {
|
|
5
|
+
// 验证配方用本次规则执行替代独立 facade 命令,禁止配置降低其失败语义。
|
|
6
|
+
const facade = resolveProfileConfig({ config, profileName: profile }).rules
|
|
7
|
+
.find(rule => rule.id === "extension-facade-sync");
|
|
8
|
+
if (facade?.severity !== "error" || config.whitelist?.some(entry => entry.rule === "extension-facade-sync")) {
|
|
9
|
+
throw new Error("验证必须启用不可豁免的 extension-facade-sync error 规则");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function emitRepoGuardResult(input) {
|
|
13
|
+
const { result, config, options, json, platformVersion, stdout, stderr } = input;
|
|
14
|
+
if (json) {
|
|
15
|
+
stdout(JSON.stringify({
|
|
16
|
+
command: "guard.repo",
|
|
17
|
+
ok: result.counts.error === 0,
|
|
18
|
+
profile: result.profileName,
|
|
19
|
+
counts: result.counts,
|
|
20
|
+
diagnostics: result.diagnostics,
|
|
21
|
+
selectedRuleIds: result.selectedRuleIds,
|
|
22
|
+
}, null, 2));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const formats = options.formats.length > 0
|
|
26
|
+
? options.formats
|
|
27
|
+
: resolveProfileConfig({
|
|
28
|
+
config,
|
|
29
|
+
profileName: options.profile,
|
|
30
|
+
}).outputs;
|
|
31
|
+
for (const format of formats) {
|
|
32
|
+
if (format === "text") {
|
|
33
|
+
const text = formatGuardText(result);
|
|
34
|
+
if (formats.includes("sarif")) {
|
|
35
|
+
stderr(text);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
stdout(text);
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
stdout(formatGuardSarifValue(result, platformVersion));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { installCommonGitHooks, installGitHooks, resolveCanonicalHookAsset } from "./hooks/install.js";
|
|
2
|
+
export { parseRepoGuardArgs } from "./repo-args.js";
|
|
3
|
+
export type { RepoGuardOptions } from "./repo-args.js";
|
|
4
|
+
import { type GuardConfig, type GuardRuleRegistry, type GuardRunResult } from "./core/index.js";
|
|
5
|
+
export type ExecuteRepoGuardInput = {
|
|
6
|
+
args: readonly string[];
|
|
7
|
+
cwd: string;
|
|
8
|
+
workspaceRoot: string;
|
|
9
|
+
json?: boolean;
|
|
10
|
+
customRules?: GuardRuleRegistry;
|
|
11
|
+
stdout?: (value: string) => void;
|
|
12
|
+
stderr?: (value: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export type LoadedGuardConfig = {
|
|
15
|
+
config: GuardConfig;
|
|
16
|
+
customRules: GuardRuleRegistry;
|
|
17
|
+
};
|
|
18
|
+
export declare function executeRepoGuard(input: ExecuteRepoGuardInput): Promise<GuardRunResult>;
|
|
19
|
+
export declare function createGuardRuleRegistry(customRules?: GuardRuleRegistry): GuardRuleRegistry;
|
|
20
|
+
export declare function loadGuardConfig(configPath: string): Promise<GuardConfig>;
|
|
21
|
+
export declare function loadGuardConfigWithPlugins(configPath: string): Promise<LoadedGuardConfig>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { REPO_KIT_VERSION } from "../host-protocol.js";
|
|
2
|
+
import { assertFacadeVerificationConfig, emitRepoGuardResult } from "./repo-output-rules.js";
|
|
3
|
+
import { parseRepoGuardArgs } from "./repo-args.js";
|
|
4
|
+
export { installCommonGitHooks, installGitHooks, resolveCanonicalHookAsset } from "./hooks/install.js";
|
|
5
|
+
export { parseRepoGuardArgs } from "./repo-args.js";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { parseGuardConfig, runGuard, } from "./core/index.js";
|
|
11
|
+
import { externalRuleRegistry } from "./rules/external/index.js";
|
|
12
|
+
export async function executeRepoGuard(input) {
|
|
13
|
+
const options = parseRepoGuardArgs(input.args);
|
|
14
|
+
const configPath = options.configPath
|
|
15
|
+
? path.resolve(input.cwd, options.configPath)
|
|
16
|
+
: path.join(input.workspaceRoot, "guard.config.ts");
|
|
17
|
+
const { config, customRules } = await loadGuardConfigWithPlugins(configPath);
|
|
18
|
+
if (options.verifyFacades)
|
|
19
|
+
assertFacadeVerificationConfig(config, options.profile);
|
|
20
|
+
const result = await runGuard({
|
|
21
|
+
workspaceRoot: input.workspaceRoot,
|
|
22
|
+
profileName: options.profile,
|
|
23
|
+
config,
|
|
24
|
+
ruleRegistry: createGuardRuleRegistry({ ...customRules, ...input.customRules }),
|
|
25
|
+
});
|
|
26
|
+
const stdout = input.stdout ?? console.log;
|
|
27
|
+
const stderr = input.stderr ?? console.error;
|
|
28
|
+
emitRepoGuardResult({ result, config, options, json: input.json, platformVersion: REPO_KIT_VERSION, stdout, stderr });
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
export function createGuardRuleRegistry(customRules) {
|
|
32
|
+
return {
|
|
33
|
+
...externalRuleRegistry,
|
|
34
|
+
...customRules,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export async function loadGuardConfig(configPath) {
|
|
38
|
+
return (await loadGuardConfigWithPlugins(configPath)).config;
|
|
39
|
+
}
|
|
40
|
+
export async function loadGuardConfigWithPlugins(configPath) {
|
|
41
|
+
if (!existsSync(configPath)) {
|
|
42
|
+
throw new Error(`Guard config not found: ${configPath}`);
|
|
43
|
+
}
|
|
44
|
+
let module;
|
|
45
|
+
try {
|
|
46
|
+
module = (await import(pathToFileURL(configPath).href));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const code = error?.code;
|
|
50
|
+
if (configPath.endsWith(".ts") && (code === "ERR_UNKNOWN_FILE_EXTENSION" || code === "ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING")) {
|
|
51
|
+
const source = readFileSync(configPath, "utf8");
|
|
52
|
+
const transpiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } }).outputText;
|
|
53
|
+
const url = `data:text/javascript;base64,${Buffer.from(transpiled, "utf8").toString("base64")}`;
|
|
54
|
+
module = (await import(url));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const raw = module.default ?? module.guardConfig;
|
|
61
|
+
if (!raw || typeof raw !== "object") {
|
|
62
|
+
throw new Error(`Failed to load guard config from "${configPath}". Expected default export.`);
|
|
63
|
+
}
|
|
64
|
+
const record = raw;
|
|
65
|
+
const { customRules: inlineRules, ...rest } = record;
|
|
66
|
+
const mergedRules = {
|
|
67
|
+
...(inlineRules && typeof inlineRules === "object" ? inlineRules : {}),
|
|
68
|
+
...(module.customRules ?? {}),
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
config: parseGuardConfig(rest),
|
|
72
|
+
customRules: mergedRules,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { collectFiles, pathExists } from "../shared/records.js";
|
|
3
|
+
import { collectGuardProductRoots } from "../../../product-roots.js";
|
|
4
|
+
export async function collectOrphanApiTestRecords(workspaceRoot) {
|
|
5
|
+
const records = [];
|
|
6
|
+
for (const product of await collectGuardProductRoots(workspaceRoot, "extension")) {
|
|
7
|
+
const extensionId = product.id;
|
|
8
|
+
for (const layer of ["unit", "integration"]) {
|
|
9
|
+
const testRoot = path.join(product.root, "test", layer, "server");
|
|
10
|
+
if (!(await pathExists(testRoot))) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const testFiles = await collectFiles(testRoot, (filePath) => /\.test\.tsx?$/u.test(filePath));
|
|
14
|
+
for (const testFilePath of testFiles) {
|
|
15
|
+
const layerKey = toPosixPath(path.relative(testRoot, testFilePath)).replace(/\.test\.tsx?$/u, "");
|
|
16
|
+
const expectedApiFilePath = path.join(product.root, "src", "server", `${layerKey}.ts`);
|
|
17
|
+
if (await pathExists(expectedApiFilePath)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
records.push({
|
|
21
|
+
extensionId,
|
|
22
|
+
filePath: testFilePath,
|
|
23
|
+
relativeFilePath: toPosixPath(path.relative(workspaceRoot, testFilePath)),
|
|
24
|
+
layerKey,
|
|
25
|
+
expectedApiFilePath: toPosixPath(path.relative(workspaceRoot, expectedApiFilePath)),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return records;
|
|
31
|
+
}
|
|
32
|
+
function toPosixPath(value) {
|
|
33
|
+
return value.split(path.sep).join("/");
|
|
34
|
+
}
|