* 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 = {})
| 2111 | * @returns true if watching started successfully |
| 2112 | */ |
| 2113 | watch(options: WatchOptions = {}): boolean { |
| 2114 | if (this.watcher?.isActive()) return true; |
| 2115 | |
| 2116 | this.watcher = new (engine().FileWatcher)( |
| 2117 | this.projectRoot, |
| 2118 | async (paths?: string[]) => { |
| 2119 | const result = await this.sync({ paths }); |
| 2120 | const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved; |
| 2121 | return { filesChanged, durationMs: result.durationMs }; |
| 2122 | }, |
| 2123 | options, |
| 2124 | process.platform === 'win32' |
| 2125 | ? (filePath) => this.isIndexedFileStateCurrent(filePath) |
| 2126 | : undefined |
| 2127 | ); |
| 2128 | |
| 2129 | // A watching graph detects frameworks again as files change: keep what |
| 2130 | // detection reads, so that reads only what changed (#2516). |
| 2131 | this.orchestrator.setKeepDetectionContents(true); |
| 2132 | const started = this.watcher.start(); |
| 2133 | if (!started) this.orchestrator.setKeepDetectionContents(false); |
| 2134 | return started; |
| 2135 | } |
| 2136 | |
| 2137 | /** |
| 2138 | * Stop watching for file changes. |