import { EventEmitter } from "node:events"; /** * Options for FileWatcher */ export interface FileWatcherOptions { /** Debounce time in milliseconds (default: 500) */ debounceMs?: number; /** * Poll interval in milliseconds (default: 5000). * Used by chokidar's polling mode when `usePolling` is on, and by the * always-on stat fallback otherwise. */ pollIntervalMs?: number; /** * Replace native file system events with chokidar's polling mode * (`fs.watchFile`). Use this on mounts where `fs.watch` itself fails. * When off (default), native events are used and a lightweight `fs.stat` * fallback runs alongside them so that changes which never produce a native * event — cloud sync from another machine, WSL drvfs (9p) mounts — are still * picked up within one poll interval. */ usePolling?: boolean; /** Retry delay in milliseconds for JSON parse (default: 200) */ retryDelayMs?: number; /** Maximum number of retries for JSON parse (default: 10) */ maxRetries?: number; } /** * FileWatcher watches a file or directory for changes and emits events. * * Change detection combines two sources, both debounced through the same * path so a change seen by both fires once: * - chokidar (native events, or its own polling when `usePolling` is set) * - a stat-based fallback ({@link StatPoller}) that only runs when * `usePolling` is off and the watched path is a file * * Events: * - 'change': Emitted when a watched file changes (after debounce) * - 'error': Emitted when a watch error occurs * - 'ready': Emitted when watching has started * - 'parsed': Emitted when JSON file is successfully parsed * - 'parseError': Emitted when JSON parse fails after all retries */ export declare class FileWatcher extends EventEmitter { private readonly watchPath; private readonly debounceMs; private readonly pollIntervalMs; private readonly usePolling; private readonly retryDelayMs; private readonly maxRetries; private watcher; private statPoller; private watching; private debounceTimers; constructor(watchPath: string, options?: FileWatcherOptions); /** * Start watching for file changes */ start(): Promise; /** * Start the stat-based fallback unless chokidar is already polling. * StatPoller declines to run on a directory path. */ private startStatFallback; /** * Emit 'error' only when someone is listening; an unhandled 'error' event * would throw and take the host process down. */ private emitErrorIfListened; /** * Handle file change with debouncing */ private handleFileChange; /** * Try to parse JSON file with retries */ private tryParseJsonFile; /** * Delay helper */ private delay; /** * Stop watching for file changes */ close(): void; /** * Get the watched path */ getPath(): string; /** * Check if the watcher is currently active */ isWatching(): boolean; /** * Whether the stat-based fallback poll is running. * False when `usePolling` is on, when the path is a directory, or after close(). */ isStatPollingActive(): boolean; /** * Get the debounce time in milliseconds */ getDebounceMs(): number; /** * Get the poll interval in milliseconds */ getPollIntervalMs(): number; /** * Get the retry delay in milliseconds */ getRetryDelayMs(): number; /** * Get the maximum number of retries */ getMaxRetries(): number; } //# sourceMappingURL=file-watcher.d.ts.map