1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.Ignore = void 0;
|
8 | const minimatch_1 = require("minimatch");
|
9 | const pattern_js_1 = require("./pattern.js");
|
10 | const defaultPlatform = (typeof process === 'object' &&
|
11 | process &&
|
12 | typeof process.platform === 'string') ?
|
13 | process.platform
|
14 | : 'linux';
|
15 |
|
16 |
|
17 |
|
18 | class Ignore {
|
19 | relative;
|
20 | relativeChildren;
|
21 | absolute;
|
22 | absoluteChildren;
|
23 | platform;
|
24 | mmopts;
|
25 | constructor(ignored, { nobrace, nocase, noext, noglobstar, platform = defaultPlatform, }) {
|
26 | this.relative = [];
|
27 | this.absolute = [];
|
28 | this.relativeChildren = [];
|
29 | this.absoluteChildren = [];
|
30 | this.platform = platform;
|
31 | this.mmopts = {
|
32 | dot: true,
|
33 | nobrace,
|
34 | nocase,
|
35 | noext,
|
36 | noglobstar,
|
37 | optimizationLevel: 2,
|
38 | platform,
|
39 | nocomment: true,
|
40 | nonegate: true,
|
41 | };
|
42 | for (const ign of ignored)
|
43 | this.add(ign);
|
44 | }
|
45 | add(ign) {
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | const mm = new minimatch_1.Minimatch(ign, this.mmopts);
|
59 | for (let i = 0; i < mm.set.length; i++) {
|
60 | const parsed = mm.set[i];
|
61 | const globParts = mm.globParts[i];
|
62 |
|
63 | if (!parsed || !globParts) {
|
64 | throw new Error('invalid pattern object');
|
65 | }
|
66 |
|
67 |
|
68 | while (parsed[0] === '.' && globParts[0] === '.') {
|
69 | parsed.shift();
|
70 | globParts.shift();
|
71 | }
|
72 |
|
73 | const p = new pattern_js_1.Pattern(parsed, globParts, 0, this.platform);
|
74 | const m = new minimatch_1.Minimatch(p.globString(), this.mmopts);
|
75 | const children = globParts[globParts.length - 1] === '**';
|
76 | const absolute = p.isAbsolute();
|
77 | if (absolute)
|
78 | this.absolute.push(m);
|
79 | else
|
80 | this.relative.push(m);
|
81 | if (children) {
|
82 | if (absolute)
|
83 | this.absoluteChildren.push(m);
|
84 | else
|
85 | this.relativeChildren.push(m);
|
86 | }
|
87 | }
|
88 | }
|
89 | ignored(p) {
|
90 | const fullpath = p.fullpath();
|
91 | const fullpaths = `${fullpath}/`;
|
92 | const relative = p.relative() || '.';
|
93 | const relatives = `${relative}/`;
|
94 | for (const m of this.relative) {
|
95 | if (m.match(relative) || m.match(relatives))
|
96 | return true;
|
97 | }
|
98 | for (const m of this.absolute) {
|
99 | if (m.match(fullpath) || m.match(fullpaths))
|
100 | return true;
|
101 | }
|
102 | return false;
|
103 | }
|
104 | childrenIgnored(p) {
|
105 | const fullpath = p.fullpath() + '/';
|
106 | const relative = (p.relative() || '.') + '/';
|
107 | for (const m of this.relativeChildren) {
|
108 | if (m.match(relative))
|
109 | return true;
|
110 | }
|
111 | for (const m of this.absoluteChildren) {
|
112 | if (m.match(fullpath))
|
113 | return true;
|
114 | }
|
115 | return false;
|
116 | }
|
117 | }
|
118 | exports.Ignore = Ignore;
|
119 |
|
\ | No newline at end of file |