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 | constructor(ignored, { nobrace, nocase, noext, noglobstar, platform = defaultPlatform, }) {
|
24 | this.relative = [];
|
25 | this.absolute = [];
|
26 | this.relativeChildren = [];
|
27 | this.absoluteChildren = [];
|
28 | const mmopts = {
|
29 | dot: true,
|
30 | nobrace,
|
31 | nocase,
|
32 | noext,
|
33 | noglobstar,
|
34 | optimizationLevel: 2,
|
35 | platform,
|
36 | nocomment: true,
|
37 | nonegate: true,
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | for (const ign of ignored) {
|
52 | const mm = new minimatch_1.Minimatch(ign, mmopts);
|
53 | for (let i = 0; i < mm.set.length; i++) {
|
54 | const parsed = mm.set[i];
|
55 | const globParts = mm.globParts[i];
|
56 |
|
57 | if (!parsed || !globParts) {
|
58 | throw new Error('invalid pattern object');
|
59 | }
|
60 |
|
61 |
|
62 | while (parsed[0] === '.' && globParts[0] === '.') {
|
63 | parsed.shift();
|
64 | globParts.shift();
|
65 | }
|
66 |
|
67 | const p = new pattern_js_1.Pattern(parsed, globParts, 0, platform);
|
68 | const m = new minimatch_1.Minimatch(p.globString(), mmopts);
|
69 | const children = globParts[globParts.length - 1] === '**';
|
70 | const absolute = p.isAbsolute();
|
71 | if (absolute)
|
72 | this.absolute.push(m);
|
73 | else
|
74 | this.relative.push(m);
|
75 | if (children) {
|
76 | if (absolute)
|
77 | this.absoluteChildren.push(m);
|
78 | else
|
79 | this.relativeChildren.push(m);
|
80 | }
|
81 | }
|
82 | }
|
83 | }
|
84 | ignored(p) {
|
85 | const fullpath = p.fullpath();
|
86 | const fullpaths = `${fullpath}/`;
|
87 | const relative = p.relative() || '.';
|
88 | const relatives = `${relative}/`;
|
89 | for (const m of this.relative) {
|
90 | if (m.match(relative) || m.match(relatives))
|
91 | return true;
|
92 | }
|
93 | for (const m of this.absolute) {
|
94 | if (m.match(fullpath) || m.match(fullpaths))
|
95 | return true;
|
96 | }
|
97 | return false;
|
98 | }
|
99 | childrenIgnored(p) {
|
100 | const fullpath = p.fullpath() + '/';
|
101 | const relative = (p.relative() || '.') + '/';
|
102 | for (const m of this.relativeChildren) {
|
103 | if (m.match(relative))
|
104 | return true;
|
105 | }
|
106 | for (const m of this.absoluteChildren) {
|
107 | if (m.match(fullpath))
|
108 | return true;
|
109 | }
|
110 | return false;
|
111 | }
|
112 | }
|
113 | exports.Ignore = Ignore;
|
114 |
|
\ | No newline at end of file |