π File detail
utils/settings/internalWrites.ts
π― Use case
This file lives under βutils/β, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, β¦). On the API surface it exposes markInternalWrite, consumeInternalWrite, and clearInternalWrites β mainly functions, hooks, or classes. What the file header says: Tracks timestamps of in-process settings-file writes so the chokidar watcher in changeDetector.ts can ignore its own echoes. Extracted from changeDetector.ts to break the settings.ts β changeDetector.ts β hooks.ts β β¦ β settings.ts cycle. settings.ts needs to mark "I'm about to w.
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
Tracks timestamps of in-process settings-file writes so the chokidar watcher in changeDetector.ts can ignore its own echoes. Extracted from changeDetector.ts to break the settings.ts β changeDetector.ts β hooks.ts β β¦ β settings.ts cycle. settings.ts needs to mark "I'm about to write" before the write lands; changeDetector needs to read the mark when chokidar fires. The map is the only shared state β everything else in changeDetector (chokidar, hooks, mdm polling) is irrelevant to settings.ts. Callers pass resolved paths. The pathβsource resolution (getSettingsFilePathForSource) lives in settings.ts, so settings.ts does it before calling here. No imports.
π€ Exports (heuristic)
markInternalWriteconsumeInternalWriteclearInternalWrites
π₯οΈ Source preview
/**
* Tracks timestamps of in-process settings-file writes so the chokidar watcher
* in changeDetector.ts can ignore its own echoes.
*
* Extracted from changeDetector.ts to break the settings.ts β changeDetector.ts β
* hooks.ts β β¦ β settings.ts cycle. settings.ts needs to mark "I'm about to
* write" before the write lands; changeDetector needs to read the mark when
* chokidar fires. The map is the only shared state β everything else in
* changeDetector (chokidar, hooks, mdm polling) is irrelevant to settings.ts.
*
* Callers pass resolved paths. The pathβsource resolution (getSettingsFilePathForSource)
* lives in settings.ts, so settings.ts does it before calling here. No imports.
*/
const timestamps = new Map<string, number>()
export function markInternalWrite(path: string): void {
timestamps.set(path, Date.now())
}
/**
* True if `path` was marked within `windowMs`. Consumes the mark on match β
* the watcher fires once per write, so a matched mark shouldn't suppress
* the next (real, external) change to the same file.
*/
export function consumeInternalWrite(path: string, windowMs: number): boolean {
const ts = timestamps.get(path)
if (ts !== undefined && Date.now() - ts < windowMs) {
timestamps.delete(path)
return true
}
return false
}
export function clearInternalWrites(): void {
timestamps.clear()
}