* 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 = {})
| 2134 | * @returns true if watching started successfully |
| 2135 | */ |
| 2136 | watch(options: WatchOptions = {}): boolean { |
| 2137 | if (this.watcher?.isActive()) return true; |
| 2138 | |
| 2139 | this.watcher = new (engine().FileWatcher)( |
| 2140 | this.projectRoot, |
| 2141 | async (paths?: string[]) => { |
| 2142 | const result = await this.sync({ paths }); |
| 2143 | const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved; |
| 2144 | return { filesChanged, durationMs: result.durationMs }; |
| 2145 | }, |
| 2146 | options, |
| 2147 | process.platform === 'win32' |
| 2148 | ? (filePath) => this.isIndexedFileStateCurrent(filePath) |
| 2149 | : undefined |
| 2150 | ); |
| 2151 | |
| 2152 | // A watching graph detects frameworks again as files change: keep what |
| 2153 | // detection reads, so that reads only what changed (#2516). |
| 2154 | this.orchestrator.setKeepDetectionContents(true); |
| 2155 | const started = this.watcher.start(); |
| 2156 | if (!started) this.orchestrator.setKeepDetectionContents(false); |
| 2157 | return started; |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * Stop watching for file changes. |