@ngcompass/engine 0.1.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +578 -0
- package/dist/index.d.ts +578 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { RuleContext, RuleFailure, RuleMetadata, InfrastructureErrorCollector, RuleResult, TemplateAst, StyleAst, ProjectContext, ParserOptions, Result, AnalysisResult, ComponentFiles } from '@ngcompass/common';
|
|
2
|
+
import { AnyAngularClassNode, CallExpression, AngularClassNode, DecoratedPropertyNode, NewExpression, TemplateAttributeNode, TemplateBlockNode, TemplateExpressionNode, TemplateAnalysis } from '@ngcompass/ast';
|
|
3
|
+
import { Program } from 'oxc-parser';
|
|
4
|
+
import ts, { TypeChecker } from 'typescript';
|
|
5
|
+
import { ExecutionPlanOutput, Task } from '@ngcompass/planner';
|
|
6
|
+
import { CacheContext } from '@ngcompass/cache';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview
|
|
10
|
+
* Facilitates the definition of analytical rules as passive observers.
|
|
11
|
+
*
|
|
12
|
+
* Rules implemented via this interface are designed for maximum performance,
|
|
13
|
+
* operating on pre-filtered node streams without performing independent
|
|
14
|
+
* AST traversals or resource allocations.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
type StreamType = 'AngularClass' | 'AnyAngularClass' | 'DecoratedProperty' | 'TemplateExpression' | 'TemplateAttribute' | 'TemplateBlock' | 'Template' | 'CallExpression' | 'NewExpression';
|
|
18
|
+
/**
|
|
19
|
+
* Rule handler for a specific stream type.
|
|
20
|
+
*
|
|
21
|
+
* @template TNode - Node type from stream (pre-filtered, pre-analyzed)
|
|
22
|
+
*/
|
|
23
|
+
interface RuleHandler<TNode> {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly streamType: StreamType;
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates a node from a pre-filtered analytical stream.
|
|
28
|
+
*
|
|
29
|
+
* Implementation must adhere to strict performance constraints, ensuring
|
|
30
|
+
* O(1) or near-constant time complexity and zero memory allocation.
|
|
31
|
+
*
|
|
32
|
+
* @param node The pre-analyzed AST node to evaluate.
|
|
33
|
+
* @param context The analytical context for the current file.
|
|
34
|
+
* @returns A rule failure, a collection of failures, or null if compliant.
|
|
35
|
+
*/
|
|
36
|
+
handle(node: TNode, context: RuleContext): RuleFailure | RuleFailure[] | null;
|
|
37
|
+
readonly meta?: Partial<RuleMetadata>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Helper to create component rule handlers.
|
|
41
|
+
*/
|
|
42
|
+
declare const createComponentRule: (name: string, handler: (node: AngularClassNode, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<AngularClassNode>;
|
|
43
|
+
/**
|
|
44
|
+
* Helper to create rules that handle ANY Angular-decorated class:
|
|
45
|
+
* @Component, @Directive, @Pipe, @Injectable, @NgModule.
|
|
46
|
+
*
|
|
47
|
+
* Use this instead of createComponentRule when the rule applies to
|
|
48
|
+
* classes beyond just @Component and @Directive.
|
|
49
|
+
*/
|
|
50
|
+
declare const createAnyAngularClassRule: (name: string, handler: (node: AnyAngularClassNode, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<AnyAngularClassNode>;
|
|
51
|
+
/**
|
|
52
|
+
* Helper to create decorated property rule handlers.
|
|
53
|
+
*/
|
|
54
|
+
declare const createDecoratedPropertyRule: (name: string, handler: (node: DecoratedPropertyNode, context: RuleContext) => RuleFailure | RuleFailure[] | null) => RuleHandler<DecoratedPropertyNode>;
|
|
55
|
+
/**
|
|
56
|
+
* Helper to create template expression rule handlers.
|
|
57
|
+
*/
|
|
58
|
+
declare const createTemplateExpressionRule: (name: string, handler: (node: TemplateExpressionNode, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<TemplateExpressionNode>;
|
|
59
|
+
/**
|
|
60
|
+
* Helper to create template attribute rule handlers.
|
|
61
|
+
*/
|
|
62
|
+
declare const createTemplateAttributeRule: (name: string, handler: (node: TemplateAttributeNode, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<TemplateAttributeNode>;
|
|
63
|
+
/**
|
|
64
|
+
* Helper to create call expression rule handlers.
|
|
65
|
+
*
|
|
66
|
+
* Receives every CallExpression node in the file's AST exactly once.
|
|
67
|
+
* The handler is responsible for its own callee-shape filtering
|
|
68
|
+
* (e.g. checking for a StaticMemberExpression callee and a specific method name).
|
|
69
|
+
*/
|
|
70
|
+
declare const createCallExpressionRule: (name: string, handler: (node: CallExpression, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<CallExpression>;
|
|
71
|
+
/**
|
|
72
|
+
* Helper to create new expression rule handlers.
|
|
73
|
+
*/
|
|
74
|
+
declare const createNewExpressionRule: (name: string, handler: (node: NewExpression, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<NewExpression>;
|
|
75
|
+
/**
|
|
76
|
+
* Helper to create template block rule handlers.
|
|
77
|
+
*/
|
|
78
|
+
declare const createTemplateBlockRule: (name: string, handler: (node: TemplateBlockNode, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<TemplateBlockNode>;
|
|
79
|
+
/**
|
|
80
|
+
* Helper to create template rules that receive the full template analysis.
|
|
81
|
+
*/
|
|
82
|
+
declare const createTemplateRule: (name: string, handler: (node: TemplateAnalysis, context: RuleContext) => RuleFailure | RuleFailure[] | null, meta?: Partial<RuleMetadata>) => RuleHandler<TemplateAnalysis>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @fileoverview
|
|
86
|
+
* Implements a high-performance visitor registry for O(1) node dispatch.
|
|
87
|
+
*
|
|
88
|
+
* This module facilitates the routing of AST nodes to their respective rule
|
|
89
|
+
* handlers by utilizing a static dispatch table, significantly optimizing the
|
|
90
|
+
* throughput of the single-pass engine.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Compile-time exhaustiveness check.
|
|
95
|
+
* Every StreamType MUST have an entry here.
|
|
96
|
+
* Template streams use a sentinel prefix '__' — they are dispatched
|
|
97
|
+
* separately after the main AST walk and are skipped in buildVisitorMap.
|
|
98
|
+
*/
|
|
99
|
+
type StreamToNodeType = {
|
|
100
|
+
[K in StreamType]: string;
|
|
101
|
+
};
|
|
102
|
+
declare const STREAM_TO_NODE_TYPE: StreamToNodeType;
|
|
103
|
+
/**
|
|
104
|
+
* A visitor entry bundles:
|
|
105
|
+
* - the raw-node → stream-node filter function
|
|
106
|
+
* - the rule handler
|
|
107
|
+
* - failure collection reference
|
|
108
|
+
* - per-rule timing reference
|
|
109
|
+
*
|
|
110
|
+
* This avoids closure allocation on the hot path by pre-binding everything
|
|
111
|
+
* at registry build time.
|
|
112
|
+
*/
|
|
113
|
+
interface VisitorEntry {
|
|
114
|
+
/** Rule name (for failure collection and timing) */
|
|
115
|
+
readonly ruleName: string;
|
|
116
|
+
/** Converts raw Oxc node → typed stream node (or null if not applicable) */
|
|
117
|
+
readonly filter: (rawNode: any) => unknown;
|
|
118
|
+
/** The rule handler's handle function (pre-bound) */
|
|
119
|
+
readonly handle: (streamNode: any, ctx: RuleContext) => RuleFailure | RuleFailure[] | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Maps Oxc node.type → array of VisitorEntry.
|
|
123
|
+
* Lookup is O(1) (Map.get), dispatch is O(H) where H = handlers for that type.
|
|
124
|
+
*/
|
|
125
|
+
type VisitorMap = ReadonlyMap<string, ReadonlyArray<VisitorEntry>>;
|
|
126
|
+
/**
|
|
127
|
+
* Constructs a high-speed dispatch map from a collection of rule handlers.
|
|
128
|
+
*
|
|
129
|
+
* @param handlers A collection of rule handlers to include in the registry.
|
|
130
|
+
* @param streamFilters A mapping of stream types to their respective node filters.
|
|
131
|
+
* @returns A read-only VisitorMap optimized for O(1) lookup.
|
|
132
|
+
*/
|
|
133
|
+
declare function buildVisitorMap(handlers: ReadonlyArray<RuleHandler<any>>, streamFilters: Partial<Record<StreamType, (rawNode: any) => unknown>>): VisitorMap;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @fileoverview
|
|
137
|
+
* Implements the performance-optimized single-pass analytical engine.
|
|
138
|
+
*
|
|
139
|
+
* This component is designed for maximum throughput, performing exactly one
|
|
140
|
+
* traversal of the Abstract Syntax Tree (AST) while dispatching nodes to
|
|
141
|
+
* passive observers via an O(1) visitor infrastructure.
|
|
142
|
+
*
|
|
143
|
+
* Key Performance Characteristics:
|
|
144
|
+
* - Linear Complexity: O(N) traversal in relation to the number of AST nodes.
|
|
145
|
+
* - Optimized Dispatch: Leverages a high-speed visitor map for node-type routing.
|
|
146
|
+
* - Resource Efficiency: Maintains strict execution budgets for individual rules.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
interface RuleTiming {
|
|
150
|
+
ruleName: string;
|
|
151
|
+
totalMs: number;
|
|
152
|
+
invocations: number;
|
|
153
|
+
}
|
|
154
|
+
interface PerformanceReport {
|
|
155
|
+
traversalMs: number;
|
|
156
|
+
nodesVisited: number;
|
|
157
|
+
ruleTimings: RuleTiming[];
|
|
158
|
+
cacheStats: {
|
|
159
|
+
hits: number;
|
|
160
|
+
misses: number;
|
|
161
|
+
};
|
|
162
|
+
budgetViolations: string[];
|
|
163
|
+
hasBudgetViolations: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Executes a comprehensive analytical pass over a provided AST program.
|
|
167
|
+
*
|
|
168
|
+
* @param rules A collection of rule handlers to evaluate during the pass.
|
|
169
|
+
* @param context The analytical context containing the program and metadata.
|
|
170
|
+
* @param options Operational configuration, including error collection.
|
|
171
|
+
* @returns A consolidated result set and performance diagnostic report.
|
|
172
|
+
*/
|
|
173
|
+
declare const runSinglePassAnalysis: (rules: ReadonlyArray<RuleHandler<any>>, context: RuleContext, options?: {
|
|
174
|
+
errorCollector?: InfrastructureErrorCollector;
|
|
175
|
+
}) => {
|
|
176
|
+
results: RuleResult[];
|
|
177
|
+
performance: PerformanceReport;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @fileoverview
|
|
182
|
+
* Provides the RuleContextFactory for initializing rule execution contexts.
|
|
183
|
+
*
|
|
184
|
+
* This component is responsible for aggregating various analytical artifacts—including
|
|
185
|
+
* file content, AST structures, type information, and project metadata—into a
|
|
186
|
+
* unified RuleContext suitable for rule evaluation.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Defines the operational boundaries for context construction.
|
|
191
|
+
* Encapsulates resource access requirements for both main-thread and worker-thread execution.
|
|
192
|
+
*/
|
|
193
|
+
interface ExecutionContext {
|
|
194
|
+
readonly rootDir: string;
|
|
195
|
+
readonly readFile: (filePath: string) => Promise<string>;
|
|
196
|
+
readonly getProgram: (filePath: string) => Promise<Program>;
|
|
197
|
+
readonly getTypeChecker?: (filePath: string) => Promise<TypeChecker | undefined>;
|
|
198
|
+
readonly getTemplate: (filePath: string) => Promise<TemplateAst | undefined>;
|
|
199
|
+
readonly getStyle: (filePath: string) => Promise<StyleAst | undefined>;
|
|
200
|
+
/**
|
|
201
|
+
* Retrieves the project-wide analytical context, if available.
|
|
202
|
+
*/
|
|
203
|
+
readonly getProjectContext?: () => ProjectContext | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Retrieves the TypeScript SourceFile representation for a given path.
|
|
206
|
+
*/
|
|
207
|
+
readonly getTsSourceFile?: (filePath: string) => ts.SourceFile | undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Orschestrates the assembly of fully-resolved RuleContext objects.
|
|
211
|
+
*
|
|
212
|
+
* Decouples the rule execution logic from the underlying storage and retrieval
|
|
213
|
+
* mechanisms by utilizing the ExecutionContext abstraction.
|
|
214
|
+
*/
|
|
215
|
+
declare class RuleContextFactory {
|
|
216
|
+
private readonly context;
|
|
217
|
+
constructor(context: ExecutionContext);
|
|
218
|
+
/**
|
|
219
|
+
* Builds a RuleContext for the given file.
|
|
220
|
+
*
|
|
221
|
+
* @param filePath - Absolute path to the file being analysed
|
|
222
|
+
* @param options - Rule-specific options from the configuration
|
|
223
|
+
* @param needsTemplate - Whether the rule(s) in this batch require the template
|
|
224
|
+
* @returns A fully resolved RuleContext
|
|
225
|
+
*/
|
|
226
|
+
build(filePath: string, options: Record<string, unknown>, needsTemplate: boolean): Promise<RuleContext>;
|
|
227
|
+
/**
|
|
228
|
+
* Builds a `ComponentCrossRef` for the given file path when that file is
|
|
229
|
+
* either a `.component.ts` class or its associated template.
|
|
230
|
+
*
|
|
231
|
+
* Returns `undefined` for all other file types.
|
|
232
|
+
*/
|
|
233
|
+
private resolveExternalTemplatePath;
|
|
234
|
+
private buildCrossRef;
|
|
235
|
+
private getComponentSourceFile;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @fileoverview
|
|
240
|
+
* Provides the AnalysisContext abstraction for ngcompass.
|
|
241
|
+
*
|
|
242
|
+
* This module facilitates deterministic, memoized access to file system resources
|
|
243
|
+
* and abstract syntax tree (AST) artifacts, ensuring peak performance during
|
|
244
|
+
* analysis by minimizing redundant I/O and parsing operations.
|
|
245
|
+
*
|
|
246
|
+
* Implementation Strategy:
|
|
247
|
+
* - Memoization: Caches raw file content, TypeScript Programs, Template ASTs, and Style ASTs.
|
|
248
|
+
* - Resource Management: Implements an explicit eviction mechanism to control heap usage.
|
|
249
|
+
* - Determinism: Ensures the same file path always yields consistent artifacts across a run.
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Encapsulates the state and logic required for analyzing a set of source files.
|
|
254
|
+
* Provides unified access to file content and parsed metadata with internal memoization.
|
|
255
|
+
*/
|
|
256
|
+
interface AnalysisContext {
|
|
257
|
+
readonly rootDir: string;
|
|
258
|
+
readonly readFile: (filePath: string) => Promise<string>;
|
|
259
|
+
readonly getProgram: (filePath: string) => Promise<Program>;
|
|
260
|
+
readonly getTemplate: (filePath: string) => Promise<TemplateAst | undefined>;
|
|
261
|
+
readonly getStyle: (filePath: string) => Promise<StyleAst | undefined>;
|
|
262
|
+
/**
|
|
263
|
+
* Purges all cached artifacts associated with the specified file path.
|
|
264
|
+
*
|
|
265
|
+
* This method is critical for memory governance in large-scale repositories.
|
|
266
|
+
* It should be invoked immediately upon completion of a file's analysis tasks
|
|
267
|
+
* to release references to raw strings and AST structures, enabling garbage
|
|
268
|
+
* collection.
|
|
269
|
+
*
|
|
270
|
+
* @param filePath The path of the file to evict from internal caches.
|
|
271
|
+
*/
|
|
272
|
+
readonly evict: (filePath: string) => void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Instantiates an AnalysisContext provider with integrated memoization logic.
|
|
276
|
+
*
|
|
277
|
+
* @param rootDir The base directory used to resolve relative file transitions.
|
|
278
|
+
* @returns A stateful AnalysisContext instance.
|
|
279
|
+
*/
|
|
280
|
+
declare const createAnalysisContext: (rootDir: string) => AnalysisContext;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @fileoverview
|
|
284
|
+
* Implements the high-level analysis orchestration pipeline.
|
|
285
|
+
*
|
|
286
|
+
* The orchestrator manages the lifecycle of an analysis run, coordinating
|
|
287
|
+
* task distribution across local threads and worker pools, while managing
|
|
288
|
+
* analytical state, result aggregation, and caching strategies.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
interface AnalysisFileProgress {
|
|
292
|
+
readonly filePath: string;
|
|
293
|
+
readonly taskCount: number;
|
|
294
|
+
readonly issueCount: number;
|
|
295
|
+
readonly errorCount: number;
|
|
296
|
+
readonly warningCount: number;
|
|
297
|
+
readonly duration: number;
|
|
298
|
+
readonly cached?: boolean;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Configuration parameters for the analysis orchestration process.
|
|
303
|
+
*/
|
|
304
|
+
interface AnalysisOptions {
|
|
305
|
+
/** Root directory for resolving file paths */
|
|
306
|
+
readonly rootDir: string;
|
|
307
|
+
/** Optional cache context for retrieving skipped task results */
|
|
308
|
+
readonly cache?: CacheContext;
|
|
309
|
+
/** Enable debug logging */
|
|
310
|
+
readonly debug?: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Maximum number of worker threads to use.
|
|
313
|
+
* Clamped to [1, os.cpus().length] (RFC §7.3 unified concurrency model).
|
|
314
|
+
* Defaults to os.cpus().length.
|
|
315
|
+
*/
|
|
316
|
+
readonly maxWorkers?: number;
|
|
317
|
+
/**
|
|
318
|
+
* Number of tasks above which the worker pool is used instead of local
|
|
319
|
+
* pLimit execution. Default: 150.
|
|
320
|
+
*/
|
|
321
|
+
readonly parallelThreshold?: number;
|
|
322
|
+
/**
|
|
323
|
+
* Integrates an optional infrastructure error sink.
|
|
324
|
+
* When provided, operational errors are encapsulated and reported through
|
|
325
|
+
* this collector instead of triggering terminal exceptions.
|
|
326
|
+
*/
|
|
327
|
+
readonly errorCollector?: InfrastructureErrorCollector;
|
|
328
|
+
/**
|
|
329
|
+
* All files discovered by the scanner for this run.
|
|
330
|
+
*
|
|
331
|
+
* CTX-001: Forwarded to `createTypeAwareAnalysisContext()` so the
|
|
332
|
+
* `ProjectContext` import-graph builder can restrict edges to intra-project
|
|
333
|
+
* imports and correctly populate `ProjectContext.projectFiles`.
|
|
334
|
+
*
|
|
335
|
+
* Optional for backward compatibility — when omitted the ProjectContext
|
|
336
|
+
* will still be built but `projectFiles` may be less complete (derived
|
|
337
|
+
* solely from the TypeScript Program's source-file list).
|
|
338
|
+
*/
|
|
339
|
+
readonly files?: ReadonlyArray<string>;
|
|
340
|
+
/** Optional TypeScript parser settings from config. */
|
|
341
|
+
readonly parserOptions?: ParserOptions;
|
|
342
|
+
/**
|
|
343
|
+
* Maximum number of files per type-aware execution chunk.
|
|
344
|
+
*
|
|
345
|
+
* Type-aware tasks run on the main thread with a shared `ts.Program`.
|
|
346
|
+
* For large repos the Program can consume several GB. Chunking splits
|
|
347
|
+
* the work: each chunk creates its own scoped Program, processes its
|
|
348
|
+
* tasks, then lets the Program be garbage-collected before the next chunk
|
|
349
|
+
* starts. Smaller values reduce peak memory; larger values reduce the
|
|
350
|
+
* number of (expensive) `ts.createProgram` calls.
|
|
351
|
+
*
|
|
352
|
+
* Default: 400 files per chunk. Set to `Infinity` to disable chunking.
|
|
353
|
+
*/
|
|
354
|
+
readonly typeAwareChunkSize?: number;
|
|
355
|
+
/**
|
|
356
|
+
* When true, type-checker-dependent rules are skipped entirely.
|
|
357
|
+
* Use this as an escape valve for very large repos where even a chunked
|
|
358
|
+
* TS Program is too memory-intensive to build.
|
|
359
|
+
*/
|
|
360
|
+
readonly skipTypeCheck?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Called whenever a batch of tasks completes.
|
|
363
|
+
* @param completed - Total tasks finished so far (including cached).
|
|
364
|
+
* @param total - Grand total tasks for this run (executed + cached).
|
|
365
|
+
*/
|
|
366
|
+
readonly onProgress?: (completed: number, total: number) => void;
|
|
367
|
+
/** Called whenever all tasks for a file have completed. */
|
|
368
|
+
readonly onFileProgress?: (event: AnalysisFileProgress) => void;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Primary entry point for executing an analysis plan.
|
|
372
|
+
*
|
|
373
|
+
* Coordinates task execution strategies, manages result caching, and
|
|
374
|
+
* synthesizes the final analytical report.
|
|
375
|
+
*
|
|
376
|
+
* @param plan The execution plan containing tasks and cached metadata.
|
|
377
|
+
* @param options Configuration options for the orchestrator.
|
|
378
|
+
* @returns A promise resolving to an AnalysisResult encapsulation.
|
|
379
|
+
*/
|
|
380
|
+
declare const runAnalysis: (plan: ExecutionPlanOutput, options: AnalysisOptions) => Promise<Result<AnalysisResult>>;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* @fileoverview
|
|
384
|
+
* Facilitates the construction of the ProjectContext for ngcompass.
|
|
385
|
+
*
|
|
386
|
+
* This module performs a traversal of the TypeScript module graph to assemble
|
|
387
|
+
* a comprehensive, read-only representation of the project structure. This
|
|
388
|
+
* includes import relationships, component clusters, and Angular-specific
|
|
389
|
+
* metadata (e.g., NgModule declarations).
|
|
390
|
+
*
|
|
391
|
+
* Implementation Strategy:
|
|
392
|
+
* - Efficient Traversal: Analyzes the resolved module graph in O(F + E) time.
|
|
393
|
+
* - Structural Disambiguation: Detects barrel files and component clusters.
|
|
394
|
+
* - Angular Awareness: Integrates decorator metadata for standalone and NgModule discovery.
|
|
395
|
+
*/
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Constructs a ProjectContext immutable structure from a TypeScript Program.
|
|
399
|
+
*
|
|
400
|
+
* @param program The ts.Program instance used for type-aware analysis.
|
|
401
|
+
* @param files A collection of file paths identified during the scanning phase.
|
|
402
|
+
* @param rootDir The absolute path to the project root directory.
|
|
403
|
+
* @param componentFiles An optional mapping of component-related file clusters.
|
|
404
|
+
* @returns A fully initialized ProjectContext instance.
|
|
405
|
+
*/
|
|
406
|
+
declare function buildProjectContext(program: ts.Program, files: ReadonlyArray<string>, rootDir: string, componentFiles?: ReadonlyMap<string, ComponentFiles>): ProjectContext;
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Enhances the baseline AnalysisContext with semantic and project-wide data.
|
|
410
|
+
*/
|
|
411
|
+
interface TypeAwareAnalysisContext extends AnalysisContext {
|
|
412
|
+
/**
|
|
413
|
+
* Retrieves the TypeScript TypeChecker for semantic analysis.
|
|
414
|
+
*/
|
|
415
|
+
readonly getTypeChecker: (filePath: string) => Promise<ts.TypeChecker | undefined>;
|
|
416
|
+
/**
|
|
417
|
+
* Retrieves the pre-built, immutable ProjectContext for the current run.
|
|
418
|
+
*/
|
|
419
|
+
readonly getProjectContext: () => ProjectContext | undefined;
|
|
420
|
+
/**
|
|
421
|
+
* Retrieves the TypeScript SourceFile representation for a given path.
|
|
422
|
+
*/
|
|
423
|
+
readonly getTsSourceFile: (filePath: string) => ts.SourceFile | undefined;
|
|
424
|
+
/**
|
|
425
|
+
* Performs an explicit initialization phase for type-aware resources.
|
|
426
|
+
*/
|
|
427
|
+
readonly warmup: () => Promise<void>;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Initializes a TypeAwareAnalysisContext for the specified root directory.
|
|
431
|
+
*
|
|
432
|
+
* @param rootDir The absolute path to the project root.
|
|
433
|
+
* @param files A collection of file paths identified during the scanning phase.
|
|
434
|
+
* @returns A fully initialized TypeAwareAnalysisContext instance.
|
|
435
|
+
*/
|
|
436
|
+
declare const createTypeAwareAnalysisContext: (rootDir: string, files?: ReadonlyArray<string>, parserOptions?: ParserOptions) => TypeAwareAnalysisContext;
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @fileoverview
|
|
440
|
+
* Provides the core execution runner for ngcompass.
|
|
441
|
+
*
|
|
442
|
+
* This module consolidates the rule execution logic utilized by both local
|
|
443
|
+
* sequential processes and worker-based parallel execution. It manages task
|
|
444
|
+
* batching, result mapping, and operational error handling.
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Executes a collection of analysis tasks for a specific file.
|
|
449
|
+
*
|
|
450
|
+
* Processes tasks by grouping them into optimized execution batches. Utilizes
|
|
451
|
+
* the RuleContextFactory for resource initialization and coordinates with
|
|
452
|
+
* the configured rule executor for evaluation.
|
|
453
|
+
*
|
|
454
|
+
* @param tasks A collection of tasks to execute against a single file path.
|
|
455
|
+
* @param context The operational context providing resource access.
|
|
456
|
+
* @param errorCollector An optional sink for operational error reporting.
|
|
457
|
+
* @returns A promise resolving to a collection of rule execution results.
|
|
458
|
+
*/
|
|
459
|
+
declare const executeBatchedTasks: (tasks: ReadonlyArray<Task>, context: ExecutionContext, errorCollector?: InfrastructureErrorCollector) => Promise<RuleResult[]>;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @fileoverview
|
|
463
|
+
* Establishes a dependency injection boundary for rule execution.
|
|
464
|
+
*
|
|
465
|
+
* This module facilitates the decoupling of the engine's core orchestration layer
|
|
466
|
+
* from the concrete rule implementations, mitigating circular dependency risks.
|
|
467
|
+
*/
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Executes multiple rules in a single AST pass and returns their results.
|
|
471
|
+
* Implemented by rules/src/engine/adapter.ts → executeBatchedNewEngineRules.
|
|
472
|
+
*/
|
|
473
|
+
type BatchRuleExecutorFn = (ruleNames: ReadonlyArray<string>, context: RuleContext) => ReadonlyArray<RuleResult>;
|
|
474
|
+
/**
|
|
475
|
+
* Returns true if a rule with the given name is registered in the engine.
|
|
476
|
+
* Implemented by rules/src/engine/adapter.ts → isNewEngineRule.
|
|
477
|
+
*/
|
|
478
|
+
type RuleCheckerFn = (ruleName: string) => boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Configures the analytical engine with specific rule execution and validation logic.
|
|
481
|
+
*
|
|
482
|
+
* This method must be invoked during the initialization phase of the process
|
|
483
|
+
* to register the underlying rule processing capabilities.
|
|
484
|
+
*
|
|
485
|
+
* @param executor The implementation responsible for batched rule evaluation.
|
|
486
|
+
* @param checker The implementation responsible for rule presence verification.
|
|
487
|
+
*/
|
|
488
|
+
declare const configureRuleExecutor: (executor: BatchRuleExecutorFn, checker: RuleCheckerFn) => void;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* @fileoverview
|
|
492
|
+
* Facilitates the calculation of aggregate analytical metrics.
|
|
493
|
+
*
|
|
494
|
+
* This module provides utilities to derive summary statistics from rule execution
|
|
495
|
+
* results, including file counts, severity distributions, and execution durations.
|
|
496
|
+
*/
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Computes comprehensive analytical statistics based on raw rule results.
|
|
500
|
+
*
|
|
501
|
+
* @param results A collection of rule execution results.
|
|
502
|
+
* @param startTime The high-resolution timestamp indicating the start of execution.
|
|
503
|
+
* @param cacheHitRate An optional precalculated cache hit ratio [0, 1].
|
|
504
|
+
* @returns An object encapsulating the aggregated statistical data.
|
|
505
|
+
*/
|
|
506
|
+
declare const calculateStats: (results: ReadonlyArray<RuleResult>, startTime: number, cacheHitRate?: number) => AnalysisResult["stats"];
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* @fileoverview
|
|
510
|
+
* Defines engine-level constants and performance benchmarks for ngcompass.
|
|
511
|
+
*
|
|
512
|
+
* This module serves as the centralized source of truth for architectural
|
|
513
|
+
* thresholds, concurrency limits, and performance budgets used across the
|
|
514
|
+
* orchestration and execution layers.
|
|
515
|
+
*/
|
|
516
|
+
/**
|
|
517
|
+
* The minimum number of worker threads to maintain in the execution pool,
|
|
518
|
+
* ensuring availability regardless of the host system's CPU topology.
|
|
519
|
+
*/
|
|
520
|
+
declare const MIN_WORKER_COUNT = 2;
|
|
521
|
+
/**
|
|
522
|
+
* The refresh interval for the command-line interface progress visualization.
|
|
523
|
+
*/
|
|
524
|
+
declare const SPINNER_FRAME_INTERVAL_MS = 80;
|
|
525
|
+
/**
|
|
526
|
+
* Maximum wall-clock time a single worker thread is allowed to run before it
|
|
527
|
+
* is forcibly terminated and its results replaced with empty failures.
|
|
528
|
+
*
|
|
529
|
+
* 60 seconds is intentionally generous — the timeout is a last-resort safety
|
|
530
|
+
* net for hung workers (e.g. infinite loops or deadlocked TypeScript programs),
|
|
531
|
+
* not a performance budget.
|
|
532
|
+
*/
|
|
533
|
+
declare const WORKER_TIMEOUT_MS = 60000;
|
|
534
|
+
/**
|
|
535
|
+
* Performance Budgets:
|
|
536
|
+
* Thresholds used to monitor and report execution efficiency.
|
|
537
|
+
*/
|
|
538
|
+
/**
|
|
539
|
+
* The target execution time (p95) per file for rules that do not utilize
|
|
540
|
+
* type-checking services.
|
|
541
|
+
*/
|
|
542
|
+
declare const BUDGET_MS_PER_FILE_WITHOUT_TYPES = 2;
|
|
543
|
+
/**
|
|
544
|
+
* The target execution time (p95) per file for rules requiring full
|
|
545
|
+
* type-checking capabilities.
|
|
546
|
+
*/
|
|
547
|
+
declare const BUDGET_MS_PER_FILE_WITH_TYPES = 5;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* @fileoverview
|
|
551
|
+
* Provides a terminal-based progress visualization utility.
|
|
552
|
+
*
|
|
553
|
+
* Implements a high-efficiency visual indicator (spinner) for long-running
|
|
554
|
+
* command-line operations, isolated from core analytical logic.
|
|
555
|
+
*/
|
|
556
|
+
/**
|
|
557
|
+
* Manages the state and rendering of a terminal-based progress indicator.
|
|
558
|
+
*/
|
|
559
|
+
declare class Spinner {
|
|
560
|
+
private frameIndex;
|
|
561
|
+
private interval;
|
|
562
|
+
private message;
|
|
563
|
+
start(message: string): void;
|
|
564
|
+
update(message: string): void;
|
|
565
|
+
stop(finalMessage?: string): void;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* @fileoverview
|
|
570
|
+
* Manages parallel analysis execution utilizing worker thread pools.
|
|
571
|
+
*
|
|
572
|
+
* Coordinates the distribution of analytical tasks across multiple workers to
|
|
573
|
+
* maximize CPU utilization. Provides a resilient fallback to local concurrent
|
|
574
|
+
* execution if worker resources are unavailable.
|
|
575
|
+
*/
|
|
576
|
+
declare const runAnalysisParallel: (tasks: ReadonlyArray<Task>, rootDir: string, startTime: number, maxWorkers?: number, concurrency?: number, onFileProgress?: (event: AnalysisFileProgress) => void) => Promise<Result<AnalysisResult>>;
|
|
577
|
+
|
|
578
|
+
export { type AnalysisContext, type AnalysisFileProgress, type AnalysisOptions, BUDGET_MS_PER_FILE_WITHOUT_TYPES, BUDGET_MS_PER_FILE_WITH_TYPES, type BatchRuleExecutorFn, type ExecutionContext, MIN_WORKER_COUNT, type PerformanceReport, type RuleCheckerFn, RuleContextFactory, type RuleHandler, SPINNER_FRAME_INTERVAL_MS, STREAM_TO_NODE_TYPE, Spinner, type StreamType, type TypeAwareAnalysisContext, type VisitorEntry, type VisitorMap, WORKER_TIMEOUT_MS, buildProjectContext, buildVisitorMap, calculateStats, configureRuleExecutor, createAnalysisContext, createAnyAngularClassRule, createCallExpressionRule, createComponentRule, createDecoratedPropertyRule, createNewExpressionRule, createTemplateAttributeRule, createTemplateBlockRule, createTemplateExpressionRule, createTemplateRule, createTypeAwareAnalysisContext, executeBatchedTasks, runAnalysis, runAnalysisParallel, runSinglePassAnalysis };
|