Skip to content

Commit 944eca1

Browse files
authored
fix: use shared shouldIgnore/isSupportedFile in watcher (#864)
* fix: use shared shouldIgnore/isSupportedFile in watcher (#838) The watcher duplicated shouldIgnore and isSupportedFile logic locally, causing the shared exports in constants.ts to be misclassified as test-only. Reuse the shared functions to fix role classification and eliminate duplication. * fix: correct missing imports in watcher (#864) Replace raw IGNORE_DIRS/EXTENSIONS references in collectTrackedFiles with the already-imported shouldIgnore/isSupportedFile helpers, fixing the TypeScript compilation error.
1 parent 13665d4 commit 944eca1

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/domain/graph/watcher.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import { closeDb, getNodeId as getNodeIdQuery, initSchema, openDb } from '../../db/index.js';
44
import { debug, info } from '../../infrastructure/logger.js';
5-
import { EXTENSIONS, IGNORE_DIRS, normalizePath } from '../../shared/constants.js';
5+
import { isSupportedFile, normalizePath, shouldIgnore } from '../../shared/constants.js';
66
import { DbError } from '../../shared/errors.js';
77
import { createParseTreeCache, getActiveEngine } from '../parser.js';
88
import { type IncrementalStmts, rebuildFile } from './builder/incremental.js';
99
import { appendChangeEvents, buildChangeEvent, diffSymbols } from './change-journal.js';
1010
import { appendJournalEntries } from './journal.js';
1111

12-
function shouldIgnore(filePath: string): boolean {
12+
function shouldIgnorePath(filePath: string): boolean {
1313
const parts = filePath.split(path.sep);
14-
return parts.some((p) => IGNORE_DIRS.has(p));
15-
}
16-
17-
function isTrackedExt(filePath: string): boolean {
18-
return EXTENSIONS.has(path.extname(filePath));
14+
return parts.some((p) => shouldIgnore(p));
1915
}
2016

2117
/** Prepare all SQL statements needed by the watcher's incremental rebuild. */
@@ -146,11 +142,11 @@ function collectTrackedFiles(dir: string, result: string[]): void {
146142
return;
147143
}
148144
for (const entry of entries) {
149-
if (IGNORE_DIRS.has(entry.name) || entry.name.startsWith('.')) continue;
145+
if (shouldIgnore(entry.name)) continue;
150146
const full = path.join(dir, entry.name);
151147
if (entry.isDirectory()) {
152148
collectTrackedFiles(full, result);
153-
} else if (EXTENSIONS.has(path.extname(entry.name))) {
149+
} else if (isSupportedFile(entry.name)) {
154150
result.push(full);
155151
}
156152
}
@@ -268,8 +264,8 @@ function startPollingWatcher(ctx: WatcherContext, pollIntervalMs: number): () =>
268264
function startNativeWatcher(ctx: WatcherContext): () => void {
269265
const watcher = fs.watch(ctx.rootDir, { recursive: true }, (_eventType, filename) => {
270266
if (!filename) return;
271-
if (shouldIgnore(filename)) return;
272-
if (!isTrackedExt(filename)) return;
267+
if (shouldIgnorePath(filename)) return;
268+
if (!isSupportedFile(filename)) return;
273269

274270
ctx.pending.add(path.join(ctx.rootDir, filename));
275271
scheduleDebouncedProcess(ctx);

0 commit comments

Comments
 (0)