Events are relative to a watch's logical path, even for an external target.
(dir: string, filename: string | Buffer | null)
| 602 | |
| 603 | /** Events are relative to a watch's logical path, even for an external target. */ |
| 604 | private handleDirEvent(dir: string, filename: string | Buffer | null): void { |
| 605 | if (this.stopped) return; |
| 606 | if (filename == null) { |
| 607 | this.scheduleTreeRefresh(); |
| 608 | return; |
| 609 | } |
| 610 | const name = String(filename); |
| 611 | // Names are relative to the watched folder. An absolute one is the folder |
| 612 | // itself, reported gone (see armGoneCheck); this is all a normal event pays. |
| 613 | if (path.isAbsolute(name)) { |
| 614 | this.armGoneCheck(dir); |
| 615 | return; |
| 616 | } |
| 617 | const full = path.join(dir, name); |
| 618 | const rel = normalizePath(path.relative(this.projectRoot, full)); |
| 619 | if (!rel || rel === '.') { |
| 620 | this.scheduleTreeRefresh(); |
| 621 | return; |
| 622 | } |
| 623 | // Churn under an ignored directory (node_modules, dist, .git) is dropped |
| 624 | // before any per-event fs call; `.git/info/exclude` still reaches the scope |
| 625 | // refresh in handleChange (#1728). |
| 626 | if (rel !== '.git/info/exclude' && this.shouldIgnoreDir(path.dirname(full))) return; |
| 627 | try { |
| 628 | if (fs.statSync(full).isDirectory()) { |
| 629 | if (this.shouldIgnoreDir(full)) return; |
| 630 | // Existing directory notifications can represent a retargeted link. |
| 631 | if (this.knownDirs.get(full) !== fs.realpathSync(full)) this.scheduleTreeRefresh(); |
| 632 | return; |
| 633 | } |
| 634 | } catch { /* deleted/inaccessible */ } |
| 635 | if (this.knownDirs.has(full) && !this.shouldIgnoreDir(full)) this.scheduleTreeRefresh(); |
| 636 | this.handleChange(rel); |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Shared change handler for both watch strategies. `rel` is a |
no test coverage detected