ngperf-audit
Version:
A comprehensive Angular performance analyzer that identifies performance bottlenecks, memory leaks, and optimization opportunities in Angular applications
134 lines • 4.53 kB
TypeScript
import * as ts from 'typescript';
export interface ComponentAnalysis {
componentName: string;
filePath: string;
changeDetectionIssues: ChangeDetectionProblem[];
templateIssues: TemplatePerformanceIssue[];
subscriptionIssues: SubscriptionIssue[];
bundleOptimizations: BundleOptimization[];
performanceScore: number;
recommendations: OptimizationRecommendation[];
}
export interface ChangeDetectionProblem {
type: 'missing-onpush' | 'function-in-template' | 'object-comparison' | 'unnecessary-computation';
severity: 'high' | 'medium' | 'low';
location: CodeLocation;
description: string;
estimatedImpact: string;
fix: string;
}
export interface TemplatePerformanceIssue {
type: 'missing-trackby' | 'suboptimal-trackby' | 'async-pipe-opportunity' | 'expensive-pipe' | 'large-ngfor';
severity: 'high' | 'medium' | 'low';
location: CodeLocation;
description: string;
elementCount?: number;
fix: string;
}
export interface SubscriptionIssue {
type: 'manual-subscription' | 'memory-leak' | 'multiple-subscriptions';
severity: 'high' | 'medium' | 'low';
location: CodeLocation;
description: string;
fix: string;
}
export interface BundleOptimization {
type: 'lazy-loading' | 'tree-shaking' | 'code-splitting';
description: string;
estimatedSizeReduction: string;
implementation: string;
}
export interface OptimizationRecommendation {
priority: 'high' | 'medium' | 'low';
category: 'performance' | 'memory' | 'bundle-size';
title: string;
description: string;
implementation: string;
estimatedImpact: string;
}
export interface CodeLocation {
file: string;
line: number;
column: number;
snippet: string;
}
export interface ComponentInfo {
name: string;
filePath: string;
templatePath?: string;
sourceCode: string;
templateCode?: string;
metadata: ComponentMetadata;
}
export interface ComponentMetadata {
selector: string;
templateUrl?: string;
styleUrls?: string[];
changeDetection?: string;
inputs: string[];
outputs: string[];
providers: string[];
}
export interface ProjectSummary {
totalComponents: number;
totalIssues: number;
averagePerformanceScore: number;
analysisErrors: number;
issueBreakdown: Record<string, number>;
topIssues: Array<{
type: string;
count: number;
}>;
}
export declare class PerformanceAnalyzer {
private typeChecker?;
private sourceFile;
private templateContent;
private componentInfo;
constructor(typeChecker?: ts.TypeChecker | undefined);
analyzeComponent(componentPath: string): ComponentAnalysis;
private parseComponentFile;
private parseComponentMetadata;
private analyzeChangeDetection;
private analyzeTemplate;
private analyzeSubscriptions;
private analyzeBundleOptimizations;
private calculatePerformanceScore;
private generateRecommendations;
/**
* Determines if a component is complex enough to warrant OnPush strategy
* Only recommends OnPush for components that have meaningful logic or complexity
*/
private shouldRecommendOnPush;
private getComponentDecoratorLocation;
private findFunctionCallsInTemplate;
private findObjectComparisonsInTemplate;
private findNgForLoops;
private analyzeForTrackingRecommendation;
private hasIdProperty;
private extractItemVariable;
private findSubscriptionUsagesInTemplate;
private findManualSubscriptions;
private findImports;
private estimateLoopSize;
private isSubscriptionVariable;
private isLargeLibrary;
private getLineNumber;
private getColumnNumber;
}
export declare class PerformanceAnalyzerCLI {
static analyzeProject(projectPath?: string): ComponentAnalysis[];
static analyzeProjectWithSummary(projectPath?: string): {
analyses: ComponentAnalysis[];
summary: ProjectSummary;
};
private static generateProjectSummary;
private static findComponentFiles;
private static shouldSkipDirectory;
private static isComponentFile;
static generateReport(analyses: ComponentAnalysis[]): string;
static generateReportWithSummary(analyses: ComponentAnalysis[], summary: ProjectSummary): string;
static saveReportToFile(report: string, outputPath?: string): Promise<void>;
static runAnalysis(projectPath?: string, outputPath?: string): ComponentAnalysis[];
}
//# sourceMappingURL=performance-analyzer.d.ts.map