deno.land / x / lume@v2.1.4 / core / scopes.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { Entry } from "./fs.ts";
/** * Define independent updates scopes * This optimize the update process after any change */export default class Scopes { scopes = new Set<ScopeFilter>();
/** Returns a function to filter the pages that must be rebuild */ getFilter(changedFiles: Iterable<string>): (entry: Entry) => boolean { // There's no any scope, so rebuild all pages 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; } }
// Calculate scoped extensions that didn't change const notChanged: ScopeFilter[] = [];
for (const scopeFn of this.scopes) { if (!changed.has(scopeFn)) { notChanged.push(scopeFn); } }
// Generate the filter function return function (entry) { // Ignore directories if (entry.type === "directory") { return true; }
// It matches with any scope that has changed for (const scopeFn of changed) { if (scopeFn(entry.path)) { return true; } }
// It's not scoped return noScoped && notChanged.every((scopeFn) => !scopeFn(entry.path)); }; }}
export type ScopeFilter = (path: string) => boolean;
lume

Version Info

Tagged at
7 months ago