import type { FSWatcher, WatchOptions } from 'chokidar';
import { RawSourceMap } from 'source-map';
import { ModuleResolutionOptions } from './module-resolver';
import { ModuleLoadOptions, LoadedModule } from './module-loader';
import { ModuleMetadata } from './module-registry';
import { CompilerOptions } from '../config';
import { ModuleSystemStats, SystemHealth } from './metrics';
import { ResourceLimits } from './resource-limiter';
export type ModuleWatchEventType = 'add' | 'change' | 'unlink' | 'addDir' | 'unlinkDir';
export interface ModuleWatchEvent {
    type: ModuleWatchEventType;
    filePath: string;
}
export interface ModuleSystemWatchOptions {
    onChange?: (_event: ModuleWatchEvent) => void;
    includeNodeModules?: boolean;
    additionalPaths?: string[];
    chokidarOptions?: WatchOptions;
}
export interface ModuleSystemOptions {
    resolution?: ModuleResolutionOptions;
    loading?: ModuleLoadOptions;
    compilation?: CompilerOptions;
    metrics?: boolean;
    circuitBreakers?: boolean;
    logger?: boolean;
    managementServer?: boolean;
    managementPort?: number;
    resourceLimits?: ResourceLimits;
    operationTimeout?: number;
}
export interface CompiledModule {
    code: string;
    map?: RawSourceMap;
}
export interface CompilationError {
    message: string;
    filePath: string;
    line?: number;
    column?: number;
    suggestion?: string;
    originalError?: Error;
}
export interface CompilationResult {
    modules: Map<string, CompiledModule>;
    entryPoint: string;
    dependencies: string[];
    errors: CompilationError[];
    warnings: string[];
}
export interface BundleOptions {
    entryPoint: string;
    outputPath?: string;
    format?: 'commonjs';
    minify?: boolean;
    sourceMaps?: boolean;
    externals?: string[];
    inlineSources?: boolean;
}
export interface BundleOutput {
    code: string;
    map?: string;
}
export declare class ModuleSystem {
    private readonly resolver;
    private readonly loader;
    private readonly registry;
    private readonly activeWatchers;
    private readonly defaultCompilation;
    private readonly metrics?;
    private readonly circuitBreakers?;
    private readonly logger?;
    private readonly configManager?;
    private readonly managementServer?;
    private readonly resourceLimiter?;
    private readonly operationTimeout;
    constructor(options?: ModuleSystemOptions);
    /**
     * Provide helpful suggestions for common compilation errors.
     */
    private getSuggestionForError;
    /**
     * Create a structured compilation error with context and suggestions.
     */
    private createCompilationError;
    /**
     * Validate ModuleSystem configuration options upfront.
     * Fail fast with clear error messages for invalid configurations.
     */
    private validateConfiguration;
    private validateResolutionOptions;
    private validateResolutionBaseUrl;
    private validateResolutionPaths;
    private validateResolutionExtensions;
    private validateResolutionModuleDirectories;
    private validateResolutionBooleanFlags;
    private validateCompilationOptions;
    private validateManagementServer;
    private validateManagementPort;
    private validateOperationTimeout;
    private validateResourceLimits;
    private validateLoaderOptions;
    /**
     * Load a module and all its dependencies
     */
    loadModule(specifier: string, fromFile: string): Promise<LoadedModule>;
    /**
     * Load module synchronously
     */
    loadModuleSync(specifier: string, fromFile: string): LoadedModule;
    private setupExternals;
    private collectLoaderWarnings;
    private checkCircularDependencies;
    private compileModulesInOrder;
    private handleEntryPointLoadError;
    private cleanupOnCompilationFailure;
    /**
     * Compile a module and all its dependencies
     */
    compile(entryPoint: string, externals?: string[], overrideCompilation?: Partial<CompilerOptions>): Promise<CompilationResult>;
    /**
     * Bundle modules into a single file
     */
    bundle(options: BundleOptions): Promise<BundleOutput>;
    /**
     * Resolve a module specifier
     */
    resolve(specifier: string, fromFile: string): string;
    /**
     * Get module metadata
     */
    getModule(moduleId: string): ModuleMetadata | undefined;
    /**
     * Get all loaded modules
     */
    getAllModules(): ModuleMetadata[];
    /**
     * Get dependency graph
     */
    getDependencyGraph(): Map<string, string[]>;
    /**
     * Get module statistics
     */
    getStatistics(): {
        totalModules: number;
        totalDependencies: number;
        averageDependencies: number;
        maxDependencyDepth: number;
        circularDependencies: number;
    };
    /**
     * Clear all caches
     */
    clearCache(): void;
    /**
     * Update module system options
     */
    updateOptions(options: ModuleSystemOptions): void;
    /**
     * Gracefully shutdown the module system
     * - Stops resource limiter
     * - Stops all file watchers
     * - Stops management server
     * - Clears all caches
     * - Times out after 30 seconds to prevent hanging
     */
    shutdown(): Promise<void>;
    private performShutdownSequence;
    private shutdownResourceLimiter;
    private shutdownWatchers;
    private shutdownCircuitBreakers;
    private shutdownManagementServerSafely;
    private shutdownClearCaches;
    private logShutdownError;
    private executeWithTimeout;
    watch(entryPoint: string, options?: ModuleSystemWatchOptions): FSWatcher;
    stopWatching(): Promise<void>;
    private registerAllLoadedModules;
    private resolveCompilationOptions;
    private toPipelineOptions;
    private initializeBundleContext;
    private createBundleCodeBuilder;
    private appendToBuilder;
    private createSourceMapGenerator;
    private buildModuleMapSection;
    private addModuleSourceMappings;
    private addBundleRuntimeCode;
    private generateBundleSourceMap;
    private applyMinification;
    private serializeBundleSourceMap;
    private generateCommonJSBundle;
    private buildExternalCandidates;
    private matchesExternal;
    private markExternalModule;
    private prepareModulesForBundle;
    private rewriteRequiresForModule;
    /**
     * Validate source map structure and required fields.
     * Fails fast with clear error messages for invalid maps.
     */
    private validateSourceMap;
    private compileModule;
    private collectCompilationErrors;
    private parseModuleSourceMap;
    private deriveBundleFilename;
    private minify;
    /**
     * Start management server for production monitoring
     */
    startManagementServer(port?: number): Promise<number | null>;
    /**
     * Stop management server
     */
    stopManagementServer(): Promise<void>;
    /**
     * Get production metrics
     */
    getMetrics(): ModuleSystemStats | null;
    /**
     * Get system health status
     */
    getHealth(): Promise<SystemHealth>;
    /**
     * Validate module system integrity
     */
    validate(): {
        isValid: boolean;
        errors: string[];
    };
}
//# sourceMappingURL=module-system.d.ts.map