(dirPath: string)
| 248 | } |
| 249 | |
| 250 | function watchDirectory(dirPath: string): void { |
| 251 | if (watchers.has(dirPath)) { |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | if (dirPath !== watchRoot && fileSystem.isIgnored(dirPath, watchRoot)) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | const stats = getPathStats(dirPath); |
| 260 | if (!stats?.isDirectory()) { |
| 261 | return; |
| 262 | } |
| 263 | |
| 264 | try { |
| 265 | const watcher = fs.watch(dirPath, (eventType, rawFilename) => { |
| 266 | const name = rawFilename?.toString(); |
| 267 | if (!name) { |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | handleFileEvent(eventType, dirPath, name); |
| 272 | }); |
| 273 | watchers.set(dirPath, watcher); |
| 274 | } catch (error) { |
| 275 | console.warn(`Warning: failed to watch ${dirPath}:`, error); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | try { |
| 280 | for (const entry of fs.readdirSync(dirPath, { withFileTypes: true })) { |
| 281 | if (!entry.isDirectory()) { |
| 282 | continue; |
| 283 | } |
| 284 | |
| 285 | watchDirectory(path.join(dirPath, entry.name)); |
| 286 | } |
| 287 | } catch (error) { |
| 288 | console.warn(`Warning: failed to read directory ${dirPath}:`, error); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | watchDirectory(watchRoot); |
| 293 | } catch (error) { |
no test coverage detected