* 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 = {})
| 2060 | * @returns true if watching started successfully |
| 2061 | */ |
| 2062 | watch(options: WatchOptions = {}): boolean { |
| 2063 | if (this.watcher?.isActive()) return true; |
| 2064 | |
| 2065 | this.watcher = new (engine().FileWatcher)( |
| 2066 | this.projectRoot, |
| 2067 | async (paths?: string[]) => { |
| 2068 | const result = await this.sync({ paths }); |
| 2069 | const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved; |
| 2070 | return { filesChanged, durationMs: result.durationMs }; |
| 2071 | }, |
| 2072 | options, |
| 2073 | process.platform === 'win32' |
| 2074 | ? (filePath) => this.isIndexedFileStateCurrent(filePath) |
| 2075 | : undefined |
| 2076 | ); |
| 2077 | |
| 2078 | // A watching graph detects frameworks again as files change: keep what |
| 2079 | // detection reads, so that reads only what changed (#2516). |
| 2080 | this.orchestrator.setKeepDetectionContents(true); |
| 2081 | const started = this.watcher.start(); |
| 2082 | if (!started) this.orchestrator.setKeepDetectionContents(false); |
| 2083 | return started; |
| 2084 | } |
| 2085 | |
| 2086 | /** |
| 2087 | * Stop watching for file changes. |