/** * @angular-modernizer/plugin-angular - Bundle Size Optimization Rule * * Detects bundle size optimization opportunities for faster initial load times. * * Detection Patterns: * - Large library imports that could be lazy-loaded * - Barrel imports that prevent tree-shaking * - Missing lazy-loading for feature modules */ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system'; export interface BundleSizeOptimizationConfig { maxBundleSizeKB: number; largeLibraries: string[]; allowedBarrelImports: string[]; } export declare class BundleSizeOptimizationRule implements AnalysisRule { readonly id = "plugin-angular:bundle-size-optimization"; readonly name = "Bundle Size Optimization"; readonly description = "Detects bundle size optimization opportunities for faster initial load times"; readonly severity = "warning"; readonly category = "build-time"; readonly tags: string[]; private config; configure(config: Partial): void; /** * Analyzes the given context for bundle size optimization violations. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results representing bundle size optimization violations. */ analyze(context: AnalysisContext): Promise; /** * Detects routes that use eager loading instead of lazy loading. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for missing lazy loading violations. */ private detectMissingLazyLoading; /** * Detects namespace imports from large libraries that prevent tree-shaking. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for large import violations. */ private detectLargeImports; /** * Checks if an import declaration is a namespace import from a large library. * @param importDecl - The import declaration to check. * @returns True if it's a namespace import from a large library. */ private isNamespaceImportFromLargeLibrary; /** * Creates a violation for a large library namespace import. * @param importDecl - The import declaration that violates the rule. * @param sourceFile - The source file containing the import. * @returns The analysis result violation. */ private createLargeImportViolation; /** * Detects incorrect module imports like BrowserModule in feature modules. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for incorrect module import violations. */ private detectIncorrectModuleImports; /** * Finds all NgModule decorators in a source file. * @param sourceFile - The source file to search. * @returns Array of NgModule decorators. */ private findNgModuleDecorators; /** * Extracts a BrowserModule violation from an NgModule decorator if it exists. * @param decorator - The NgModule decorator to analyze. * @param sourceFile - The source file containing the decorator. * @returns A violation if BrowserModule is found in imports, null otherwise. */ private extractBrowserModuleViolation; /** * Extracts the imports array from an NgModule decorator. * @param decorator - The NgModule decorator. * @returns The imports array literal expression, or null if not found. */ private extractImportsArrayFromNgModule; /** * Checks if an imports array contains BrowserModule. * @param importsArray - The imports array to check. * @returns True if BrowserModule is found. */ private hasBrowserModule; /** * Creates a violation for BrowserModule usage in a feature module. * @param decorator - The NgModule decorator. * @param sourceFile - The source file containing the decorator. * @returns The analysis result violation. */ private createBrowserModuleViolation; /** * Detects barrel imports that prevent tree-shaking. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for barrel import violations. */ private detectBarrelImports; /** * Checks if an import declaration is a barrel import. * @param importDecl - The import declaration to check. * @returns True if it's a barrel import that should be flagged. */ private isBarrelImport; /** * Checks if a module specifier represents a relative import. * @param moduleSpecifier - The module specifier to check. * @returns True if it's a relative import (starts with ./ or ../). */ private isRelativeImport; /** * Creates a violation for a barrel import. * @param importDecl - The import declaration that violates the rule. * @param sourceFile - The source file containing the import. * @returns The analysis result violation. */ private createBarrelImportViolation; /** * Detects side-effect imports that may include unused code. * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for non-tree-shakeable import violations. */ private detectNonTreeShakeableImports; /** * Estimates the bundle size of a library based on known library sizes. * @param libraryName - The name of the library to estimate size for. * @returns The estimated size in KB. */ private estimateLibrarySize; } //# sourceMappingURL=bundle-size-optimization.rule.d.ts.map