@getchomp/core 0.0.0-stage → 0.2.42
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/README.md +10 -2
- package/dist/diagnostics/frameworkCoverage.d.ts +72 -0
- package/dist/diagnostics/frameworkCoverage.js +588 -0
- package/dist/diagnostics/healthMetrics.d.ts +50 -0
- package/dist/diagnostics/healthMetrics.js +123 -0
- package/dist/diagnostics/receptorClassifier.d.ts +56 -0
- package/dist/diagnostics/receptorClassifier.js +402 -0
- package/dist/diagnostics/scoutSanity.d.ts +82 -0
- package/dist/diagnostics/scoutSanity.js +811 -0
- package/dist/diagnostics/shapeResolution.d.ts +145 -0
- package/dist/diagnostics/shapeResolution.js +672 -0
- package/dist/diagnostics/signalClusters.d.ts +65 -0
- package/dist/diagnostics/signalClusters.js +88 -0
- package/dist/diagnostics/unresolvedClassifier.d.ts +31 -0
- package/dist/diagnostics/unresolvedClassifier.js +525 -0
- package/dist/differ/index.d.ts +10 -0
- package/dist/differ/index.js +199 -0
- package/dist/extractor/adapters/drizzleAdapter.d.ts +25 -0
- package/dist/extractor/adapters/drizzleAdapter.js +156 -0
- package/dist/extractor/adapters/expressAdapter.d.ts +124 -0
- package/dist/extractor/adapters/expressAdapter.js +150 -0
- package/dist/extractor/adapters/mcpAdapter.d.ts +7 -0
- package/dist/extractor/adapters/mcpAdapter.js +17 -0
- package/dist/extractor/adapters/nextjsAdapter.d.ts +67 -0
- package/dist/extractor/adapters/nextjsAdapter.js +132 -0
- package/dist/extractor/adapters/payloadAdapter.d.ts +10 -0
- package/dist/extractor/adapters/payloadAdapter.js +39 -0
- package/dist/extractor/adapters/reactAdapter.d.ts +22 -0
- package/dist/extractor/adapters/reactAdapter.js +50 -0
- package/dist/extractor/conventions/astro.d.ts +22 -0
- package/dist/extractor/conventions/astro.js +106 -0
- package/dist/extractor/conventions/config.d.ts +20 -0
- package/dist/extractor/conventions/config.js +150 -0
- package/dist/extractor/conventions/core.d.ts +2 -0
- package/dist/extractor/conventions/core.js +222 -0
- package/dist/extractor/conventions/drizzle.d.ts +9 -0
- package/dist/extractor/conventions/drizzle.js +100 -0
- package/dist/extractor/conventions/engine.d.ts +139 -0
- package/dist/extractor/conventions/engine.js +2918 -0
- package/dist/extractor/conventions/express.d.ts +6 -0
- package/dist/extractor/conventions/express.js +284 -0
- package/dist/extractor/conventions/frameworks.d.ts +340 -0
- package/dist/extractor/conventions/frameworks.js +1754 -0
- package/dist/extractor/conventions/index.d.ts +34 -0
- package/dist/extractor/conventions/index.js +95 -0
- package/dist/extractor/conventions/mcp.d.ts +2 -0
- package/dist/extractor/conventions/mcp.js +40 -0
- package/dist/extractor/conventions/nextjs.d.ts +27 -0
- package/dist/extractor/conventions/nextjs.js +263 -0
- package/dist/extractor/conventions/payload.d.ts +10 -0
- package/dist/extractor/conventions/payload.js +420 -0
- package/dist/extractor/conventions/portConventions.d.ts +26 -0
- package/dist/extractor/conventions/portConventions.js +405 -0
- package/dist/extractor/conventions/react.d.ts +13 -0
- package/dist/extractor/conventions/react.js +152 -0
- package/dist/extractor/conventions/sveltekit.d.ts +52 -0
- package/dist/extractor/conventions/sveltekit.js +272 -0
- package/dist/extractor/conventions/types.d.ts +398 -0
- package/dist/extractor/conventions/types.js +17 -0
- package/dist/extractor/index.d.ts +45 -0
- package/dist/extractor/index.js +1535 -0
- package/dist/extractor/pathResolver.d.ts +18 -0
- package/dist/extractor/pathResolver.js +475 -0
- package/dist/extractor/sourcePreprocessor.d.ts +43 -0
- package/dist/extractor/sourcePreprocessor.js +529 -0
- package/dist/extractor/visitors/boundaryVisitor.d.ts +3 -0
- package/dist/extractor/visitors/boundaryVisitor.js +74 -0
- package/dist/extractor/visitors/commonjsExportVisitor.d.ts +7 -0
- package/dist/extractor/visitors/commonjsExportVisitor.js +18 -0
- package/dist/extractor/visitors/contractVisitor.d.ts +30 -0
- package/dist/extractor/visitors/contractVisitor.js +1220 -0
- package/dist/extractor/visitors/definePropertyVisitor.d.ts +7 -0
- package/dist/extractor/visitors/definePropertyVisitor.js +12 -0
- package/dist/extractor/visitors/directiveVisitor.d.ts +22 -0
- package/dist/extractor/visitors/directiveVisitor.js +50 -0
- package/dist/extractor/visitors/eventEmitterVisitor.d.ts +64 -0
- package/dist/extractor/visitors/eventEmitterVisitor.js +157 -0
- package/dist/extractor/visitors/factoryExportVisitor.d.ts +7 -0
- package/dist/extractor/visitors/factoryExportVisitor.js +126 -0
- package/dist/extractor/visitors/frameworkRelationshipVisitor.d.ts +141 -0
- package/dist/extractor/visitors/frameworkRelationshipVisitor.js +2611 -0
- package/dist/extractor/visitors/initBlockVisitor.d.ts +71 -0
- package/dist/extractor/visitors/initBlockVisitor.js +575 -0
- package/dist/extractor/visitors/openConnectorVisitor.d.ts +126 -0
- package/dist/extractor/visitors/openConnectorVisitor.js +1708 -0
- package/dist/extractor/visitors/portValveVisitor.d.ts +49 -0
- package/dist/extractor/visitors/portValveVisitor.js +440 -0
- package/dist/extractor/visitors/publicMethodVisitor.d.ts +28 -0
- package/dist/extractor/visitors/publicMethodVisitor.js +242 -0
- package/dist/extractor/visitors/relationshipVisitor.d.ts +81 -0
- package/dist/extractor/visitors/relationshipVisitor.js +5249 -0
- package/dist/extractor/visitors/shapeKeyVisitor.d.ts +52 -0
- package/dist/extractor/visitors/shapeKeyVisitor.js +623 -0
- package/dist/extractor/visitors/targetResolver.d.ts +252 -0
- package/dist/extractor/visitors/targetResolver.js +4850 -0
- package/dist/extractor/visitors/unresolvedConnectionVisitor.d.ts +53 -0
- package/dist/extractor/visitors/unresolvedConnectionVisitor.js +1850 -0
- package/dist/extractor/workspaceResolver.d.ts +70 -0
- package/dist/extractor/workspaceResolver.js +678 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/layout/entityVocabulary.d.ts +70 -0
- package/dist/layout/entityVocabulary.js +212 -0
- package/dist/layout/healthMetrics.d.ts +10 -0
- package/dist/layout/healthMetrics.js +194 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/ruleMatcher.d.ts +71 -0
- package/dist/layout/ruleMatcher.js +193 -0
- package/dist/layout/types.d.ts +337 -0
- package/dist/layout/types.js +9 -0
- package/dist/layout/visualLinter.d.ts +94 -0
- package/dist/layout/visualLinter.js +378 -0
- package/dist/shims/applyShimOverlays.d.ts +50 -0
- package/dist/shims/applyShimOverlays.js +209 -0
- package/dist/types/diff.d.ts +27 -0
- package/dist/types/diff.js +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +10 -0
- package/dist/types/ledger.d.ts +120 -0
- package/dist/types/ledger.js +3 -0
- package/dist/types/ontology.d.ts +251 -0
- package/dist/types/ontology.js +31 -0
- package/dist/types/pluginPresentation.d.ts +374 -0
- package/dist/types/pluginPresentation.js +626 -0
- package/dist/types/ports.d.ts +34 -0
- package/dist/types/ports.js +308 -0
- package/dist/utils/entityHash.d.ts +17 -0
- package/dist/utils/entityHash.js +26 -0
- package/dist/utils/id.d.ts +83 -0
- package/dist/utils/id.js +159 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +29 -0
- package/package.json +84 -3
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@getchomp/core`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deterministic, single-pass TypeScript & JavaScript AST structural extraction engine for [Chomp](https://getchomp.dev).
|
|
4
|
+
|
|
5
|
+
- Extracts **Boundaries** (`DEPLOYMENT_UNIT`, `CLASS`, `NAMESPACE`, `INIT_BLOCK`), **Contracts**, **Relationships**, and **Open Connectors** with line-level source traceability and SHA-256 identity.
|
|
6
|
+
- Structural graph diffing (`compareGraphs`), unresolved call classification, and declarative framework conventions.
|
|
7
|
+
- Zero database imports and zero network calls.
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
See [https://getchomp.dev/docs](https://getchomp.dev/docs).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { RepresentationGraph } from '../types/index.js';
|
|
2
|
+
export type FrameworkRuleCategory = 'framework-adapter' | 'unhandled-framework' | 'library';
|
|
3
|
+
export interface FrameworkDetectionRule {
|
|
4
|
+
label: string;
|
|
5
|
+
deps: readonly string[];
|
|
6
|
+
category: FrameworkRuleCategory;
|
|
7
|
+
/** Matches `ConventionSet.framework` when `category === 'framework-adapter'`. */
|
|
8
|
+
conventionSetId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const FRAMEWORK_DETECTION_RULES: readonly FrameworkDetectionRule[];
|
|
11
|
+
export declare function detectFrameworkRulesFromDependencies(deps: Iterable<string>): FrameworkDetectionRule[];
|
|
12
|
+
export declare function detectFrameworkRulesFromPackageJson(pkgJsonPath: string): FrameworkDetectionRule[];
|
|
13
|
+
export declare function detectFrameworksFromPackageJson(pkgJsonPath: string): string[];
|
|
14
|
+
export type FrameworkWarningKind = 'UNHANDLED_FRAMEWORK' | 'SUSPECTED_CUSTOM_CONVENTION' | 'UNRESOLVED_CONVENTION_CONFIG';
|
|
15
|
+
export interface FrameworkCoverageWarning {
|
|
16
|
+
kind: FrameworkWarningKind;
|
|
17
|
+
packageName: string;
|
|
18
|
+
packagePath: string;
|
|
19
|
+
framework: string;
|
|
20
|
+
conventionSetId?: string;
|
|
21
|
+
configFile?: string;
|
|
22
|
+
configKey?: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PackageFrameworkCoverage {
|
|
26
|
+
packageName: string;
|
|
27
|
+
packagePath: string;
|
|
28
|
+
frameworks: string[];
|
|
29
|
+
supportedAdapters: string[];
|
|
30
|
+
unhandledFrameworks: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface UnextractedExportRecord {
|
|
33
|
+
filePath: string;
|
|
34
|
+
lineNumber: number;
|
|
35
|
+
exportName: string;
|
|
36
|
+
exportSyntax: string;
|
|
37
|
+
snippet: string;
|
|
38
|
+
}
|
|
39
|
+
export interface FrameworkCoverageReport {
|
|
40
|
+
packages: PackageFrameworkCoverage[];
|
|
41
|
+
warnings: FrameworkCoverageWarning[];
|
|
42
|
+
/**
|
|
43
|
+
* Source files in USER scope (`analyzedFiles`) that produced 0 extracted Contracts,
|
|
44
|
+
* 0 Class/Namespace boundaries, and 0 originating Relationships (Signal 4: Dark Files).
|
|
45
|
+
*/
|
|
46
|
+
darkFiles: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Top-level non-type, non-scalar `export` declarations in USER-scope source files that did not
|
|
49
|
+
* produce any `CONTRACT` or `CLASS`/`NAMESPACE` `BOUNDARY` node (even if the file is only
|
|
50
|
+
* partially dark or no other file imports the export).
|
|
51
|
+
*/
|
|
52
|
+
unextractedExports: UnextractedExportRecord[];
|
|
53
|
+
}
|
|
54
|
+
import { findDarkFiles } from './shapeResolution.js';
|
|
55
|
+
export { findDarkFiles };
|
|
56
|
+
/**
|
|
57
|
+
* Inspects every USER-scope source file (`analyzedFiles`) and returns top-level non-type,
|
|
58
|
+
* non-scalar `export` declarations (`export const x = factory(...)`, `export const cfg = { ... }`,
|
|
59
|
+
* `export default ...`) that did not produce any `CONTRACT` or `CLASS`/`NAMESPACE` `BOUNDARY` node.
|
|
60
|
+
*
|
|
61
|
+
* Catches unhandled export patterns even when:
|
|
62
|
+
* 1. The file is only partially dark (another export or `INIT_BLOCK` edge made the file active).
|
|
63
|
+
* 2. No other file in the repository imports the export yet.
|
|
64
|
+
*/
|
|
65
|
+
export declare function findUnextractedExports(repoRoot: string, graph: Pick<RepresentationGraph, 'nodes' | 'edges' | 'analyzedFiles'>): UnextractedExportRecord[];
|
|
66
|
+
/**
|
|
67
|
+
* Evaluates a repository's `package.json` dependencies and convention configs against the extracted
|
|
68
|
+
* `RepresentationGraph` to surface accuracy warnings for unhandled frameworks, suspected custom
|
|
69
|
+
* conventions (0 framework contracts extracted despite the framework dependency), and dynamic
|
|
70
|
+
* convention config values.
|
|
71
|
+
*/
|
|
72
|
+
export declare function auditFrameworkCoverage(repoRoot: string, graph: Pick<RepresentationGraph, 'nodes' | 'edges' | 'analyzedFiles'>, excludeWorkspaces?: readonly string[]): FrameworkCoverageReport;
|
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
// packages/core/src/diagnostics/frameworkCoverage.ts
|
|
2
|
+
//
|
|
3
|
+
// Shared framework detection & post-extraction convention coverage / accuracy diagnostics.
|
|
4
|
+
//
|
|
5
|
+
// Principle of Incomplete Truth:
|
|
6
|
+
// 1. When a repository depends on a framework that has NO registered convention set in @chomp/core
|
|
7
|
+
// (e.g. Fastify, NestJS, Hono), Chomp must warn that only generic TypeScript/ES module structure
|
|
8
|
+
// is extracted and framework-specific conventions may be missing (`UNHANDLED_FRAMEWORK`).
|
|
9
|
+
// 2. When a repository depends on a supported framework (e.g. Next.js, Express, MCP SDK, Drizzle,
|
|
10
|
+
// Payload CMS) in a package that contains extracted source entities, yet 0 entities from that
|
|
11
|
+
// framework's convention set were produced, Chomp flags a suspected custom convention or
|
|
12
|
+
// unhandled variant (`SUSPECTED_CUSTOM_CONVENTION`).
|
|
13
|
+
// 3. When a framework config file (e.g. `next.config.js` `pageExtensions`) uses a dynamic expression
|
|
14
|
+
// that cannot be statically proven, Chomp surfaces `UNRESOLVED_CONVENTION_CONFIG`.
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import ts from 'typescript';
|
|
18
|
+
import { buildWorkspaceRegistry } from '../extractor/workspaceResolver.js';
|
|
19
|
+
import { getCachedSourceFile, preprocessAstroOrMdxSource } from '../extractor/visitors/targetResolver.js';
|
|
20
|
+
import { extractSymbolFromNodeName } from '../extractor/visitors/unresolvedConnectionVisitor.js';
|
|
21
|
+
import { CONVENTION_SETS, createConventionConfigResolver, } from '../extractor/conventions/index.js';
|
|
22
|
+
export const FRAMEWORK_DETECTION_RULES = [
|
|
23
|
+
// Supported frameworks with declarative convention sets in `packages/core/src/extractor/conventions/`
|
|
24
|
+
{ label: 'Next.js', deps: ['next'], category: 'framework-adapter', conventionSetId: 'nextjs' },
|
|
25
|
+
{ label: 'React', deps: ['react', 'react-dom'], category: 'framework-adapter', conventionSetId: 'react' },
|
|
26
|
+
{ label: 'Express', deps: ['express'], category: 'framework-adapter', conventionSetId: 'express' },
|
|
27
|
+
{ label: 'Hono', deps: ['hono'], category: 'framework-adapter', conventionSetId: 'express' },
|
|
28
|
+
{
|
|
29
|
+
label: 'MCP SDK',
|
|
30
|
+
deps: ['@modelcontextprotocol/sdk'],
|
|
31
|
+
category: 'framework-adapter',
|
|
32
|
+
conventionSetId: 'mcp',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Payload CMS',
|
|
36
|
+
deps: ['payload', '@payloadcms/next'],
|
|
37
|
+
category: 'framework-adapter',
|
|
38
|
+
conventionSetId: 'payload',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'Drizzle',
|
|
42
|
+
deps: ['drizzle-orm'],
|
|
43
|
+
category: 'framework-adapter',
|
|
44
|
+
conventionSetId: 'drizzle',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
label: 'Astro',
|
|
48
|
+
deps: ['astro'],
|
|
49
|
+
category: 'framework-adapter',
|
|
50
|
+
conventionSetId: 'astro',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Svelte',
|
|
54
|
+
deps: ['svelte', '@sveltejs/kit'],
|
|
55
|
+
category: 'framework-adapter',
|
|
56
|
+
conventionSetId: 'sveltekit',
|
|
57
|
+
},
|
|
58
|
+
// Known frameworks without a dedicated convention adapter yet (emit accuracy warnings)
|
|
59
|
+
{ label: 'Fastify', deps: ['fastify'], category: 'unhandled-framework' },
|
|
60
|
+
{ label: 'NestJS', deps: ['@nestjs/core'], category: 'unhandled-framework' },
|
|
61
|
+
{ label: 'Koa', deps: ['koa'], category: 'unhandled-framework' },
|
|
62
|
+
{
|
|
63
|
+
label: 'Remix',
|
|
64
|
+
deps: ['@remix-run/react', '@remix-run/node'],
|
|
65
|
+
category: 'unhandled-framework',
|
|
66
|
+
},
|
|
67
|
+
{ label: 'tRPC', deps: ['@trpc/server'], category: 'unhandled-framework' },
|
|
68
|
+
{
|
|
69
|
+
label: 'GraphQL',
|
|
70
|
+
deps: ['@apollo/server', 'type-graphql'],
|
|
71
|
+
category: 'unhandled-framework',
|
|
72
|
+
},
|
|
73
|
+
{ label: 'Vue', deps: ['vue', 'nuxt'], category: 'unhandled-framework' },
|
|
74
|
+
{ label: 'Angular', deps: ['@angular/core'], category: 'unhandled-framework' },
|
|
75
|
+
// Standard libraries / runtimes displayed in workspace discovery
|
|
76
|
+
{ label: 'PixiJS', deps: ['pixi.js', 'pixi-viewport'], category: 'library' },
|
|
77
|
+
{ label: 'SQLite', deps: ['better-sqlite3', 'sqlite3'], category: 'library' },
|
|
78
|
+
{ label: 'Prisma', deps: ['prisma', '@prisma/client'], category: 'library' },
|
|
79
|
+
{ label: 'Supabase', deps: ['@supabase/supabase-js'], category: 'library' },
|
|
80
|
+
{ label: 'Commander CLI', deps: ['commander'], category: 'library' },
|
|
81
|
+
{ label: 'Tailwind CSS', deps: ['tailwindcss', '@tailwindcss/postcss'], category: 'library' },
|
|
82
|
+
];
|
|
83
|
+
export function detectFrameworkRulesFromDependencies(deps) {
|
|
84
|
+
const allDeps = deps instanceof Set ? deps : new Set(deps);
|
|
85
|
+
const matched = [];
|
|
86
|
+
for (const rule of FRAMEWORK_DETECTION_RULES) {
|
|
87
|
+
if (rule.deps.some((d) => allDeps.has(d))) {
|
|
88
|
+
matched.push(rule);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return matched;
|
|
92
|
+
}
|
|
93
|
+
export function detectFrameworkRulesFromPackageJson(pkgJsonPath) {
|
|
94
|
+
if (!fs.existsSync(pkgJsonPath))
|
|
95
|
+
return [];
|
|
96
|
+
try {
|
|
97
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
98
|
+
const allDeps = new Set([
|
|
99
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
100
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
101
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
102
|
+
]);
|
|
103
|
+
return detectFrameworkRulesFromDependencies(allDeps);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function detectFrameworksFromPackageJson(pkgJsonPath) {
|
|
110
|
+
if (!fs.existsSync(pkgJsonPath))
|
|
111
|
+
return [];
|
|
112
|
+
try {
|
|
113
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
114
|
+
const allDeps = new Set([
|
|
115
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
116
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
117
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
118
|
+
]);
|
|
119
|
+
const found = detectFrameworkRulesFromPackageJson(pkgJsonPath).map((r) => r.label);
|
|
120
|
+
if (found.length === 0 && allDeps.has('typescript')) {
|
|
121
|
+
found.push('TypeScript');
|
|
122
|
+
}
|
|
123
|
+
return found;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
import { findDarkFiles, parseDuAnalyzedFiles } from './shapeResolution.js';
|
|
130
|
+
export { findDarkFiles };
|
|
131
|
+
function unwrapTypeAssertions(expr) {
|
|
132
|
+
let cur = expr;
|
|
133
|
+
while (ts.isParenthesizedExpression(cur) ||
|
|
134
|
+
ts.isAsExpression(cur) ||
|
|
135
|
+
ts.isSatisfiesExpression(cur) ||
|
|
136
|
+
ts.isTypeAssertionExpression(cur) ||
|
|
137
|
+
ts.isNonNullExpression(cur) ||
|
|
138
|
+
ts.isAwaitExpression(cur)) {
|
|
139
|
+
cur = cur.expression;
|
|
140
|
+
}
|
|
141
|
+
return cur;
|
|
142
|
+
}
|
|
143
|
+
function isScalarOrLiteralArray(expr, depth = 0) {
|
|
144
|
+
if (depth > 6)
|
|
145
|
+
return false;
|
|
146
|
+
const e = unwrapTypeAssertions(expr);
|
|
147
|
+
if (ts.isStringLiteral(e) ||
|
|
148
|
+
ts.isNumericLiteral(e) ||
|
|
149
|
+
ts.isBigIntLiteral(e) ||
|
|
150
|
+
ts.isNoSubstitutionTemplateLiteral(e) ||
|
|
151
|
+
ts.isTemplateExpression(e) ||
|
|
152
|
+
ts.isRegularExpressionLiteral(e) ||
|
|
153
|
+
e.kind === ts.SyntaxKind.TrueKeyword ||
|
|
154
|
+
e.kind === ts.SyntaxKind.FalseKeyword ||
|
|
155
|
+
e.kind === ts.SyntaxKind.NullKeyword ||
|
|
156
|
+
e.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (ts.isPrefixUnaryExpression(e)) {
|
|
160
|
+
return isScalarOrLiteralArray(e.operand, depth + 1);
|
|
161
|
+
}
|
|
162
|
+
if (ts.isBinaryExpression(e)) {
|
|
163
|
+
return isScalarOrLiteralArray(e.left, depth + 1) && isScalarOrLiteralArray(e.right, depth + 1);
|
|
164
|
+
}
|
|
165
|
+
if (ts.isArrayLiteralExpression(e)) {
|
|
166
|
+
return e.elements.every((el) => ts.isExpression(el) && isScalarOrLiteralArray(el, depth + 1));
|
|
167
|
+
}
|
|
168
|
+
if (ts.isNewExpression(e) &&
|
|
169
|
+
ts.isIdentifier(e.expression) &&
|
|
170
|
+
(e.expression.text === 'Set' || e.expression.text === 'Map')) {
|
|
171
|
+
return (e.arguments ?? []).every((arg) => isScalarOrLiteralArray(arg, depth + 1));
|
|
172
|
+
}
|
|
173
|
+
if (ts.isObjectLiteralExpression(e)) {
|
|
174
|
+
return e.properties.every((prop) => {
|
|
175
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
176
|
+
const init = unwrapTypeAssertions(prop.initializer);
|
|
177
|
+
if (depth <= 1 && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return (isScalarOrLiteralArray(init, depth + 1) ||
|
|
181
|
+
(depth >= 2 && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))));
|
|
182
|
+
}
|
|
183
|
+
if (ts.isSpreadAssignment(prop)) {
|
|
184
|
+
return ts.isIdentifier(prop.expression) || isScalarOrLiteralArray(prop.expression, depth + 1);
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
function formatCalleeLabel(expr) {
|
|
192
|
+
const e = unwrapTypeAssertions(expr);
|
|
193
|
+
if (ts.isIdentifier(e))
|
|
194
|
+
return e.text;
|
|
195
|
+
if (ts.isPropertyAccessExpression(e)) {
|
|
196
|
+
const head = formatCalleeLabel(e.expression);
|
|
197
|
+
return head ? `${head}.${e.name.text}` : e.name.text;
|
|
198
|
+
}
|
|
199
|
+
return 'anonymous';
|
|
200
|
+
}
|
|
201
|
+
function classifyExportInitializerSyntax(expr) {
|
|
202
|
+
const e = unwrapTypeAssertions(expr);
|
|
203
|
+
if (ts.isCallExpression(e)) {
|
|
204
|
+
return `Call(${formatCalleeLabel(e.expression)})`;
|
|
205
|
+
}
|
|
206
|
+
if (ts.isNewExpression(e)) {
|
|
207
|
+
return `New(${formatCalleeLabel(e.expression)})`;
|
|
208
|
+
}
|
|
209
|
+
if (ts.isObjectLiteralExpression(e))
|
|
210
|
+
return 'ObjectLiteral';
|
|
211
|
+
if (ts.isArrayLiteralExpression(e))
|
|
212
|
+
return 'ArrayLiteral';
|
|
213
|
+
if (ts.isArrowFunction(e) || ts.isFunctionExpression(e))
|
|
214
|
+
return 'FunctionExpr';
|
|
215
|
+
if (ts.isClassExpression(e))
|
|
216
|
+
return 'ClassExpr';
|
|
217
|
+
if (ts.isTaggedTemplateExpression(e)) {
|
|
218
|
+
return `TaggedTemplate(${formatCalleeLabel(e.tag)})`;
|
|
219
|
+
}
|
|
220
|
+
if (ts.isIdentifier(e))
|
|
221
|
+
return `Identifier(${e.text})`;
|
|
222
|
+
return ts.SyntaxKind[e.kind] ?? 'Expression';
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Inspects every USER-scope source file (`analyzedFiles`) and returns top-level non-type,
|
|
226
|
+
* non-scalar `export` declarations (`export const x = factory(...)`, `export const cfg = { ... }`,
|
|
227
|
+
* `export default ...`) that did not produce any `CONTRACT` or `CLASS`/`NAMESPACE` `BOUNDARY` node.
|
|
228
|
+
*
|
|
229
|
+
* Catches unhandled export patterns even when:
|
|
230
|
+
* 1. The file is only partially dark (another export or `INIT_BLOCK` edge made the file active).
|
|
231
|
+
* 2. No other file in the repository imports the export yet.
|
|
232
|
+
*/
|
|
233
|
+
export function findUnextractedExports(repoRoot, graph) {
|
|
234
|
+
const absRoot = path.resolve(repoRoot);
|
|
235
|
+
const rootDir = fs.existsSync(absRoot) && fs.statSync(absRoot).isFile()
|
|
236
|
+
? path.dirname(absRoot)
|
|
237
|
+
: absRoot;
|
|
238
|
+
const candidates = new Set();
|
|
239
|
+
if (Array.isArray(graph.analyzedFiles) && graph.analyzedFiles.length > 0) {
|
|
240
|
+
for (const f of graph.analyzedFiles) {
|
|
241
|
+
candidates.add(f.replace(/\\/g, '/'));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
for (const n of graph.nodes) {
|
|
246
|
+
if (n.type === 'BOUNDARY' && n.entityType === 'DEPLOYMENT_UNIT') {
|
|
247
|
+
for (const f of parseDuAnalyzedFiles(n.metadata)) {
|
|
248
|
+
candidates.add(f.replace(/\\/g, '/'));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (candidates.size === 0)
|
|
254
|
+
return [];
|
|
255
|
+
const extractedSymbolsByFile = new Map();
|
|
256
|
+
const extractedLinesByFile = new Map();
|
|
257
|
+
for (const n of graph.nodes) {
|
|
258
|
+
if ((n.scope ?? 'USER') !== 'USER')
|
|
259
|
+
continue;
|
|
260
|
+
const isContract = n.type === 'CONTRACT';
|
|
261
|
+
const isCodeBoundary = n.type === 'BOUNDARY' && (n.entityType === 'CLASS' || n.entityType === 'NAMESPACE');
|
|
262
|
+
if (!isContract && !isCodeBoundary)
|
|
263
|
+
continue;
|
|
264
|
+
const syms = extractSymbolFromNodeName(n);
|
|
265
|
+
const orig = n.metadata?.originalName;
|
|
266
|
+
if (typeof orig === 'string' && orig.length > 0)
|
|
267
|
+
syms.push(orig);
|
|
268
|
+
const comp = n.metadata?.componentName;
|
|
269
|
+
if (typeof comp === 'string' && comp.length > 0)
|
|
270
|
+
syms.push(comp);
|
|
271
|
+
const evList = Array.isArray(n.evidence) ? n.evidence : n.evidence ? [n.evidence] : [];
|
|
272
|
+
for (const ev of evList) {
|
|
273
|
+
if (!ev || typeof ev.filePath !== 'string')
|
|
274
|
+
continue;
|
|
275
|
+
const fp = ev.filePath.replace(/\\/g, '/');
|
|
276
|
+
let symSet = extractedSymbolsByFile.get(fp);
|
|
277
|
+
if (!symSet) {
|
|
278
|
+
symSet = new Set();
|
|
279
|
+
extractedSymbolsByFile.set(fp, symSet);
|
|
280
|
+
}
|
|
281
|
+
for (const s of syms)
|
|
282
|
+
symSet.add(s);
|
|
283
|
+
if (typeof ev.lineNumber === 'number') {
|
|
284
|
+
let lineSet = extractedLinesByFile.get(fp);
|
|
285
|
+
if (!lineSet) {
|
|
286
|
+
lineSet = new Set();
|
|
287
|
+
extractedLinesByFile.set(fp, lineSet);
|
|
288
|
+
}
|
|
289
|
+
lineSet.add(ev.lineNumber);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const results = [];
|
|
294
|
+
const sortedFiles = [...candidates].sort();
|
|
295
|
+
for (const relFile of sortedFiles) {
|
|
296
|
+
const absFile = path.resolve(rootDir, relFile);
|
|
297
|
+
if (!fs.existsSync(absFile))
|
|
298
|
+
continue;
|
|
299
|
+
let sf;
|
|
300
|
+
try {
|
|
301
|
+
sf =
|
|
302
|
+
getCachedSourceFile(absFile) ??
|
|
303
|
+
ts.createSourceFile(absFile, preprocessAstroOrMdxSource(absFile, fs.readFileSync(absFile, 'utf8')), ts.ScriptTarget.Latest, true, /\.(?:astro|mdx|vue|svelte)$/i.test(absFile) ? ts.ScriptKind.TSX : undefined);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const symSet = extractedSymbolsByFile.get(relFile) ?? new Set();
|
|
309
|
+
const lineSet = extractedLinesByFile.get(relFile) ?? new Set();
|
|
310
|
+
const hasExtractedInSpan = (node) => {
|
|
311
|
+
const startLine = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
312
|
+
const endLine = sf.getLineAndCharacterOfPosition(node.getEnd()).line + 1;
|
|
313
|
+
for (const l of lineSet) {
|
|
314
|
+
if (l >= startLine && l <= endLine)
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
};
|
|
319
|
+
const makeSnippet = (node) => {
|
|
320
|
+
const startLine = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
321
|
+
const snippet = node.getText(sf).slice(0, 80).replace(/\s+/g, ' ').trim();
|
|
322
|
+
return { lineNumber: startLine, snippet };
|
|
323
|
+
};
|
|
324
|
+
for (const stmt of sf.statements) {
|
|
325
|
+
const modifiers = stmt.modifiers;
|
|
326
|
+
const hasExport = Boolean(modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword));
|
|
327
|
+
if (ts.isVariableStatement(stmt) && hasExport) {
|
|
328
|
+
if (hasExtractedInSpan(stmt))
|
|
329
|
+
continue;
|
|
330
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
331
|
+
if (!decl.initializer || isScalarOrLiteralArray(decl.initializer))
|
|
332
|
+
continue;
|
|
333
|
+
const names = [];
|
|
334
|
+
if (ts.isIdentifier(decl.name)) {
|
|
335
|
+
names.push(decl.name.text);
|
|
336
|
+
}
|
|
337
|
+
else if (ts.isObjectBindingPattern(decl.name)) {
|
|
338
|
+
for (const el of decl.name.elements) {
|
|
339
|
+
if (ts.isBindingElement(el) && ts.isIdentifier(el.name)) {
|
|
340
|
+
names.push(el.name.text);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (names.length > 0 && names.every((n) => !symSet.has(n))) {
|
|
345
|
+
const { lineNumber, snippet } = makeSnippet(stmt);
|
|
346
|
+
results.push({
|
|
347
|
+
filePath: relFile,
|
|
348
|
+
lineNumber,
|
|
349
|
+
exportName: names.join(', '),
|
|
350
|
+
exportSyntax: classifyExportInitializerSyntax(decl.initializer),
|
|
351
|
+
snippet,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else if (ts.isExportAssignment(stmt) && !stmt.isExportEquals) {
|
|
357
|
+
if (symSet.has('default') || hasExtractedInSpan(stmt))
|
|
358
|
+
continue;
|
|
359
|
+
if (isScalarOrLiteralArray(stmt.expression))
|
|
360
|
+
continue;
|
|
361
|
+
const unwrapped = unwrapTypeAssertions(stmt.expression);
|
|
362
|
+
if (ts.isIdentifier(unwrapped) && symSet.has(unwrapped.text))
|
|
363
|
+
continue;
|
|
364
|
+
const { lineNumber, snippet } = makeSnippet(stmt);
|
|
365
|
+
results.push({
|
|
366
|
+
filePath: relFile,
|
|
367
|
+
lineNumber,
|
|
368
|
+
exportName: 'default',
|
|
369
|
+
exportSyntax: classifyExportInitializerSyntax(stmt.expression),
|
|
370
|
+
snippet,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return results;
|
|
376
|
+
}
|
|
377
|
+
function patternIdsForConventionSet(conventionSetId) {
|
|
378
|
+
const ids = new Set();
|
|
379
|
+
const set = CONVENTION_SETS.find((s) => s.framework === conventionSetId);
|
|
380
|
+
if (!set)
|
|
381
|
+
return ids;
|
|
382
|
+
for (const r of set.rules) {
|
|
383
|
+
ids.add(r.emit.patternId);
|
|
384
|
+
if (r.emit.companionRelationship) {
|
|
385
|
+
ids.add(r.emit.companionRelationship.patternId);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
for (const er of set.edgeRules ?? []) {
|
|
389
|
+
ids.add(er.emit.patternId);
|
|
390
|
+
}
|
|
391
|
+
if (conventionSetId === 'react') {
|
|
392
|
+
ids.add('contract.react-functional-component');
|
|
393
|
+
ids.add('contract.react-context');
|
|
394
|
+
ids.add('contract.styled-component');
|
|
395
|
+
}
|
|
396
|
+
else if (conventionSetId === 'astro') {
|
|
397
|
+
ids.add('contract.astro-svg-component-import');
|
|
398
|
+
}
|
|
399
|
+
return ids;
|
|
400
|
+
}
|
|
401
|
+
function getEntityFilePaths(entity) {
|
|
402
|
+
const ev = entity.evidence;
|
|
403
|
+
if (!ev)
|
|
404
|
+
return [];
|
|
405
|
+
const list = Array.isArray(ev) ? ev : [ev];
|
|
406
|
+
return list
|
|
407
|
+
.map((r) => (typeof r?.filePath === 'string' ? r.filePath.replace(/\\/g, '/') : ''))
|
|
408
|
+
.filter(Boolean);
|
|
409
|
+
}
|
|
410
|
+
function pathBelongsToPackage(filePath, relPkgPath) {
|
|
411
|
+
if (relPkgPath === '.' || relPkgPath === '')
|
|
412
|
+
return true;
|
|
413
|
+
const normFile = filePath.replace(/\\/g, '/');
|
|
414
|
+
const normPkg = relPkgPath.replace(/\\/g, '/').replace(/\/+$/, '');
|
|
415
|
+
return normFile === normPkg || normFile.startsWith(`${normPkg}/`);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Evaluates a repository's `package.json` dependencies and convention configs against the extracted
|
|
419
|
+
* `RepresentationGraph` to surface accuracy warnings for unhandled frameworks, suspected custom
|
|
420
|
+
* conventions (0 framework contracts extracted despite the framework dependency), and dynamic
|
|
421
|
+
* convention config values.
|
|
422
|
+
*/
|
|
423
|
+
export function auditFrameworkCoverage(repoRoot, graph, excludeWorkspaces = []) {
|
|
424
|
+
const absRoot = path.resolve(repoRoot);
|
|
425
|
+
const rootDir = fs.existsSync(absRoot) && fs.statSync(absRoot).isFile()
|
|
426
|
+
? path.dirname(absRoot)
|
|
427
|
+
: absRoot;
|
|
428
|
+
const registry = buildWorkspaceRegistry(rootDir);
|
|
429
|
+
const excludedSet = new Set(excludeWorkspaces.map((w) => w.trim()).filter(Boolean));
|
|
430
|
+
const entries = Object.entries(registry);
|
|
431
|
+
const packageTargets = [];
|
|
432
|
+
if (entries.length === 0) {
|
|
433
|
+
const rootPkgJson = path.join(rootDir, 'package.json');
|
|
434
|
+
let rootName = path.basename(rootDir);
|
|
435
|
+
if (fs.existsSync(rootPkgJson)) {
|
|
436
|
+
try {
|
|
437
|
+
const parsed = JSON.parse(fs.readFileSync(rootPkgJson, 'utf8'));
|
|
438
|
+
if (parsed.name)
|
|
439
|
+
rootName = parsed.name;
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
// ignore
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
packageTargets.push({ name: rootName, relPath: '.', absPath: rootDir });
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
for (const [name, absPath] of entries) {
|
|
449
|
+
const relPath = path.relative(rootDir, absPath).replace(/\\/g, '/') || '.';
|
|
450
|
+
const shortName = name.replace(/^@[^/]+\//, '');
|
|
451
|
+
if (excludedSet.has(name) ||
|
|
452
|
+
excludedSet.has(relPath) ||
|
|
453
|
+
excludedSet.has(shortName)) {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
packageTargets.push({ name, relPath, absPath });
|
|
457
|
+
}
|
|
458
|
+
packageTargets.sort((a, b) => a.relPath.localeCompare(b.relPath));
|
|
459
|
+
}
|
|
460
|
+
const packages = [];
|
|
461
|
+
const warnings = [];
|
|
462
|
+
for (const pkg of packageTargets) {
|
|
463
|
+
const pkgJsonPath = path.join(pkg.absPath, 'package.json');
|
|
464
|
+
const matchedRules = detectFrameworkRulesFromPackageJson(pkgJsonPath);
|
|
465
|
+
const frameworks = detectFrameworksFromPackageJson(pkgJsonPath);
|
|
466
|
+
const supportedAdapters = matchedRules
|
|
467
|
+
.filter((r) => r.category === 'framework-adapter')
|
|
468
|
+
.map((r) => r.label);
|
|
469
|
+
const unhandledFrameworks = matchedRules
|
|
470
|
+
.filter((r) => r.category === 'unhandled-framework')
|
|
471
|
+
.map((r) => r.label);
|
|
472
|
+
packages.push({
|
|
473
|
+
packageName: pkg.name,
|
|
474
|
+
packagePath: pkg.relPath,
|
|
475
|
+
frameworks,
|
|
476
|
+
supportedAdapters,
|
|
477
|
+
unhandledFrameworks,
|
|
478
|
+
});
|
|
479
|
+
// 1. Accuracy warning for unhandled frameworks
|
|
480
|
+
for (const rule of matchedRules) {
|
|
481
|
+
if (rule.category === 'unhandled-framework') {
|
|
482
|
+
warnings.push({
|
|
483
|
+
kind: 'UNHANDLED_FRAMEWORK',
|
|
484
|
+
packageName: pkg.name,
|
|
485
|
+
packagePath: pkg.relPath,
|
|
486
|
+
framework: rule.label,
|
|
487
|
+
message: `Package "${pkg.name}" (${pkg.relPath}) depends on ${rule.label}, which has no dedicated convention adapter yet. Generic TypeScript/ES module structure is extracted, but ${rule.label}-specific conventions may be missing.`,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
// 2. Coverage check for supported framework adapters
|
|
492
|
+
const pkgNodes = graph.nodes.filter((n) => (n.scope ?? 'USER') === 'USER' &&
|
|
493
|
+
n.entityType !== 'DEPLOYMENT_UNIT' &&
|
|
494
|
+
n.type !== 'OPEN_CONNECTOR' &&
|
|
495
|
+
getEntityFilePaths(n).some((fp) => pathBelongsToPackage(fp, pkg.relPath)));
|
|
496
|
+
const pkgEdges = graph.edges.filter((e) => (e.scope ?? 'USER') === 'USER' &&
|
|
497
|
+
getEntityFilePaths(e).some((fp) => pathBelongsToPackage(fp, pkg.relPath)));
|
|
498
|
+
const pkgConnectorNodes = graph.nodes.filter((n) => (n.scope ?? 'USER') === 'USER' &&
|
|
499
|
+
n.type === 'OPEN_CONNECTOR' &&
|
|
500
|
+
getEntityFilePaths(n).some((fp) => pathBelongsToPackage(fp, pkg.relPath)));
|
|
501
|
+
if (pkgNodes.length > 0) {
|
|
502
|
+
for (const rule of matchedRules) {
|
|
503
|
+
if (rule.category !== 'framework-adapter' || !rule.conventionSetId)
|
|
504
|
+
continue;
|
|
505
|
+
const patternIds = patternIdsForConventionSet(rule.conventionSetId);
|
|
506
|
+
const astroPageNodeCount = rule.conventionSetId === 'astro'
|
|
507
|
+
? pkgNodes.filter((n) => getEntityFilePaths(n).some((fp) => fp.toLowerCase().endsWith('.astro'))).length
|
|
508
|
+
: 0;
|
|
509
|
+
const matchCount = pkgNodes.filter((n) => patternIds.has(n.patternId)).length +
|
|
510
|
+
pkgEdges.filter((e) => patternIds.has(e.patternId)).length +
|
|
511
|
+
astroPageNodeCount;
|
|
512
|
+
if (matchCount === 0) {
|
|
513
|
+
let runtimeDeps = new Set();
|
|
514
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
515
|
+
try {
|
|
516
|
+
const parsedPkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
|
517
|
+
runtimeDeps = new Set(Object.keys(parsedPkg.dependencies ?? {}));
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
// ignore
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const isRuntimeDep = rule.deps.some((d) => runtimeDeps.has(d));
|
|
524
|
+
const hasFrameworkImport = pkgConnectorNodes.some((n) => rule.deps.some((dep) => n.name === `Package: ${dep}` || n.name.startsWith(`Package: ${dep}/`)));
|
|
525
|
+
// Skip warning if the framework is only declared in peerDependencies / devDependencies
|
|
526
|
+
// (e.g. a plugin or optional integration) and never imported at runtime, or if the
|
|
527
|
+
// package never imports any of the framework's packages when package connectors exist.
|
|
528
|
+
if (!isRuntimeDep && !hasFrameworkImport)
|
|
529
|
+
continue;
|
|
530
|
+
if ((packageTargets.length > 1 || pkgConnectorNodes.length > 0) && !hasFrameworkImport) {
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (rule.conventionSetId === 'mcp') {
|
|
534
|
+
const mcpEvSnippets = pkgConnectorNodes
|
|
535
|
+
.filter((n) => n.name === 'Package: @modelcontextprotocol/sdk' ||
|
|
536
|
+
n.name.startsWith('Package: @modelcontextprotocol/sdk/'))
|
|
537
|
+
.flatMap((n) => Array.isArray(n.evidence) ? n.evidence : n.evidence ? [n.evidence] : [])
|
|
538
|
+
.map((ev) => (typeof ev?.snippet === 'string' ? ev.snippet : ''))
|
|
539
|
+
.filter(Boolean);
|
|
540
|
+
if (mcpEvSnippets.length > 0 &&
|
|
541
|
+
mcpEvSnippets.every((s) => s.includes('@modelcontextprotocol/sdk/client')) &&
|
|
542
|
+
!mcpEvSnippets.some((s) => s.includes('@modelcontextprotocol/sdk/server'))) {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
warnings.push({
|
|
547
|
+
kind: 'SUSPECTED_CUSTOM_CONVENTION',
|
|
548
|
+
packageName: pkg.name,
|
|
549
|
+
packagePath: pkg.relPath,
|
|
550
|
+
framework: rule.label,
|
|
551
|
+
conventionSetId: rule.conventionSetId,
|
|
552
|
+
message: `Package "${pkg.name}" (${pkg.relPath}) declares ${rule.label} (convention set "${rule.conventionSetId}"), but 0 ${rule.label} conventions were extracted across ${pkgNodes.length} entities. Check for custom wrappers or non-standard directory conventions.`,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
// 3. Check for statically unresolved convention configs (e.g. dynamic `pageExtensions` in `next.config.js`)
|
|
559
|
+
const configResolver = createConventionConfigResolver(rootDir);
|
|
560
|
+
for (const set of CONVENTION_SETS) {
|
|
561
|
+
if (!set.extensionConfig)
|
|
562
|
+
continue;
|
|
563
|
+
for (const pkg of packageTargets) {
|
|
564
|
+
const probeFile = path.join(pkg.absPath, 'index.ts');
|
|
565
|
+
configResolver.extensionsFor(set, probeFile);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const seenConfigKeys = new Set();
|
|
569
|
+
for (const unres of configResolver.unresolved) {
|
|
570
|
+
const dedupKey = `${unres.framework}:${unres.file}:${unres.key}`;
|
|
571
|
+
if (seenConfigKeys.has(dedupKey))
|
|
572
|
+
continue;
|
|
573
|
+
seenConfigKeys.add(dedupKey);
|
|
574
|
+
warnings.push({
|
|
575
|
+
kind: 'UNRESOLVED_CONVENTION_CONFIG',
|
|
576
|
+
packageName: path.basename(rootDir),
|
|
577
|
+
packagePath: path.dirname(unres.file) || '.',
|
|
578
|
+
framework: unres.framework,
|
|
579
|
+
conventionSetId: unres.framework,
|
|
580
|
+
configFile: unres.file,
|
|
581
|
+
configKey: unres.key,
|
|
582
|
+
message: `Convention config "${unres.key}" in ${unres.file} (${unres.framework}) is not a static string-literal array (${unres.reason}); falling back to default extensions.`,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
const darkFiles = findDarkFiles(graph);
|
|
586
|
+
const unextractedExports = findUnextractedExports(rootDir, graph);
|
|
587
|
+
return { packages, warnings, darkFiles, unextractedExports };
|
|
588
|
+
}
|