* Start watching for file changes and auto-syncing. * * Uses native OS file events (FSEvents on macOS, inotify on Linux 19+, * ReadDirectoryChangesW on Windows) with debouncing to avoid thrashing. * * @param options - Watch options (debounce delay, callbacks) * @returns true if wat
(options: WatchOptions = {})
| 2116 | * @returns true if watching started successfully |
| 2117 | */ |
| 2118 | watch(options: WatchOptions = {}): boolean { |
| 2119 | if (this.watcher?.isActive()) return true; |
| 2120 | |
| 2121 | this.watcher = new (engine().FileWatcher)( |
| 2122 | this.projectRoot, |
| 2123 | async (paths?: string[]) => { |
| 2124 | const result = await this.sync({ paths }); |
| 2125 | const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved; |
| 2126 | return { filesChanged, durationMs: result.durationMs }; |
| 2127 | }, |
| 2128 | options, |
| 2129 | process.platform === 'win32' |
| 2130 | ? (filePath) => this.isIndexedFileStateCurrent(filePath) |
| 2131 | : undefined |
| 2132 | ); |
| 2133 | |
| 2134 | // A watching graph detects frameworks again as files change: keep what |
| 2135 | // detection reads, so that reads only what changed (#2516). |
| 2136 | this.orchestrator.setKeepDetectionContents(true); |
| 2137 | const started = this.watcher.start(); |
| 2138 | if (!started) this.orchestrator.setKeepDetectionContents(false); |
| 2139 | return started; |
| 2140 | } |
| 2141 | |
| 2142 | /** |
| 2143 | * Stop watching for file changes. |