2 Object.defineProperty(exports, "__esModule", { value: true });
\r
3 var pathUtils = require("../../utils/path");
\r
4 var patternUtils = require("../../utils/pattern");
\r
5 var DeepFilter = /** @class */ (function () {
\r
6 function DeepFilter(options, micromatchOptions) {
\r
7 this.options = options;
\r
8 this.micromatchOptions = micromatchOptions;
\r
11 * Returns filter for directories.
\r
13 DeepFilter.prototype.getFilter = function (positive, negative) {
\r
15 var maxPatternDepth = this.getMaxPatternDepth(positive);
\r
16 var negativeRe = this.getNegativePatternsRe(negative);
\r
17 return function (entry) { return _this.filter(entry, negativeRe, maxPatternDepth); };
\r
20 * Returns max depth of the provided patterns.
\r
22 DeepFilter.prototype.getMaxPatternDepth = function (patterns) {
\r
23 var globstar = patterns.some(patternUtils.hasGlobStar);
\r
24 return globstar ? Infinity : patternUtils.getMaxNaivePatternsDepth(patterns);
\r
27 * Returns RegExp's for patterns that can affect the depth of reading.
\r
29 DeepFilter.prototype.getNegativePatternsRe = function (patterns) {
\r
30 var affectDepthOfReadingPatterns = patterns.filter(patternUtils.isAffectDepthOfReadingPattern);
\r
31 return patternUtils.convertPatternsToRe(affectDepthOfReadingPatterns, this.micromatchOptions);
\r
34 * Returns «true» for directory that should be read.
\r
36 DeepFilter.prototype.filter = function (entry, negativeRe, maxPatternDepth) {
\r
37 if (this.isSkippedByDeepOption(entry.depth)) {
\r
40 if (this.isSkippedByMaxPatternDepth(entry.depth, maxPatternDepth)) {
\r
43 if (this.isSkippedSymlinkedDirectory(entry)) {
\r
46 if (this.isSkippedDotDirectory(entry)) {
\r
49 return this.isSkippedByNegativePatterns(entry, negativeRe);
\r
52 * Returns «true» when the «deep» option is disabled or number and depth of the entry is greater that the option value.
\r
54 DeepFilter.prototype.isSkippedByDeepOption = function (entryDepth) {
\r
55 return !this.options.deep || (typeof this.options.deep === 'number' && entryDepth >= this.options.deep);
\r
58 * Returns «true» when depth parameter is not an Infinity and entry depth greater that the parameter value.
\r
60 DeepFilter.prototype.isSkippedByMaxPatternDepth = function (entryDepth, maxPatternDepth) {
\r
61 return maxPatternDepth !== Infinity && entryDepth >= maxPatternDepth;
\r
64 * Returns «true» for symlinked directory if the «followSymlinkedDirectories» option is disabled.
\r
66 DeepFilter.prototype.isSkippedSymlinkedDirectory = function (entry) {
\r
67 return !this.options.followSymlinkedDirectories && entry.isSymbolicLink();
\r
70 * Returns «true» for a directory whose name starts with a period if «dot» option is disabled.
\r
72 DeepFilter.prototype.isSkippedDotDirectory = function (entry) {
\r
73 return !this.options.dot && pathUtils.isDotDirectory(entry.path);
\r
76 * Returns «true» for a directory whose path math to any negative pattern.
\r
78 DeepFilter.prototype.isSkippedByNegativePatterns = function (entry, negativeRe) {
\r
79 return !patternUtils.matchAny(entry.path, negativeRe);
\r
83 exports.default = DeepFilter;
\r