--- /dev/null
+"use strict";\r
+Object.defineProperty(exports, "__esModule", { value: true });\r
+var pathUtils = require("../../utils/path");\r
+var patternUtils = require("../../utils/pattern");\r
+var EntryFilter = /** @class */ (function () {\r
+ function EntryFilter(options, micromatchOptions) {\r
+ this.options = options;\r
+ this.micromatchOptions = micromatchOptions;\r
+ this.index = new Map();\r
+ }\r
+ /**\r
+ * Returns filter for directories.\r
+ */\r
+ EntryFilter.prototype.getFilter = function (positive, negative) {\r
+ var _this = this;\r
+ var positiveRe = patternUtils.convertPatternsToRe(positive, this.micromatchOptions);\r
+ var negativeRe = patternUtils.convertPatternsToRe(negative, this.micromatchOptions);\r
+ return function (entry) { return _this.filter(entry, positiveRe, negativeRe); };\r
+ };\r
+ /**\r
+ * Returns true if entry must be added to result.\r
+ */\r
+ EntryFilter.prototype.filter = function (entry, positiveRe, negativeRe) {\r
+ // Exclude duplicate results\r
+ if (this.options.unique) {\r
+ if (this.isDuplicateEntry(entry)) {\r
+ return false;\r
+ }\r
+ this.createIndexRecord(entry);\r
+ }\r
+ // Filter files and directories by options\r
+ if (this.onlyFileFilter(entry) || this.onlyDirectoryFilter(entry)) {\r
+ return false;\r
+ }\r
+ if (this.isSkippedByAbsoluteNegativePatterns(entry, negativeRe)) {\r
+ return false;\r
+ }\r
+ return this.isMatchToPatterns(entry.path, positiveRe) && !this.isMatchToPatterns(entry.path, negativeRe);\r
+ };\r
+ /**\r
+ * Return true if the entry already has in the cross reader index.\r
+ */\r
+ EntryFilter.prototype.isDuplicateEntry = function (entry) {\r
+ return this.index.has(entry.path);\r
+ };\r
+ /**\r
+ * Create record in the cross reader index.\r
+ */\r
+ EntryFilter.prototype.createIndexRecord = function (entry) {\r
+ this.index.set(entry.path, undefined);\r
+ };\r
+ /**\r
+ * Returns true for non-files if the «onlyFiles» option is enabled.\r
+ */\r
+ EntryFilter.prototype.onlyFileFilter = function (entry) {\r
+ return this.options.onlyFiles && !entry.isFile();\r
+ };\r
+ /**\r
+ * Returns true for non-directories if the «onlyDirectories» option is enabled.\r
+ */\r
+ EntryFilter.prototype.onlyDirectoryFilter = function (entry) {\r
+ return this.options.onlyDirectories && !entry.isDirectory();\r
+ };\r
+ /**\r
+ * Return true when `absolute` option is enabled and matched to the negative patterns.\r
+ */\r
+ EntryFilter.prototype.isSkippedByAbsoluteNegativePatterns = function (entry, negativeRe) {\r
+ if (!this.options.absolute) {\r
+ return false;\r
+ }\r
+ var fullpath = pathUtils.makeAbsolute(this.options.cwd, entry.path);\r
+ return this.isMatchToPatterns(fullpath, negativeRe);\r
+ };\r
+ /**\r
+ * Return true when entry match to provided patterns.\r
+ *\r
+ * First, just trying to apply patterns to the path.\r
+ * Second, trying to apply patterns to the path with final slash (need to micromatch to support «directory/**» patterns).\r
+ */\r
+ EntryFilter.prototype.isMatchToPatterns = function (filepath, patternsRe) {\r
+ return patternUtils.matchAny(filepath, patternsRe) || patternUtils.matchAny(filepath + '/', patternsRe);\r
+ };\r
+ return EntryFilter;\r
+}());\r
+exports.default = EntryFilter;\r