@devlander/collect-exports-for-bundle
Version:
Generate comprehensive export files for TypeScript/JavaScript projects with Rollup compatibility
226 lines (225 loc) • 7.11 kB
TypeScript
import { ModuleExportOptions } from '../types/module-exporter.types';
/**
* Optimized auto-exporter with significant performance improvements.
*
* This class provides high-performance export collection and generation
* for TypeScript/JavaScript projects. It uses optimized algorithms and
* caching to significantly improve performance over the standard auto-exporter.
*
* Key features:
* - Parallel file processing
* - Intelligent caching
* - Batch operations
* - Memory-efficient algorithms
* - Comprehensive error handling
*
* @example
* ```typescript
* const config = {
* rootDir: './src',
* allowedExtensions: ['.ts', '.tsx'],
* exportMode: 'both',
* debug: true
* };
*
* const exporter = new OptimizedAutoExporter(config);
* await exporter.collectExports();
* ```
*/
export declare class OptimizedAutoExporter {
/** Optimized export analyzer instance */
private analyzer;
/** Optimized path collector instance */
private pathCollector;
/** Configuration options for the exporter */
private config;
/**
* Create a new OptimizedAutoExporter instance.
*
* @param config - Configuration options for export collection
*
* @example
* ```typescript
* const exporter = new OptimizedAutoExporter({
* rootDir: './src',
* allowedExtensions: ['.ts', '.tsx'],
* exportMode: 'named',
* debug: true
* });
* ```
*/
constructor(config: ModuleExportOptions);
/**
* Main export collection method - optimized version.
*
* This method orchestrates the entire export collection process:
* 1. Collects all file paths from the root directory
* 2. Filters and analyzes files with exports
* 3. Generates optimized export statements
* 4. Writes the output file
*
* @returns Promise that resolves when export collection is complete
*
* @example
* ```typescript
* try {
* await exporter.collectExports();
* console.log('Export collection completed successfully');
* } catch (error) {
* console.error('Export collection failed:', error);
* }
* ```
*/
collectExports(): Promise<void>;
/**
* Collect all file paths from the root directory.
*
* This method recursively traverses the root directory and collects
* all file paths that match the allowed extensions, excluding
* specified folders and files.
*
* @returns Promise that resolves to an array of file paths
*
* @example
* ```typescript
* const paths = await exporter.collectAllPaths();
* console.log(`Found ${paths.length} files to analyze`);
* ```
*/
private collectAllPaths;
/**
* Generate export content from files with exports.
*
* This method analyzes all files with exports and generates
* optimized import and export statements based on the configuration.
*
* @param filesWithExports - Array of file paths that contain exports
* @returns Promise that resolves to the generated export content
*
* @example
* ```typescript
* const files = ['./src/comp1.ts', './src/comp2.tsx'];
* const content = await exporter.generateExportContent(files);
* console.log('Generated content:', content);
* ```
*/
private generateExportContent;
/**
* Write the output file with generated export content.
*
* This method creates the output directory if it doesn't exist
* and writes the generated export content to the specified file.
*
* @param content - The export content to write to the file
* @returns Promise that resolves when the file is written
*
* @example
* ```typescript
* const content = 'export { MyComponent } from "./MyComponent";';
* await exporter.writeOutputFile(content);
* ```
*/
private writeOutputFile;
/**
* Get import path from relative path.
*
* This method converts a relative file path to an import path
* by removing the file extension and converting Windows path
* separators to forward slashes.
*
* @param relativePath - The relative path to convert
* @returns The import path suitable for import statements
*
* @example
* ```typescript
* const importPath = exporter.getImportPath('./components/Button.tsx');
* console.log(importPath); // './components/Button'
* ```
*/
private getImportPath;
/**
* Get default export name from file path.
*
* This method generates a default export name by capitalizing
* the first letter of the filename (without extension).
*
* @param relativePath - The relative path to extract the name from
* @returns The default export name
*
* @example
* ```typescript
* const name = exporter.getDefaultExportName('./components/button.tsx');
* console.log(name); // 'Button'
* ```
*/
private getDefaultExportName;
/**
* Validate and enhance configuration.
*
* This method validates the provided configuration and adds
* default values for missing properties to ensure the exporter
* works correctly.
*
* @param config - The configuration to validate and enhance
* @returns Enhanced configuration with all required properties
*
* @example
* ```typescript
* const config = exporter.validateAndEnhanceConfig({
* rootDir: './src'
* });
* console.log(config.allowedExtensions); // ['.ts', '.tsx']
* ```
*/
private validateAndEnhanceConfig;
/**
* Log performance statistics.
*
* This method logs cache statistics and other performance metrics
* when debug mode is enabled.
*
* @example
* ```typescript
* exporter.logPerformanceStats();
* // Output: 📊 Performance Statistics:
* // File content cache: 150 entries
* // Analysis cache: 150 entries
* ```
*/
private logPerformanceStats;
/**
* Clear all caches to free memory.
*
* This method clears all internal caches to free up memory.
* Useful when processing large projects or when memory usage
* becomes a concern.
*
* @example
* ```typescript
* exporter.clearCaches();
* console.log('All caches cleared');
* ```
*/
clearCaches(): void;
}
/**
* Convenience function for backward compatibility.
*
* This function provides a simple interface for using the optimized
* auto-exporter without creating a class instance directly.
*
* @param config - Configuration options for export collection
* @returns Promise that resolves when export collection is complete
*
* @example
* ```typescript
* await optimizedAutoExporter({
* rootDir: './src',
* allowedExtensions: ['.ts', '.tsx'],
* exportMode: 'both',
* debug: true
* });
* ```
*/
export declare function optimizedAutoExporter(config: ModuleExportOptions): Promise<void>;
export default optimizedAutoExporter;