2 Object.defineProperty(exports, "__esModule", { value: true });
\r
3 var pathUtils = require("../../utils/path");
\r
4 var patternUtils = require("../../utils/pattern");
\r
5 var EntryFilter = /** @class */ (function () {
\r
6 function EntryFilter(options, micromatchOptions) {
\r
7 this.options = options;
\r
8 this.micromatchOptions = micromatchOptions;
\r
9 this.index = new Map();
\r
12 * Returns filter for directories.
\r
14 EntryFilter.prototype.getFilter = function (positive, negative) {
\r
16 var positiveRe = patternUtils.convertPatternsToRe(positive, this.micromatchOptions);
\r
17 var negativeRe = patternUtils.convertPatternsToRe(negative, this.micromatchOptions);
\r
18 return function (entry) { return _this.filter(entry, positiveRe, negativeRe); };
\r
21 * Returns true if entry must be added to result.
\r
23 EntryFilter.prototype.filter = function (entry, positiveRe, negativeRe) {
\r
24 // Exclude duplicate results
\r
25 if (this.options.unique) {
\r
26 if (this.isDuplicateEntry(entry)) {
\r
29 this.createIndexRecord(entry);
\r
31 // Filter files and directories by options
\r
32 if (this.onlyFileFilter(entry) || this.onlyDirectoryFilter(entry)) {
\r
35 if (this.isSkippedByAbsoluteNegativePatterns(entry, negativeRe)) {
\r
38 return this.isMatchToPatterns(entry.path, positiveRe) && !this.isMatchToPatterns(entry.path, negativeRe);
\r
41 * Return true if the entry already has in the cross reader index.
\r
43 EntryFilter.prototype.isDuplicateEntry = function (entry) {
\r
44 return this.index.has(entry.path);
\r
47 * Create record in the cross reader index.
\r
49 EntryFilter.prototype.createIndexRecord = function (entry) {
\r
50 this.index.set(entry.path, undefined);
\r
53 * Returns true for non-files if the «onlyFiles» option is enabled.
\r
55 EntryFilter.prototype.onlyFileFilter = function (entry) {
\r
56 return this.options.onlyFiles && !entry.isFile();
\r
59 * Returns true for non-directories if the «onlyDirectories» option is enabled.
\r
61 EntryFilter.prototype.onlyDirectoryFilter = function (entry) {
\r
62 return this.options.onlyDirectories && !entry.isDirectory();
\r
65 * Return true when `absolute` option is enabled and matched to the negative patterns.
\r
67 EntryFilter.prototype.isSkippedByAbsoluteNegativePatterns = function (entry, negativeRe) {
\r
68 if (!this.options.absolute) {
\r
71 var fullpath = pathUtils.makeAbsolute(this.options.cwd, entry.path);
\r
72 return this.isMatchToPatterns(fullpath, negativeRe);
\r
75 * Return true when entry match to provided patterns.
\r
77 * First, just trying to apply patterns to the path.
\r
78 * Second, trying to apply patterns to the path with final slash (need to micromatch to support «directory/**» patterns).
\r
80 EntryFilter.prototype.isMatchToPatterns = function (filepath, patternsRe) {
\r
81 return patternUtils.matchAny(filepath, patternsRe) || patternUtils.matchAny(filepath + '/', patternsRe);
\r
85 exports.default = EntryFilter;
\r