(filePath: string = DEFAULT_FILE_PATH)
| 21 | * Returns an empty set if the file does not exist. |
| 22 | */ |
| 23 | export function loadExcludeList(filePath: string = DEFAULT_FILE_PATH): Set<string> { |
| 24 | try { |
| 25 | const mtimeMs = statSync(filePath).mtimeMs; |
| 26 | const cached = loadCache.get(filePath); |
| 27 | if (cached && cached.mtimeMs === mtimeMs) { |
| 28 | // Copy: callers may mutate the returned set |
| 29 | return new Set(cached.set); |
| 30 | } |
| 31 | const raw = readFileSync(filePath, "utf-8"); |
| 32 | const arr: unknown = JSON.parse(raw); |
| 33 | const set = Array.isArray(arr) |
| 34 | ? new Set(arr.filter((x): x is string => typeof x === "string")) |
| 35 | : new Set<string>(); |
| 36 | loadCache.set(filePath, { mtimeMs, set }); |
| 37 | return new Set(set); |
| 38 | } catch { |
| 39 | loadCache.delete(filePath); |
| 40 | return new Set(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Save a set of model IDs to disk as a sorted JSON array. |
no test coverage detected