@open-mercato/cli 0.11.1-develop.8784.1.e9d95a72f5 → 0.11.1-develop.8805.1.6357054d1a
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/.turbo/turbo-build.log +4 -2
- package/AGENTS.md +2 -0
- package/dist/agentic/guides/architecture.md +1 -0
- package/dist/agentic/guides/module-facts.json +2014 -1099
- package/dist/agentic/guides/module-facts.v2.json +2014 -1099
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/auth/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/cart/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +11 -8
- package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -5
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +11 -8
- package/dist/agentic/guides/modules/catalog/index.md +2 -2
- package/dist/agentic/guides/modules/catalog/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
- package/dist/agentic/guides/modules/configs/acl-features.md +2 -1
- package/dist/agentic/guides/modules/configs/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/configs/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/configs/host-extension-points.md +10 -0
- package/dist/agentic/guides/modules/configs/index.md +5 -3
- package/dist/agentic/guides/modules/configs/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/configs/setup.md +1 -1
- package/dist/agentic/guides/modules/configs/umes-diagnostics.md +9 -0
- package/dist/agentic/guides/modules/configs/umes-hosts.md +9 -0
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -0
- package/dist/agentic/guides/modules/customers/contribution-resolutions.md +2 -0
- package/dist/agentic/guides/modules/customers/di-registrations-rich.md +8 -5
- package/dist/agentic/guides/modules/customers/exact-override-targets.md +10 -5
- package/dist/agentic/guides/modules/customers/index.md +5 -5
- package/dist/agentic/guides/modules/customers/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/customers/umes-contributions.md +2 -0
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -10
- package/dist/agentic/guides/modules/dashboards/contribution-resolutions.md +0 -10
- package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +0 -10
- package/dist/agentic/guides/modules/dashboards/index.md +5 -5
- package/dist/agentic/guides/modules/dashboards/umes-contributions.md +0 -10
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/entities/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/events/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/ledger/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/active-extension-bindings.md +8 -0
- package/dist/agentic/guides/modules/sales/contribution-resolutions.md +8 -0
- package/dist/agentic/guides/modules/sales/di-registrations-rich.md +31 -30
- package/dist/agentic/guides/modules/sales/di-service-tokens.md +5 -5
- package/dist/agentic/guides/modules/sales/exact-override-targets.md +39 -30
- package/dist/agentic/guides/modules/sales/index.md +5 -5
- package/dist/agentic/guides/modules/sales/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/sales/umes-contributions.md +8 -0
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/search/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/active-extension-bindings.md +2 -1
- package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -0
- package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/staff/index.md +8 -8
- package/dist/agentic/guides/modules/staff/umes-contributions.md +1 -0
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/upgrade_actions/contribution-resolutions.md +12 -0
- package/dist/agentic/guides/modules/upgrade_actions/exact-override-targets.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/index.md +15 -0
- package/dist/agentic/guides/modules/upgrade_actions/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/umes-contributions.md +12 -0
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/lib/generators/extensions/dashboard-widgets.js +46 -4
- package/dist/lib/generators/extensions/dashboard-widgets.js.map +2 -2
- package/dist/lib/generators/extensions/workflows.js +25 -2
- package/dist/lib/generators/extensions/workflows.js.map +2 -2
- package/dist/lib/generators/module-facts.js +2 -0
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-registry.js +7 -6
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/module-coupling/analyze.js +391 -0
- package/dist/lib/module-coupling/analyze.js.map +7 -0
- package/dist/lib/module-diagnostics.js +160 -0
- package/dist/lib/module-diagnostics.js.map +7 -0
- package/dist/lib/module-index.js +103 -0
- package/dist/lib/module-index.js.map +7 -0
- package/dist/lib/testing/integration-discovery.js +20 -15
- package/dist/lib/testing/integration-discovery.js.map +3 -3
- package/dist/mercato.js +19 -2
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/__tests__/rotation-json-output.test.ts +13 -0
- package/src/lib/__tests__/module-diagnostics.test.ts +207 -0
- package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +2 -2
- package/src/lib/generators/__tests__/output-snapshots.test.ts +19 -0
- package/src/lib/generators/__tests__/structural-contracts.test.ts +18 -0
- package/src/lib/generators/extensions/dashboard-widgets.ts +49 -3
- package/src/lib/generators/extensions/workflows.ts +26 -2
- package/src/lib/generators/module-facts.ts +2 -0
- package/src/lib/generators/module-registry.ts +11 -7
- package/src/lib/module-coupling/analyze.ts +464 -0
- package/src/lib/module-diagnostics.ts +182 -0
- package/src/lib/module-index.ts +133 -0
- package/src/lib/testing/__tests__/integration-discovery.test.ts +26 -2
- package/src/lib/testing/integration-discovery.ts +19 -11
- package/src/mercato.ts +21 -2
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import ts from "typescript-js";
|
|
4
|
+
import { resolveModuleRequirement } from "@open-mercato/shared/modules/module-locators";
|
|
5
|
+
import { extractModuleFacts } from "../generators/module-facts.js";
|
|
6
|
+
import { resolveIndexedModule } from "../module-index.js";
|
|
7
|
+
import { resolveModuleDependenciesForSpec } from "../testing/integration-discovery.js";
|
|
8
|
+
const PLATFORM_KERNEL = ["auth", "directory", "api_keys"];
|
|
9
|
+
const kernel = new Set(PLATFORM_KERNEL);
|
|
10
|
+
const excludedDirectories = /* @__PURE__ */ new Set(["__tests__", "__mocks__", "__benchmarks__", "migrations", "i18n", "node_modules"]);
|
|
11
|
+
const testsOrGenerated = /(?:\.(?:test|generated|d)\.[cm]?[jt]sx?)$/;
|
|
12
|
+
function walkFiles(directory) {
|
|
13
|
+
if (!fs.existsSync(directory)) return [];
|
|
14
|
+
const files = [];
|
|
15
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
16
|
+
if (excludedDirectories.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
17
|
+
const fullPath = path.join(directory, entry.name);
|
|
18
|
+
if (entry.isDirectory()) files.push(...walkFiles(fullPath));
|
|
19
|
+
else if (/\.[cm]?[jt]sx?$/.test(entry.name) && !testsOrGenerated.test(entry.name)) files.push(fullPath);
|
|
20
|
+
}
|
|
21
|
+
return files;
|
|
22
|
+
}
|
|
23
|
+
function literalValue(node) {
|
|
24
|
+
return node && ts.isStringLiteralLike(node) ? node.text : void 0;
|
|
25
|
+
}
|
|
26
|
+
function fileName(root, file) {
|
|
27
|
+
return path.relative(root, file).split(path.sep).join("/");
|
|
28
|
+
}
|
|
29
|
+
function readFiles(roots) {
|
|
30
|
+
const files = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const root of roots) {
|
|
32
|
+
for (const absolute of walkFiles(root)) {
|
|
33
|
+
const relative = fileName(root, absolute);
|
|
34
|
+
const identity = relative.replace(/\.[cm]?[jt]sx?$/, "");
|
|
35
|
+
if (files.has(identity)) continue;
|
|
36
|
+
const text = fs.readFileSync(absolute, "utf8");
|
|
37
|
+
files.set(identity, { relative, absolute, source: ts.createSourceFile(absolute, text, ts.ScriptTarget.Latest, true) });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return [...files.values()].sort((left, right) => left.relative.localeCompare(right.relative));
|
|
41
|
+
}
|
|
42
|
+
function asApiPath(route) {
|
|
43
|
+
const pathname = route.startsWith("/") ? route : `/${route}`;
|
|
44
|
+
return pathname.startsWith("/api/") ? pathname : `/api${pathname}`;
|
|
45
|
+
}
|
|
46
|
+
function staticApiRoute(file, moduleId) {
|
|
47
|
+
if (!file.relative.startsWith("api/") || file.relative.includes("/__integration__/")) return void 0;
|
|
48
|
+
const handlers = /* @__PURE__ */ new Set(["get", "post", "put", "patch", "delete", "head", "options"]);
|
|
49
|
+
const segments = file.relative.replace(/\.[cm]?[jt]sx?$/, "").split("/").slice(1);
|
|
50
|
+
const first = segments[0];
|
|
51
|
+
const isConventionalRoute = segments.at(-1) === "route";
|
|
52
|
+
if (isConventionalRoute) segments.pop();
|
|
53
|
+
else if (first && handlers.has(first.toLowerCase())) segments.shift();
|
|
54
|
+
else return void 0;
|
|
55
|
+
for (const statement of file.source.statements) {
|
|
56
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
57
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
58
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== "metadata" || !declaration.initializer || !ts.isObjectLiteralExpression(declaration.initializer)) continue;
|
|
59
|
+
for (const property of declaration.initializer.properties) {
|
|
60
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
61
|
+
const name = propertyText(property.name);
|
|
62
|
+
const value = literalValue(property.initializer);
|
|
63
|
+
if (name === "path" && value) return asApiPath(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return asApiPath([moduleId, ...segments].join("/"));
|
|
68
|
+
}
|
|
69
|
+
function analyzeModule(entry) {
|
|
70
|
+
const files = readFiles(entry.roots);
|
|
71
|
+
const features = /* @__PURE__ */ new Set();
|
|
72
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
73
|
+
const api = /* @__PURE__ */ new Set();
|
|
74
|
+
const pages = /* @__PURE__ */ new Set();
|
|
75
|
+
let contributions;
|
|
76
|
+
for (const moduleRoot of entry.roots) {
|
|
77
|
+
const facts = extractModuleFacts({ moduleId: entry.id, moduleRoot, sourcePackage: entry.packageName === "@app" ? null : entry.packageName });
|
|
78
|
+
facts.aclFeatures.forEach((feature) => features.add(feature));
|
|
79
|
+
facts.diTokens.forEach((token) => tokens.add(token));
|
|
80
|
+
facts.apiRoutes.forEach((route) => api.add(asApiPath(route.path)));
|
|
81
|
+
facts.backendPages.forEach((page) => pages.add(page.path));
|
|
82
|
+
if (!contributions) contributions = facts.extensionSurfaces;
|
|
83
|
+
else if (facts.extensionSurfaces) {
|
|
84
|
+
contributions = {
|
|
85
|
+
hosts: [...contributions.hosts, ...facts.extensionSurfaces.hosts],
|
|
86
|
+
contributions: [...contributions.contributions, ...facts.extensionSurfaces.contributions],
|
|
87
|
+
unresolved: [...contributions.unresolved, ...facts.extensionSurfaces.unresolved]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
const route = staticApiRoute(file, entry.id);
|
|
93
|
+
if (route) api.add(route);
|
|
94
|
+
}
|
|
95
|
+
return { entry, files, features, tokens, api, pages, contributions };
|
|
96
|
+
}
|
|
97
|
+
function propertyText(name) {
|
|
98
|
+
return ts.isIdentifier(name) ? name.text : literalValue(name);
|
|
99
|
+
}
|
|
100
|
+
function callName(expression) {
|
|
101
|
+
return ts.isIdentifier(expression) ? expression.text : ts.isPropertyAccessExpression(expression) ? expression.name.text : void 0;
|
|
102
|
+
}
|
|
103
|
+
function lineOf(file, node) {
|
|
104
|
+
return file.source.getLineAndCharacterOfPosition(node.getStart(file.source)).line + 1;
|
|
105
|
+
}
|
|
106
|
+
function isValueImport(node) {
|
|
107
|
+
if (!node.importClause) return true;
|
|
108
|
+
const { isTypeOnly, name, namedBindings } = node.importClause;
|
|
109
|
+
if (isTypeOnly) return false;
|
|
110
|
+
return !!name || !namedBindings || !ts.isNamedImports(namedBindings) || namedBindings.elements.some((item) => !item.isTypeOnly);
|
|
111
|
+
}
|
|
112
|
+
function parseFileReferences(file) {
|
|
113
|
+
const results = [];
|
|
114
|
+
const featureProperties = /* @__PURE__ */ new Set(["requireFeatures", "requireCustomerFeatures", "features", "requiredFeatures"]);
|
|
115
|
+
function add(kind, node, value, partial = false) {
|
|
116
|
+
if (node && value) results.push({ kind, value, file: file.absolute, line: lineOf(file, node), partial });
|
|
117
|
+
}
|
|
118
|
+
function visit(node) {
|
|
119
|
+
if (ts.isImportDeclaration(node) && isValueImport(node)) {
|
|
120
|
+
add("import", node.moduleSpecifier, literalValue(node.moduleSpecifier));
|
|
121
|
+
} else if (ts.isExportDeclaration(node) && !node.isTypeOnly && !(node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.every((item) => item.isTypeOnly))) {
|
|
122
|
+
add("import", node.moduleSpecifier, literalValue(node.moduleSpecifier));
|
|
123
|
+
} else if (ts.isCallExpression(node)) {
|
|
124
|
+
const name = callName(node.expression);
|
|
125
|
+
const arg = node.arguments[0];
|
|
126
|
+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword || name === "require") {
|
|
127
|
+
add("import", arg, literalValue(arg));
|
|
128
|
+
} else if (name === "resolve" || name === "hasRegistration") {
|
|
129
|
+
add("di-token", arg, literalValue(arg));
|
|
130
|
+
} else if (name === "hasFeature") {
|
|
131
|
+
const feature = node.arguments[1];
|
|
132
|
+
add("feature", feature, literalValue(feature));
|
|
133
|
+
}
|
|
134
|
+
} else if (ts.isPropertyAssignment(node) && featureProperties.has(propertyText(node.name) ?? "") && ts.isArrayLiteralExpression(node.initializer)) {
|
|
135
|
+
for (const value of node.initializer.elements) add("feature", value, literalValue(value));
|
|
136
|
+
} else if (ts.isStringLiteralLike(node) || ts.isTemplateExpression(node)) {
|
|
137
|
+
const value = ts.isTemplateExpression(node) ? node.head.text : node.text;
|
|
138
|
+
const kind = value.startsWith("/api/") ? "api-path" : value.startsWith("/backend/") ? "page-path" : void 0;
|
|
139
|
+
if (kind) add(kind, node, value, ts.isTemplateExpression(node));
|
|
140
|
+
}
|
|
141
|
+
ts.forEachChild(node, visit);
|
|
142
|
+
}
|
|
143
|
+
visit(file.source);
|
|
144
|
+
return results;
|
|
145
|
+
}
|
|
146
|
+
function escapeRegExp(value) {
|
|
147
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
148
|
+
}
|
|
149
|
+
function routeOwner(route, owner) {
|
|
150
|
+
const segments = route.split("/").filter(Boolean);
|
|
151
|
+
const dynamic = (segment) => segment.startsWith("[") || segment.startsWith(":") || segment.startsWith("{");
|
|
152
|
+
const pattern = segments.map((segment) => segment.includes("...") || segment.startsWith("[[...") ? ".+" : dynamic(segment) ? "[^/]+" : escapeRegExp(segment));
|
|
153
|
+
return { route, owner, exact: !segments.some(dynamic), pattern: new RegExp(`^/${pattern.join("/")}/?$`) };
|
|
154
|
+
}
|
|
155
|
+
function routeModule(reference, routes) {
|
|
156
|
+
const requestPath = reference.value.split(/[?#]/)[0];
|
|
157
|
+
if (!reference.partial) {
|
|
158
|
+
return routes.find((route) => route.exact && route.route === requestPath)?.owner ?? routes.find((route) => route.pattern.test(requestPath))?.owner;
|
|
159
|
+
}
|
|
160
|
+
const prefix = requestPath.endsWith("/") ? requestPath : `${requestPath}/`;
|
|
161
|
+
const owners = new Set(routes.filter((route) => route.route.startsWith(prefix)).map((route) => route.owner));
|
|
162
|
+
return owners.size === 1 ? [...owners][0] : void 0;
|
|
163
|
+
}
|
|
164
|
+
function importModule(reference, roots, sourcePackage) {
|
|
165
|
+
if (reference.value.startsWith("@open-mercato/shared/modules/")) return void 0;
|
|
166
|
+
const direct = reference.value.match(/^(?:@[^/]+\/[^/]+\/modules|@\/modules)\/([a-z0-9_]+)(?:\/|$)/);
|
|
167
|
+
if (direct) return direct[1];
|
|
168
|
+
const samePackage = reference.value.startsWith(`${sourcePackage}/modules/`) ? reference.value.slice(sourcePackage.length + "/modules/".length).split("/")[0] : void 0;
|
|
169
|
+
if (samePackage) return samePackage;
|
|
170
|
+
if (!reference.value.startsWith(".")) return void 0;
|
|
171
|
+
let current = path.resolve(path.dirname(reference.file), reference.value);
|
|
172
|
+
while (current !== path.dirname(current)) {
|
|
173
|
+
const owner = roots.get(current);
|
|
174
|
+
if (owner) return owner;
|
|
175
|
+
current = path.dirname(current);
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
function closure(entry, modules, includeOptional) {
|
|
180
|
+
const reached = /* @__PURE__ */ new Set();
|
|
181
|
+
const visited = /* @__PURE__ */ new Set([entry.id]);
|
|
182
|
+
const pending = [entry];
|
|
183
|
+
while (pending.length > 0) {
|
|
184
|
+
const source = pending.pop();
|
|
185
|
+
if (!source) continue;
|
|
186
|
+
const requirements = includeOptional ? [...source.requires, ...source.optionalRequires] : source.requires;
|
|
187
|
+
for (const requirement of requirements) {
|
|
188
|
+
const target = resolveIndexedModule(requirement, modules);
|
|
189
|
+
reached.add(target?.id ?? requirement);
|
|
190
|
+
if (!target || visited.has(target.id)) continue;
|
|
191
|
+
visited.add(target.id);
|
|
192
|
+
pending.push(target);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return reached;
|
|
196
|
+
}
|
|
197
|
+
function guardEvidence(file, target, features, tokens, reference) {
|
|
198
|
+
const client = file.source.statements.some((statement) => ts.isExpressionStatement(statement) && literalValue(statement.expression) === "use client");
|
|
199
|
+
let evidence = false;
|
|
200
|
+
function visit(node) {
|
|
201
|
+
if (evidence) return;
|
|
202
|
+
if (ts.isCallExpression(node)) {
|
|
203
|
+
const name = callName(node.expression);
|
|
204
|
+
const argument = literalValue(node.arguments[0]);
|
|
205
|
+
const moduleGuard = name === "isClientModuleEnabled" || (client ? name === "useModuleEnabled" : name === "isModuleEnabled");
|
|
206
|
+
if (moduleGuard && argument === target) evidence = true;
|
|
207
|
+
if (name === "hasRegistration" && argument && tokens.has(argument)) evidence = true;
|
|
208
|
+
const feature = literalValue(node.arguments[1]);
|
|
209
|
+
if (name === "hasFeature" && feature && features.has(feature)) evidence = true;
|
|
210
|
+
if (name === "resolve" && reference.kind === "di-token" && argument === reference.value) {
|
|
211
|
+
const options = node.arguments[1];
|
|
212
|
+
if (options && ts.isObjectLiteralExpression(options) && options.properties.some((property) => ts.isPropertyAssignment(property) && propertyText(property.name) === "allowUnregistered" && property.initializer.kind === ts.SyntaxKind.TrueKeyword)) evidence = true;
|
|
213
|
+
for (let parent = node; parent; parent = parent.parent) {
|
|
214
|
+
if (ts.isTryStatement(parent) && parent.catchClause && node.getStart(file.source) < parent.tryBlock.end) evidence = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (ts.isPropertyAssignment(node) && ts.isArrayLiteralExpression(node.initializer)) {
|
|
219
|
+
const key = propertyText(node.name);
|
|
220
|
+
for (const entry of node.initializer.elements) {
|
|
221
|
+
const value = literalValue(entry);
|
|
222
|
+
if (key === "requiredModules" && value === target) evidence = true;
|
|
223
|
+
if ((key === "requiredFeatures" || key === "requireFeatures" || key === "features") && value && features.has(value)) evidence = true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
ts.forEachChild(node, visit);
|
|
227
|
+
}
|
|
228
|
+
visit(file.source);
|
|
229
|
+
return evidence;
|
|
230
|
+
}
|
|
231
|
+
function optionalCapabilityLabel(entry, target) {
|
|
232
|
+
const key = `optionalRequires.${target}`;
|
|
233
|
+
for (const root of entry.roots) {
|
|
234
|
+
const english = path.join(root, "i18n", "en.json");
|
|
235
|
+
try {
|
|
236
|
+
const text = JSON.parse(fs.readFileSync(english, "utf8"));
|
|
237
|
+
const value = text[`${entry.id}.${key}`] ?? text[key];
|
|
238
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
function readWidgetModuleRequirements(files) {
|
|
245
|
+
const requirements = /* @__PURE__ */ new Map();
|
|
246
|
+
for (const file of files) {
|
|
247
|
+
let visit2 = function(node) {
|
|
248
|
+
if (ts.isPropertyAssignment(node) && propertyText(node.name) === "metadata" && ts.isObjectLiteralExpression(node.initializer)) {
|
|
249
|
+
const metadata = node.initializer.properties.filter(ts.isPropertyAssignment);
|
|
250
|
+
const id = literalValue(metadata.find((entry) => propertyText(entry.name) === "id")?.initializer);
|
|
251
|
+
const dependencies = metadata.find((entry) => propertyText(entry.name) === "requiredModules")?.initializer;
|
|
252
|
+
if (id && dependencies && ts.isArrayLiteralExpression(dependencies)) {
|
|
253
|
+
requirements.set(id, dependencies.elements.map(literalValue).filter((value) => !!value));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
ts.forEachChild(node, visit2);
|
|
257
|
+
};
|
|
258
|
+
var visit = visit2;
|
|
259
|
+
if (!file.relative.startsWith("widgets/injection/")) continue;
|
|
260
|
+
visit2(file.source);
|
|
261
|
+
}
|
|
262
|
+
return requirements;
|
|
263
|
+
}
|
|
264
|
+
function hostContributions(modules, enabledIds) {
|
|
265
|
+
const result = [];
|
|
266
|
+
const candidates = modules.filter((module) => enabledIds.has(module.entry.id)).map((module) => ({
|
|
267
|
+
contributions: module.contributions?.contributions ?? [],
|
|
268
|
+
requirements: readWidgetModuleRequirements(module.files)
|
|
269
|
+
}));
|
|
270
|
+
for (const module of modules) {
|
|
271
|
+
let visit2 = function(node) {
|
|
272
|
+
if (ts.isCallExpression(node) && callName(node.expression) === "injectionExtensionHost" && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
273
|
+
const host = node.arguments[0];
|
|
274
|
+
const spot = host.properties.find((item) => ts.isPropertyAssignment(item) && propertyText(item.name) === "spotId");
|
|
275
|
+
const min = host.properties.find((item) => ts.isPropertyAssignment(item) && propertyText(item.name) === "minContributions");
|
|
276
|
+
const spotId = spot ? literalValue(spot.initializer) : void 0;
|
|
277
|
+
if (spotId && min && ts.isNumericLiteral(min.initializer)) {
|
|
278
|
+
const minimum = Number(min.initializer.text);
|
|
279
|
+
const suffix = `@${spotId}`;
|
|
280
|
+
const count = candidates.reduce((total, { contributions, requirements }) => total + contributions.filter((contribution) => {
|
|
281
|
+
if (!("targets" in contribution) || !contribution.id.endsWith(suffix)) return false;
|
|
282
|
+
const widgetId = contribution.id.slice(0, -suffix.length);
|
|
283
|
+
return requirements.get(widgetId)?.every((id) => enabledIds.has(id)) ?? true;
|
|
284
|
+
}).length, 0);
|
|
285
|
+
if (count < minimum) result.push({ module: module.entry.id, spotId, minimum, count, file: file.absolute, line: lineOf(file, node) });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
ts.forEachChild(node, visit2);
|
|
289
|
+
};
|
|
290
|
+
var visit = visit2;
|
|
291
|
+
if (!enabledIds.has(module.entry.id)) continue;
|
|
292
|
+
const declaration = module.files.find((file2) => /^extension-points\.[cm]?[jt]sx?$/.test(file2.relative));
|
|
293
|
+
if (!declaration) continue;
|
|
294
|
+
const file = declaration;
|
|
295
|
+
visit2(declaration.source);
|
|
296
|
+
}
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
function findMissingModuleContributions(entries) {
|
|
300
|
+
const enabled = entries.filter((entry) => entry.enabled);
|
|
301
|
+
return hostContributions(enabled.map(analyzeModule), new Set(enabled.map((entry) => entry.id)));
|
|
302
|
+
}
|
|
303
|
+
function analyzeModuleCoupling(entries, analyzedModuleIds = new Set(entries.filter((entry) => entry.enabled).map((entry) => entry.id))) {
|
|
304
|
+
const modules = /* @__PURE__ */ new Map();
|
|
305
|
+
const roots = /* @__PURE__ */ new Map();
|
|
306
|
+
const api = [];
|
|
307
|
+
const pages = [];
|
|
308
|
+
const features = /* @__PURE__ */ new Map();
|
|
309
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
310
|
+
const hostOwners = /* @__PURE__ */ new Map();
|
|
311
|
+
for (const entry of [...entries.filter((item) => item.enabled), ...entries.filter((item) => !item.enabled)]) {
|
|
312
|
+
if (modules.has(entry.id)) continue;
|
|
313
|
+
const analyzed = analyzeModule(entry);
|
|
314
|
+
modules.set(entry.id, analyzed);
|
|
315
|
+
entry.roots.forEach((root) => roots.set(root, entry.id));
|
|
316
|
+
analyzed.api.forEach((route) => api.push(routeOwner(route, entry.id)));
|
|
317
|
+
analyzed.pages.forEach((route) => pages.push(routeOwner(route, entry.id)));
|
|
318
|
+
analyzed.contributions?.hosts.forEach((host) => hostOwners.set(host.id, host.ownerModule));
|
|
319
|
+
analyzed.features.forEach((feature) => {
|
|
320
|
+
if (!features.has(feature)) features.set(feature, entry.id);
|
|
321
|
+
});
|
|
322
|
+
analyzed.tokens.forEach((token) => {
|
|
323
|
+
if (!tokens.has(token)) tokens.set(token, entry.id);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
const hard = new Map([...modules.values()].map(({ entry }) => [entry.id, closure(entry, entries, false)]));
|
|
327
|
+
const dependencies = new Map([...modules.values()].map(({ entry }) => [entry.id, closure(entry, entries, true)]));
|
|
328
|
+
const findings = [];
|
|
329
|
+
const dangling = [];
|
|
330
|
+
for (const [module, analyzed] of modules) {
|
|
331
|
+
if (!analyzedModuleIds.has(module)) continue;
|
|
332
|
+
const knownHard = hard.get(module);
|
|
333
|
+
const optional = new Set(analyzed.entry.optionalRequires.map((requirement) => resolveModuleRequirement(requirement, entries) ?? requirement));
|
|
334
|
+
for (const target of optional) {
|
|
335
|
+
const index = analyzed.files.find((file) => /^index\.[cm]?[jt]sx?$/.test(file.relative));
|
|
336
|
+
if (index && !optionalCapabilityLabel(analyzed.entry, target)) {
|
|
337
|
+
findings.push({ rule: "R1", module, target, file: index.absolute, message: `Missing English capability label for optional module '${target}'` });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
for (const file of analyzed.files) {
|
|
341
|
+
const integration = file.relative.split("/").includes("__integration__");
|
|
342
|
+
if (integration && !file.relative.endsWith(".spec.ts")) continue;
|
|
343
|
+
const moduleRoot = integration ? analyzed.entry.roots.find((root) => path.join(root, file.relative) === file.absolute) : void 0;
|
|
344
|
+
const testDependencies = moduleRoot ? new Set(resolveModuleDependenciesForSpec(moduleRoot, file.relative, { includeOptional: true })) : void 0;
|
|
345
|
+
const fileContributions = analyzed.contributions?.contributions.filter((item) => "source" in item && item.source.path.endsWith(`/${file.relative}`)) ?? [];
|
|
346
|
+
const structural = new Set(fileContributions.flatMap((item) => "targets" in item ? item.targets.map((target) => hostOwners.get(target.id)).filter((owner) => !!owner) : []));
|
|
347
|
+
const providesDashboardWidget = fileContributions.some((item) => item.kind === "widget" && item.details.payload === "dashboard");
|
|
348
|
+
const providesInboxActions = /^inbox-actions\.[cm]?[jt]s$/.test(file.relative) && file.source.statements.some((statement) => ts.isExportAssignment(statement));
|
|
349
|
+
for (const reference of parseFileReferences(file)) {
|
|
350
|
+
if (integration && reference.kind === "import" && reference.value.startsWith("@open-mercato/core/modules/core/__integration__/")) continue;
|
|
351
|
+
const target = reference.kind === "import" ? importModule(reference, roots, analyzed.entry.packageName) : reference.kind === "api-path" ? routeModule(reference, api) : reference.kind === "page-path" ? routeModule(reference, pages) : reference.kind === "feature" ? features.get(reference.value) : tokens.get(reference.value);
|
|
352
|
+
if (providesDashboardWidget && target === "dashboards" && reference.kind === "feature" && reference.value === "analytics.view") continue;
|
|
353
|
+
if (providesInboxActions && target === "inbox_ops" && reference.kind === "import") continue;
|
|
354
|
+
if (!target) {
|
|
355
|
+
if (!integration && (reference.kind === "api-path" || reference.kind === "page-path") && !reference.partial) {
|
|
356
|
+
dangling.push({ ...reference, module });
|
|
357
|
+
}
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (target === module || structural.has(target)) continue;
|
|
361
|
+
const context = { module, target, file: file.absolute, line: reference.line, kind: reference.kind };
|
|
362
|
+
if (integration) {
|
|
363
|
+
if (!kernel.has(target) && !knownHard?.has(target) && !testDependencies?.has(target)) {
|
|
364
|
+
findings.push({ ...context, rule: "R4", message: `Integration spec must declare dependsOnModules: ['${target}']` });
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (!kernel.has(target) && !knownHard?.has(target) && !optional.has(target)) {
|
|
369
|
+
findings.push({ ...context, rule: "R1", message: `'${module}' references '${target}' without a dependency declaration` });
|
|
370
|
+
}
|
|
371
|
+
if (optional.has(target)) {
|
|
372
|
+
const peer = modules.get(target);
|
|
373
|
+
if (!guardEvidence(file, target, peer?.features ?? /* @__PURE__ */ new Set(), peer?.tokens ?? /* @__PURE__ */ new Set(), reference)) {
|
|
374
|
+
findings.push({ ...context, rule: "R2", message: `Optional reference to '${target}' has no module guard` });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (!(kernel.has(module) && kernel.has(target)) && dependencies.get(target)?.has(module)) {
|
|
378
|
+
findings.push({ ...context, rule: "R5", message: `'${module}' references its consumer '${target}'` });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return { findings, dangling, contributions: hostContributions([...modules.values()], new Set(analyzedModuleIds)) };
|
|
384
|
+
}
|
|
385
|
+
export {
|
|
386
|
+
PLATFORM_KERNEL,
|
|
387
|
+
analyzeModuleCoupling,
|
|
388
|
+
findMissingModuleContributions,
|
|
389
|
+
optionalCapabilityLabel
|
|
390
|
+
};
|
|
391
|
+
//# sourceMappingURL=analyze.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/module-coupling/analyze.ts"],
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport ts from 'typescript-js'\nimport { resolveModuleRequirement } from '@open-mercato/shared/modules/module-locators'\nimport { extractModuleFacts } from '../generators/module-facts'\nimport { resolveIndexedModule, type IndexedModule } from '../module-index'\nimport { resolveModuleDependenciesForSpec } from '../testing/integration-discovery'\n\nexport const PLATFORM_KERNEL = ['auth', 'directory', 'api_keys'] as const\nconst kernel = new Set<string>(PLATFORM_KERNEL)\nconst excludedDirectories = new Set(['__tests__', '__mocks__', '__benchmarks__', 'migrations', 'i18n', 'node_modules'])\nconst testsOrGenerated = /(?:\\.(?:test|generated|d)\\.[cm]?[jt]sx?)$/\n\nexport type CouplingRule = 'R1' | 'R2' | 'R4' | 'R5'\ntype ReferenceKind = 'import' | 'api-path' | 'page-path' | 'feature' | 'di-token'\ntype Reference = { kind: ReferenceKind; value: string; file: string; line: number; partial: boolean }\nexport type CouplingFinding = {\n rule: CouplingRule\n module: string\n target: string\n message: string\n kind?: ReferenceKind\n file: string\n line?: number\n}\nexport type DanglingReference = Reference & { module: string }\nexport type MissingContribution = { module: string; spotId: string; minimum: number; count: number; file: string; line: number }\nexport type CouplingReport = {\n findings: CouplingFinding[]\n dangling: DanglingReference[]\n contributions: MissingContribution[]\n}\n\ntype ParsedFile = { relative: string; absolute: string; source: ts.SourceFile }\ntype AnalyzedModule = {\n entry: IndexedModule\n files: ParsedFile[]\n features: Set<string>\n tokens: Set<string>\n api: Set<string>\n pages: Set<string>\n contributions: ReturnType<typeof extractModuleFacts>['extensionSurfaces']\n}\ntype RouteOwner = { route: string; owner: string; exact: boolean; pattern: RegExp }\n\nfunction walkFiles(directory: string): string[] {\n if (!fs.existsSync(directory)) return []\n const files: string[] = []\n for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {\n if (excludedDirectories.has(entry.name) || entry.name.startsWith('.')) continue\n const fullPath = path.join(directory, entry.name)\n if (entry.isDirectory()) files.push(...walkFiles(fullPath))\n else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !testsOrGenerated.test(entry.name)) files.push(fullPath)\n }\n return files\n}\n\nfunction literalValue(node: ts.Node | undefined): string | undefined {\n return node && ts.isStringLiteralLike(node) ? node.text : undefined\n}\n\nfunction fileName(root: string, file: string): string {\n return path.relative(root, file).split(path.sep).join('/')\n}\n\nfunction readFiles(roots: string[]): ParsedFile[] {\n const files = new Map<string, ParsedFile>()\n for (const root of roots) {\n for (const absolute of walkFiles(root)) {\n const relative = fileName(root, absolute)\n const identity = relative.replace(/\\.[cm]?[jt]sx?$/, '')\n if (files.has(identity)) continue\n const text = fs.readFileSync(absolute, 'utf8')\n files.set(identity, { relative, absolute, source: ts.createSourceFile(absolute, text, ts.ScriptTarget.Latest, true) })\n }\n }\n return [...files.values()].sort((left, right) => left.relative.localeCompare(right.relative))\n}\n\nfunction asApiPath(route: string): string {\n const pathname = route.startsWith('/') ? route : `/${route}`\n return pathname.startsWith('/api/') ? pathname : `/api${pathname}`\n}\n\nfunction staticApiRoute(file: ParsedFile, moduleId: string): string | undefined {\n if (!file.relative.startsWith('api/') || file.relative.includes('/__integration__/')) return undefined\n const handlers = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'options'])\n const segments = file.relative.replace(/\\.[cm]?[jt]sx?$/, '').split('/').slice(1)\n const first = segments[0]\n const isConventionalRoute = segments.at(-1) === 'route'\n if (isConventionalRoute) segments.pop()\n else if (first && handlers.has(first.toLowerCase())) segments.shift()\n else return undefined\n for (const statement of file.source.statements) {\n if (!ts.isVariableStatement(statement)) continue\n for (const declaration of statement.declarationList.declarations) {\n if (!ts.isIdentifier(declaration.name) || declaration.name.text !== 'metadata' || !declaration.initializer\n || !ts.isObjectLiteralExpression(declaration.initializer)) continue\n for (const property of declaration.initializer.properties) {\n if (!ts.isPropertyAssignment(property)) continue\n const name = propertyText(property.name)\n const value = literalValue(property.initializer)\n if (name === 'path' && value) return asApiPath(value)\n }\n }\n }\n return asApiPath([moduleId, ...segments].join('/'))\n}\n\nfunction analyzeModule(entry: IndexedModule): AnalyzedModule {\n const files = readFiles(entry.roots)\n const features = new Set<string>()\n const tokens = new Set<string>()\n const api = new Set<string>()\n const pages = new Set<string>()\n let contributions: AnalyzedModule['contributions']\n for (const moduleRoot of entry.roots) {\n const facts = extractModuleFacts({ moduleId: entry.id, moduleRoot, sourcePackage: entry.packageName === '@app' ? null : entry.packageName })\n facts.aclFeatures.forEach((feature) => features.add(feature))\n facts.diTokens.forEach((token) => tokens.add(token))\n facts.apiRoutes.forEach((route) => api.add(asApiPath(route.path)))\n facts.backendPages.forEach((page) => pages.add(page.path))\n if (!contributions) contributions = facts.extensionSurfaces\n else if (facts.extensionSurfaces) {\n contributions = {\n hosts: [...contributions.hosts, ...facts.extensionSurfaces.hosts],\n contributions: [...contributions.contributions, ...facts.extensionSurfaces.contributions],\n unresolved: [...contributions.unresolved, ...facts.extensionSurfaces.unresolved],\n }\n }\n }\n for (const file of files) {\n const route = staticApiRoute(file, entry.id)\n if (route) api.add(route)\n }\n return { entry, files, features, tokens, api, pages, contributions }\n}\n\nfunction propertyText(name: ts.PropertyName): string | undefined {\n return ts.isIdentifier(name) ? name.text : literalValue(name)\n}\n\nfunction callName(expression: ts.Expression): string | undefined {\n return ts.isIdentifier(expression) ? expression.text : ts.isPropertyAccessExpression(expression) ? expression.name.text : undefined\n}\n\nfunction lineOf(file: ParsedFile, node: ts.Node): number {\n return file.source.getLineAndCharacterOfPosition(node.getStart(file.source)).line + 1\n}\n\nfunction isValueImport(node: ts.ImportDeclaration): boolean {\n if (!node.importClause) return true\n const { isTypeOnly, name, namedBindings } = node.importClause\n if (isTypeOnly) return false\n return !!name || !namedBindings || !ts.isNamedImports(namedBindings) || namedBindings.elements.some((item) => !item.isTypeOnly)\n}\n\nfunction parseFileReferences(file: ParsedFile): Reference[] {\n const results: Reference[] = []\n const featureProperties = new Set(['requireFeatures', 'requireCustomerFeatures', 'features', 'requiredFeatures'])\n function add(kind: ReferenceKind, node: ts.Node | undefined, value: string | undefined, partial = false): void {\n if (node && value) results.push({ kind, value, file: file.absolute, line: lineOf(file, node), partial })\n }\n function visit(node: ts.Node): void {\n if (ts.isImportDeclaration(node) && isValueImport(node)) {\n add('import', node.moduleSpecifier, literalValue(node.moduleSpecifier))\n } else if (ts.isExportDeclaration(node) && !node.isTypeOnly\n && !(node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.every((item) => item.isTypeOnly))) {\n add('import', node.moduleSpecifier, literalValue(node.moduleSpecifier))\n } else if (ts.isCallExpression(node)) {\n const name = callName(node.expression)\n const arg = node.arguments[0]\n if (node.expression.kind === ts.SyntaxKind.ImportKeyword || name === 'require') {\n add('import', arg, literalValue(arg))\n } else if (name === 'resolve' || name === 'hasRegistration') {\n add('di-token', arg, literalValue(arg))\n } else if (name === 'hasFeature') {\n const feature = node.arguments[1]\n add('feature', feature, literalValue(feature))\n }\n } else if (ts.isPropertyAssignment(node) && featureProperties.has(propertyText(node.name) ?? '')\n && ts.isArrayLiteralExpression(node.initializer)) {\n for (const value of node.initializer.elements) add('feature', value, literalValue(value))\n } else if (ts.isStringLiteralLike(node) || ts.isTemplateExpression(node)) {\n const value = ts.isTemplateExpression(node) ? node.head.text : node.text\n const kind = value.startsWith('/api/') ? 'api-path' : value.startsWith('/backend/') ? 'page-path' : undefined\n if (kind) add(kind, node, value, ts.isTemplateExpression(node))\n }\n ts.forEachChild(node, visit)\n }\n visit(file.source)\n return results\n}\n\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nfunction routeOwner(route: string, owner: string): RouteOwner {\n const segments = route.split('/').filter(Boolean)\n const dynamic = (segment: string): boolean => segment.startsWith('[') || segment.startsWith(':') || segment.startsWith('{')\n const pattern = segments.map((segment) => segment.includes('...') || segment.startsWith('[[...') ? '.+' : dynamic(segment) ? '[^/]+' : escapeRegExp(segment))\n return { route, owner, exact: !segments.some(dynamic), pattern: new RegExp(`^/${pattern.join('/')}/?$`) }\n}\n\nfunction routeModule(reference: Reference, routes: RouteOwner[]): string | undefined {\n const requestPath = reference.value.split(/[?#]/)[0]\n if (!reference.partial) {\n return routes.find((route) => route.exact && route.route === requestPath)?.owner\n ?? routes.find((route) => route.pattern.test(requestPath))?.owner\n }\n const prefix = requestPath.endsWith('/') ? requestPath : `${requestPath}/`\n const owners = new Set(routes.filter((route) => route.route.startsWith(prefix)).map((route) => route.owner))\n return owners.size === 1 ? [...owners][0] : undefined\n}\n\nfunction importModule(reference: Reference, roots: Map<string, string>, sourcePackage: string): string | undefined {\n if (reference.value.startsWith('@open-mercato/shared/modules/')) return undefined\n const direct = reference.value.match(/^(?:@[^/]+\\/[^/]+\\/modules|@\\/modules)\\/([a-z0-9_]+)(?:\\/|$)/)\n if (direct) return direct[1]\n const samePackage = reference.value.startsWith(`${sourcePackage}/modules/`)\n ? reference.value.slice(sourcePackage.length + '/modules/'.length).split('/')[0]\n : undefined\n if (samePackage) return samePackage\n if (!reference.value.startsWith('.')) return undefined\n let current = path.resolve(path.dirname(reference.file), reference.value)\n while (current !== path.dirname(current)) {\n const owner = roots.get(current)\n if (owner) return owner\n current = path.dirname(current)\n }\n return undefined\n}\n\nfunction closure(entry: IndexedModule, modules: IndexedModule[], includeOptional: boolean): Set<string> {\n const reached = new Set<string>()\n const visited = new Set([entry.id])\n const pending = [entry]\n while (pending.length > 0) {\n const source = pending.pop()\n if (!source) continue\n const requirements = includeOptional ? [...source.requires, ...source.optionalRequires] : source.requires\n for (const requirement of requirements) {\n const target = resolveIndexedModule(requirement, modules)\n reached.add(target?.id ?? requirement)\n if (!target || visited.has(target.id)) continue\n visited.add(target.id)\n pending.push(target)\n }\n }\n return reached\n}\n\nfunction guardEvidence(file: ParsedFile, target: string, features: Set<string>, tokens: Set<string>, reference: Reference): boolean {\n const client = file.source.statements.some((statement) =>\n ts.isExpressionStatement(statement) && literalValue(statement.expression) === 'use client')\n let evidence = false\n function visit(node: ts.Node): void {\n if (evidence) return\n if (ts.isCallExpression(node)) {\n const name = callName(node.expression)\n const argument = literalValue(node.arguments[0])\n const moduleGuard = name === 'isClientModuleEnabled'\n || (client ? name === 'useModuleEnabled' : name === 'isModuleEnabled')\n if (moduleGuard && argument === target) evidence = true\n if (name === 'hasRegistration' && argument && tokens.has(argument)) evidence = true\n const feature = literalValue(node.arguments[1])\n if (name === 'hasFeature' && feature && features.has(feature)) evidence = true\n if (name === 'resolve' && reference.kind === 'di-token' && argument === reference.value) {\n const options = node.arguments[1]\n if (options && ts.isObjectLiteralExpression(options) && options.properties.some((property) =>\n ts.isPropertyAssignment(property) && propertyText(property.name) === 'allowUnregistered'\n && property.initializer.kind === ts.SyntaxKind.TrueKeyword)) evidence = true\n for (let parent: ts.Node | undefined = node; parent; parent = parent.parent) {\n if (ts.isTryStatement(parent) && parent.catchClause && node.getStart(file.source) < parent.tryBlock.end) evidence = true\n }\n }\n }\n if (ts.isPropertyAssignment(node) && ts.isArrayLiteralExpression(node.initializer)) {\n const key = propertyText(node.name)\n for (const entry of node.initializer.elements) {\n const value = literalValue(entry)\n if (key === 'requiredModules' && value === target) evidence = true\n if ((key === 'requiredFeatures' || key === 'requireFeatures' || key === 'features') && value && features.has(value)) evidence = true\n }\n }\n ts.forEachChild(node, visit)\n }\n visit(file.source)\n return evidence\n}\n\nexport function optionalCapabilityLabel(entry: IndexedModule, target: string): string | undefined {\n const key = `optionalRequires.${target}`\n for (const root of entry.roots) {\n const english = path.join(root, 'i18n', 'en.json')\n try {\n const text: Record<string, unknown> = JSON.parse(fs.readFileSync(english, 'utf8'))\n const value = text[`${entry.id}.${key}`] ?? text[key]\n if (typeof value === 'string' && value.trim()) return value\n } catch {\n // Missing capability labels are reported as declaration findings.\n }\n }\n return undefined\n}\n\nfunction readWidgetModuleRequirements(files: ParsedFile[]): Map<string, string[]> {\n const requirements = new Map<string, string[]>()\n for (const file of files) {\n if (!file.relative.startsWith('widgets/injection/')) continue\n function visit(node: ts.Node): void {\n if (ts.isPropertyAssignment(node) && propertyText(node.name) === 'metadata' && ts.isObjectLiteralExpression(node.initializer)) {\n const metadata = node.initializer.properties.filter(ts.isPropertyAssignment)\n const id = literalValue(metadata.find((entry) => propertyText(entry.name) === 'id')?.initializer)\n const dependencies = metadata.find((entry) => propertyText(entry.name) === 'requiredModules')?.initializer\n if (id && dependencies && ts.isArrayLiteralExpression(dependencies)) {\n requirements.set(id, dependencies.elements.map(literalValue).filter((value): value is string => !!value))\n }\n }\n ts.forEachChild(node, visit)\n }\n visit(file.source)\n }\n return requirements\n}\n\nfunction hostContributions(modules: AnalyzedModule[], enabledIds: Set<string>): MissingContribution[] {\n const result: MissingContribution[] = []\n const candidates = modules.filter((module) => enabledIds.has(module.entry.id)).map((module) => ({\n contributions: module.contributions?.contributions ?? [],\n requirements: readWidgetModuleRequirements(module.files),\n }))\n for (const module of modules) {\n if (!enabledIds.has(module.entry.id)) continue\n const declaration = module.files.find((file) => /^extension-points\\.[cm]?[jt]sx?$/.test(file.relative))\n if (!declaration) continue\n const file = declaration\n function visit(node: ts.Node): void {\n if (ts.isCallExpression(node) && callName(node.expression) === 'injectionExtensionHost'\n && node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])) {\n const host = node.arguments[0]\n const spot = host.properties.find((item): item is ts.PropertyAssignment => ts.isPropertyAssignment(item) && propertyText(item.name) === 'spotId')\n const min = host.properties.find((item): item is ts.PropertyAssignment => ts.isPropertyAssignment(item) && propertyText(item.name) === 'minContributions')\n const spotId = spot ? literalValue(spot.initializer) : undefined\n if (spotId && min && ts.isNumericLiteral(min.initializer)) {\n const minimum = Number(min.initializer.text)\n const suffix = `@${spotId}`\n const count = candidates.reduce((total, { contributions, requirements }) => total + contributions.filter((contribution) => {\n if (!('targets' in contribution) || !contribution.id.endsWith(suffix)) return false\n const widgetId = contribution.id.slice(0, -suffix.length)\n return requirements.get(widgetId)?.every((id) => enabledIds.has(id)) ?? true\n }).length, 0)\n if (count < minimum) result.push({ module: module.entry.id, spotId, minimum, count, file: file.absolute, line: lineOf(file, node) })\n }\n }\n ts.forEachChild(node, visit)\n }\n visit(declaration.source)\n }\n return result\n}\n\nexport function findMissingModuleContributions(entries: IndexedModule[]): MissingContribution[] {\n const enabled = entries.filter((entry) => entry.enabled)\n return hostContributions(enabled.map(analyzeModule), new Set(enabled.map((entry) => entry.id)))\n}\n\nexport function analyzeModuleCoupling(\n entries: IndexedModule[],\n analyzedModuleIds: ReadonlySet<string> = new Set(entries.filter((entry) => entry.enabled).map((entry) => entry.id)),\n): CouplingReport {\n const modules = new Map<string, AnalyzedModule>()\n const roots = new Map<string, string>()\n const api: RouteOwner[] = []\n const pages: RouteOwner[] = []\n const features = new Map<string, string>()\n const tokens = new Map<string, string>()\n const hostOwners = new Map<string, string>()\n for (const entry of [...entries.filter((item) => item.enabled), ...entries.filter((item) => !item.enabled)]) {\n if (modules.has(entry.id)) continue\n const analyzed = analyzeModule(entry)\n modules.set(entry.id, analyzed)\n entry.roots.forEach((root) => roots.set(root, entry.id))\n analyzed.api.forEach((route) => api.push(routeOwner(route, entry.id)))\n analyzed.pages.forEach((route) => pages.push(routeOwner(route, entry.id)))\n analyzed.contributions?.hosts.forEach((host) => hostOwners.set(host.id, host.ownerModule))\n analyzed.features.forEach((feature) => { if (!features.has(feature)) features.set(feature, entry.id) })\n analyzed.tokens.forEach((token) => { if (!tokens.has(token)) tokens.set(token, entry.id) })\n }\n const hard = new Map([...modules.values()].map(({ entry }) => [entry.id, closure(entry, entries, false)]))\n const dependencies = new Map([...modules.values()].map(({ entry }) => [entry.id, closure(entry, entries, true)]))\n const findings: CouplingFinding[] = []\n const dangling: DanglingReference[] = []\n for (const [module, analyzed] of modules) {\n if (!analyzedModuleIds.has(module)) continue\n const knownHard = hard.get(module)\n const optional = new Set(analyzed.entry.optionalRequires.map((requirement) => resolveModuleRequirement(requirement, entries) ?? requirement))\n for (const target of optional) {\n const index = analyzed.files.find((file) => /^index\\.[cm]?[jt]sx?$/.test(file.relative))\n if (index && !optionalCapabilityLabel(analyzed.entry, target)) {\n findings.push({ rule: 'R1', module, target, file: index.absolute, message: `Missing English capability label for optional module '${target}'` })\n }\n }\n for (const file of analyzed.files) {\n const integration = file.relative.split('/').includes('__integration__')\n if (integration && !file.relative.endsWith('.spec.ts')) continue\n const moduleRoot = integration\n ? analyzed.entry.roots.find((root) => path.join(root, file.relative) === file.absolute)\n : undefined\n const testDependencies = moduleRoot\n ? new Set(resolveModuleDependenciesForSpec(moduleRoot, file.relative, { includeOptional: true }))\n : undefined\n const fileContributions = analyzed.contributions?.contributions.filter((item) =>\n 'source' in item && item.source.path.endsWith(`/${file.relative}`)) ?? []\n const structural = new Set(fileContributions.flatMap((item) =>\n 'targets' in item\n ? item.targets.map((target) => hostOwners.get(target.id)).filter((owner): owner is string => !!owner)\n : []))\n const providesDashboardWidget = fileContributions.some((item) =>\n item.kind === 'widget' && item.details.payload === 'dashboard')\n const providesInboxActions = /^inbox-actions\\.[cm]?[jt]s$/.test(file.relative)\n && file.source.statements.some((statement) => ts.isExportAssignment(statement))\n for (const reference of parseFileReferences(file)) {\n if (integration && reference.kind === 'import'\n && reference.value.startsWith('@open-mercato/core/modules/core/__integration__/')) continue\n const target = reference.kind === 'import' ? importModule(reference, roots, analyzed.entry.packageName)\n : reference.kind === 'api-path' ? routeModule(reference, api)\n : reference.kind === 'page-path' ? routeModule(reference, pages)\n : reference.kind === 'feature' ? features.get(reference.value) : tokens.get(reference.value)\n if (providesDashboardWidget && target === 'dashboards'\n && reference.kind === 'feature' && reference.value === 'analytics.view') continue\n if (providesInboxActions && target === 'inbox_ops' && reference.kind === 'import') continue\n if (!target) {\n if (!integration && (reference.kind === 'api-path' || reference.kind === 'page-path') && !reference.partial) {\n dangling.push({ ...reference, module })\n }\n continue\n }\n if (target === module || structural.has(target)) continue\n const context = { module, target, file: file.absolute, line: reference.line, kind: reference.kind }\n if (integration) {\n if (!kernel.has(target) && !knownHard?.has(target) && !testDependencies?.has(target)) {\n findings.push({ ...context, rule: 'R4', message: `Integration spec must declare dependsOnModules: ['${target}']` })\n }\n continue\n }\n if (!kernel.has(target) && !knownHard?.has(target) && !optional.has(target)) {\n findings.push({ ...context, rule: 'R1', message: `'${module}' references '${target}' without a dependency declaration` })\n }\n if (optional.has(target)) {\n const peer = modules.get(target)\n if (!guardEvidence(file, target, peer?.features ?? new Set(), peer?.tokens ?? new Set(), reference)) {\n findings.push({ ...context, rule: 'R2', message: `Optional reference to '${target}' has no module guard` })\n }\n }\n if (!(kernel.has(module) && kernel.has(target)) && dependencies.get(target)?.has(module)) {\n findings.push({ ...context, rule: 'R5', message: `'${module}' references its consumer '${target}'` })\n }\n }\n }\n }\n return { findings, dangling, contributions: hostContributions([...modules.values()], new Set(analyzedModuleIds)) }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,gCAAgC;AACzC,SAAS,0BAA0B;AACnC,SAAS,4BAAgD;AACzD,SAAS,wCAAwC;AAE1C,MAAM,kBAAkB,CAAC,QAAQ,aAAa,UAAU;AAC/D,MAAM,SAAS,IAAI,IAAY,eAAe;AAC9C,MAAM,sBAAsB,oBAAI,IAAI,CAAC,aAAa,aAAa,kBAAkB,cAAc,QAAQ,cAAc,CAAC;AACtH,MAAM,mBAAmB;AAkCzB,SAAS,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MAAM,wBAAwB,CAAC;AAAA,UAC5G;AAAA,QACF;AACA,YAAI,EAAE,OAAO,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,MAAM,aAAa,IAAI,MAAM,GAAG,IAAI,MAAM,GAAG;AACxF,mBAAS,KAAK,EAAE,GAAG,SAAS,MAAM,MAAM,SAAS,IAAI,MAAM,8BAA8B,MAAM,IAAI,CAAC;AAAA,QACtG;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,UAAU,UAAU,eAAe,kBAAkB,CAAC,GAAG,QAAQ,OAAO,CAAC,GAAG,IAAI,IAAI,iBAAiB,CAAC,EAAE;AACnH;",
|
|
6
|
+
"names": ["visit", "file"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { getModuleRequirementHint } from "@open-mercato/shared/modules/module-locators";
|
|
3
|
+
import { analyzeModuleCoupling, optionalCapabilityLabel, PLATFORM_KERNEL } from "./module-coupling/analyze.js";
|
|
4
|
+
import { buildModuleIndex, inactiveModuleDependencies, missingModuleRequirements, resolveIndexedModule } from "./module-index.js";
|
|
5
|
+
import { createResolver } from "./resolver.js";
|
|
6
|
+
const GROUPS = [
|
|
7
|
+
"missing-kernel",
|
|
8
|
+
"missing-hard",
|
|
9
|
+
"inactive-optional",
|
|
10
|
+
"undeclared-or-upstream",
|
|
11
|
+
"missing-contributions",
|
|
12
|
+
"dangling"
|
|
13
|
+
];
|
|
14
|
+
function cleanFileName(root, file) {
|
|
15
|
+
return path.relative(root, file).split(path.sep).join("/");
|
|
16
|
+
}
|
|
17
|
+
function printHelp(command) {
|
|
18
|
+
if (command === "list") console.log("Usage: yarn mercato module list [--all] [--json]");
|
|
19
|
+
else console.log("Usage: yarn mercato module doctor [--strict] [--json]");
|
|
20
|
+
}
|
|
21
|
+
function listModules(modules, json, all) {
|
|
22
|
+
const enabled = modules.filter((module) => module.enabled);
|
|
23
|
+
const rows = modules.filter((module) => all || module.enabled).map((module) => ({
|
|
24
|
+
id: module.id,
|
|
25
|
+
package: module.packageName,
|
|
26
|
+
version: module.version,
|
|
27
|
+
enabled: module.enabled,
|
|
28
|
+
requires: module.requires,
|
|
29
|
+
optionalRequires: module.optionalRequires,
|
|
30
|
+
requiredBy: enabled.filter((other) => other.requires.some((requirement) => resolveIndexedModule(requirement, modules) === module)).map((other) => other.id),
|
|
31
|
+
...module.notAnalyzed ? { notAnalyzed: module.notAnalyzed } : {}
|
|
32
|
+
}));
|
|
33
|
+
if (json) {
|
|
34
|
+
console.log(JSON.stringify({ version: 1, modules: rows }, null, 2));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const row of rows) {
|
|
38
|
+
const status = row.enabled ? "enabled" : "installed";
|
|
39
|
+
const version = row.version ? `@${row.version}` : "";
|
|
40
|
+
console.log(`${row.id} ${row.package}${version} (${status})`);
|
|
41
|
+
if (row.requires.length) console.log(` Requires: ${row.requires.join(", ")}`);
|
|
42
|
+
if (row.optionalRequires.length) console.log(` Optional: ${row.optionalRequires.join(", ")}`);
|
|
43
|
+
if (row.requiredBy.length) console.log(` Required by: ${row.requiredBy.join(", ")}`);
|
|
44
|
+
if (row.notAnalyzed) console.log(` Not analyzed: ${row.notAnalyzed}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function instructionFor(target, modules) {
|
|
48
|
+
const installed = resolveIndexedModule(target, modules);
|
|
49
|
+
if (installed?.packageName === "@app") return `Enable '${installed.id}' in src/modules.ts.`;
|
|
50
|
+
if (installed) return `yarn mercato module enable ${installed.packageName} --module ${installed.id}`;
|
|
51
|
+
return getModuleRequirementHint(target);
|
|
52
|
+
}
|
|
53
|
+
function doctorFindings(modules, root) {
|
|
54
|
+
const enabled = modules.filter((module) => module.enabled);
|
|
55
|
+
const enabledIds = new Set(enabled.map((module) => module.id));
|
|
56
|
+
const findings = PLATFORM_KERNEL.filter((id) => !enabledIds.has(id)).map((module) => ({
|
|
57
|
+
group: "missing-kernel",
|
|
58
|
+
module,
|
|
59
|
+
message: `Enable kernel module '${module}' in src/modules.ts.`
|
|
60
|
+
}));
|
|
61
|
+
for (const module of enabled) {
|
|
62
|
+
for (const { requirement, path: chain } of missingModuleRequirements(module, modules)) {
|
|
63
|
+
findings.push({
|
|
64
|
+
group: "missing-hard",
|
|
65
|
+
module: module.id,
|
|
66
|
+
target: requirement,
|
|
67
|
+
message: `${chain.join(" \u2192 ")} is required. ${instructionFor(requirement, modules)}`
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const { source, target } of inactiveModuleDependencies(modules)) {
|
|
72
|
+
const label = optionalCapabilityLabel(source, resolveIndexedModule(target, modules)?.id ?? target);
|
|
73
|
+
findings.push({
|
|
74
|
+
group: "inactive-optional",
|
|
75
|
+
module: source.id,
|
|
76
|
+
target,
|
|
77
|
+
message: `${label ?? `Optional module '${target}'`} is inactive. ${instructionFor(target, modules)}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const coupling = analyzeModuleCoupling(modules);
|
|
81
|
+
for (const finding of coupling.findings) {
|
|
82
|
+
if (finding.rule === "R4" || enabledIds.has(finding.target) && finding.rule !== "R2") continue;
|
|
83
|
+
findings.push({
|
|
84
|
+
group: "undeclared-or-upstream",
|
|
85
|
+
module: finding.module,
|
|
86
|
+
target: finding.target,
|
|
87
|
+
kind: finding.kind,
|
|
88
|
+
file: cleanFileName(root, finding.file),
|
|
89
|
+
line: finding.line,
|
|
90
|
+
message: finding.message
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
for (const finding of coupling.contributions) {
|
|
94
|
+
findings.push({
|
|
95
|
+
group: "missing-contributions",
|
|
96
|
+
module: finding.module,
|
|
97
|
+
target: finding.spotId,
|
|
98
|
+
file: cleanFileName(root, finding.file),
|
|
99
|
+
line: finding.line,
|
|
100
|
+
message: `Host '${finding.spotId}' needs ${finding.minimum} enabled contributions, found ${finding.count}.`
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
for (const reference of coupling.dangling) {
|
|
104
|
+
findings.push({
|
|
105
|
+
group: "dangling",
|
|
106
|
+
module: reference.module,
|
|
107
|
+
target: reference.value,
|
|
108
|
+
kind: reference.kind,
|
|
109
|
+
file: cleanFileName(root, reference.file),
|
|
110
|
+
line: reference.line,
|
|
111
|
+
message: `No installed module owns '${reference.value}'.`
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const seen = /* @__PURE__ */ new Set();
|
|
115
|
+
return findings.filter((finding) => {
|
|
116
|
+
const key = JSON.stringify(finding);
|
|
117
|
+
if (seen.has(key)) return false;
|
|
118
|
+
seen.add(key);
|
|
119
|
+
return true;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function runModuleDiagnostics(command, args, resolver = createResolver()) {
|
|
123
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
124
|
+
printHelp(command);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
const commandFlag = command === "list" ? "--all" : "--strict";
|
|
128
|
+
const invalid = args.find((arg) => arg !== "--json" && arg !== commandFlag);
|
|
129
|
+
if (invalid) {
|
|
130
|
+
console.error(`Unknown module ${command} option '${invalid}'.`);
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
const json = args.includes("--json");
|
|
134
|
+
const modules = buildModuleIndex(resolver, command === "doctor" || args.includes("--all"));
|
|
135
|
+
if (command === "list") {
|
|
136
|
+
listModules(modules, json, args.includes("--all"));
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
const enabled = modules.filter((module) => module.enabled).map((module) => module.id);
|
|
140
|
+
const notAnalyzed = modules.filter((module) => module.enabled && module.notAnalyzed).map((module) => ({ module: module.id, reason: module.notAnalyzed }));
|
|
141
|
+
const findings = doctorFindings(modules, resolver.getAppDir());
|
|
142
|
+
if (json) console.log(JSON.stringify({ version: 1, enabled, findings, ...notAnalyzed.length ? { notAnalyzed } : {} }, null, 2));
|
|
143
|
+
else {
|
|
144
|
+
for (const group of GROUPS) {
|
|
145
|
+
const rows = findings.filter((finding) => finding.group === group);
|
|
146
|
+
console.log(`${group} (${rows.length})`);
|
|
147
|
+
for (const row of rows) {
|
|
148
|
+
const location = row.file ? ` (${row.file}${row.line ? `:${row.line}` : ""})` : "";
|
|
149
|
+
console.log(` ${row.module}: ${row.message}${location}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const row of notAnalyzed) console.log(`Not analyzed: ${row.module} (${row.reason})`);
|
|
153
|
+
}
|
|
154
|
+
const strict = args.includes("--strict");
|
|
155
|
+
return findings.some((finding) => finding.group === "missing-kernel" || finding.group === "missing-hard" || strict && finding.group !== "inactive-optional") ? 1 : 0;
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
runModuleDiagnostics
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=module-diagnostics.js.map
|