Debian Codegraph @

fast-glob/src/providers/matchers/partial.ts

raw symbols SCIP
1 import Matcher from './matcher';
2
3 export default class PartialMatcher extends Matcher {
4 public match(filepath: string): boolean {
5 const parts = filepath.split('/');
6 const levels = parts.length;
7
8 const patterns = this._storage.filter((info) => !info.complete || info.segments.length > levels);
9
10 for (const pattern of patterns) {
11 const section = pattern.sections[0];
12
13 /**
14 * In this case, the pattern has a globstar and we must read all directories unconditionally,
15 * but only if the level has reached the end of the first group.
16 *
17 * fixtures/{a,b}/**
18 * ^ true/false ^ always true
19 */
20 if (!pattern.complete && levels > section.length) {
21 return true;
22 }
23
24 const match = parts.every((part, index) => {
25 const segment = pattern.segments[index];
26
27 if (segment.dynamic && segment.patternRe.test(part)) {
28 return true;
29 }
30
31 if (!segment.dynamic && segment.pattern === part) {
32 return true;
33 }
34
35 return false;
36 });
37
38 if (match) {
39 return true;
40 }
41 }
42
43 return false;
44 }
45 }