import type { Entry } from "./fs.ts";
export default class Scopes { scopes = new Set<ScopeFilter>();
getFilter(changedFiles: Iterable<string>): (entry: Entry) => boolean { if (this.scopes.size === 0) { return () => true; }
let noScoped = false; const changed = new Set<ScopeFilter>();
for (const file of changedFiles) { let found = false; for (const scopeFn of this.scopes) { if (scopeFn(file)) { changed.add(scopeFn); found = true; break; } }
if (!found) { noScoped = true; } }
const notChanged: ScopeFilter[] = [];
for (const scopeFn of this.scopes) { if (!changed.has(scopeFn)) { notChanged.push(scopeFn); } }
return function (entry) { if (entry.type === "directory") { return true; }
for (const scopeFn of changed) { if (scopeFn(entry.path)) { return true; } }
return noScoped && notChanged.every((scopeFn) => !scopeFn(entry.path)); }; }}
export type ScopeFilter = (path: string) => boolean;