* Shared change handler for both watch strategies. `rel` is a * project-relative POSIX path. Applies the ignore + source-file filters and, * for a real source change, records it as pending (#403) and schedules a * debounced sync. * * The recursive (macOS/Windows) watcher reports event
(rel: string)
| 647 | * — it drops node_modules/dist/.git churn before any sync is scheduled. |
| 648 | */ |
| 649 | private handleChange(rel: string): void { |
| 650 | if (!rel || rel === '.' || escapesRoot(rel)) return; |
| 651 | // `.git/info/exclude` is otherwise always-ignored with the rest of `.git/`, |
| 652 | // but it feeds `buildScopeIgnore` — allow it through as a scope refresh |
| 653 | // when the platform delivers the event (recursive watchers may; Linux |
| 654 | // per-directory watching does not descend into `.git/`) (#1728). |
| 655 | if (rel === '.git/info/exclude') { |
| 656 | this.refreshScope(rel); |
| 657 | return; |
| 658 | } |
| 659 | if (this.isAlwaysIgnored(rel)) return; |
| 660 | // The two root files the scope matcher is derived from are handled BEFORE |
| 661 | // the matcher is consulted: a user `exclude` pattern that happens to cover |
| 662 | // them (`*.json`, `.*`) must not be able to hide their own edits (#1590). |
| 663 | if (rel === PROJECT_CONFIG_FILENAME || rel === '.gitignore') { |
| 664 | this.refreshScope(rel); |
| 665 | return; |
| 666 | } |
| 667 | if (this.ignoreMatcher && this.ignoreMatcher.ignores(rel)) return; |
| 668 | // A nested `.gitignore` (an embedded child repo's own rules, #514, or a |
| 669 | // subdirectory rule the git-backed full scan honors) is only a scope |
| 670 | // change when it sits INSIDE the current scope — checked after the matcher |
| 671 | // on purpose, so the thousands of package-local `.gitignore`s an |
| 672 | // `npm install` writes under an ignored `node_modules/` never trigger a |
| 673 | // rebuild storm. |
| 674 | if (rel.endsWith('/.gitignore')) { |
| 675 | this.refreshScope(rel); |
| 676 | return; |
| 677 | } |
| 678 | if (!isSourceFile(rel, loadExtensionOverrides(this.projectRoot), this.projectRoot)) { |
| 679 | this.maybeScheduleForRemovedDir(rel); |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | try { |
| 684 | if (this.isFileStateCurrent?.(rel)) { |
| 685 | logDebug('Ignoring file event with unchanged indexed metadata', { file: rel }); |
| 686 | return; |
| 687 | } |
| 688 | } catch (error) { |
| 689 | // The guard is an optimization, never a correctness boundary. If the |
| 690 | // stat/DB lookup fails, keep the event so a sync can reconcile it. |
| 691 | logDebug('Could not verify file event metadata; treating it as a change', { |
| 692 | file: rel, |
| 693 | error: String(error), |
| 694 | }); |
| 695 | } |
| 696 | |
| 697 | logDebug('File change detected', { file: rel }); |
| 698 | if (this.ready) { |
| 699 | const now = Date.now(); |
| 700 | const existing = this.pendingFiles.get(rel); |
| 701 | this.pendingFiles.set(rel, { |
| 702 | firstSeenMs: existing?.firstSeenMs ?? now, |
| 703 | lastSeenMs: now, |
| 704 | }); |
| 705 | } |
| 706 | this.scheduleSync(); |
no test coverage detected