4d5e97ad98659f6fa8b6a37ae0823ed859833ed864dbd3a12c21bd4969e030296ef2258fe6b159828b12a9f714344758a547ade8f3d51caa1b67e1e56999c6 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var pathUtils = require("../../utils/path");
  4. var patternUtils = require("../../utils/pattern");
  5. var DeepFilter = /** @class */ (function () {
  6. function DeepFilter(options, micromatchOptions) {
  7. this.options = options;
  8. this.micromatchOptions = micromatchOptions;
  9. }
  10. /**
  11. * Returns filter for directories.
  12. */
  13. DeepFilter.prototype.getFilter = function (positive, negative) {
  14. var _this = this;
  15. var maxPatternDepth = this.getMaxPatternDepth(positive);
  16. var negativeRe = this.getNegativePatternsRe(negative);
  17. return function (entry) { return _this.filter(entry, negativeRe, maxPatternDepth); };
  18. };
  19. /**
  20. * Returns max depth of the provided patterns.
  21. */
  22. DeepFilter.prototype.getMaxPatternDepth = function (patterns) {
  23. var globstar = patterns.some(patternUtils.hasGlobStar);
  24. return globstar ? Infinity : patternUtils.getMaxNaivePatternsDepth(patterns);
  25. };
  26. /**
  27. * Returns RegExp's for patterns that can affect the depth of reading.
  28. */
  29. DeepFilter.prototype.getNegativePatternsRe = function (patterns) {
  30. var affectDepthOfReadingPatterns = patterns.filter(patternUtils.isAffectDepthOfReadingPattern);
  31. return patternUtils.convertPatternsToRe(affectDepthOfReadingPatterns, this.micromatchOptions);
  32. };
  33. /**
  34. * Returns «true» for directory that should be read.
  35. */
  36. DeepFilter.prototype.filter = function (entry, negativeRe, maxPatternDepth) {
  37. if (this.isSkippedByDeepOption(entry.depth)) {
  38. return false;
  39. }
  40. if (this.isSkippedByMaxPatternDepth(entry.depth, maxPatternDepth)) {
  41. return false;
  42. }
  43. if (this.isSkippedSymlinkedDirectory(entry)) {
  44. return false;
  45. }
  46. if (this.isSkippedDotDirectory(entry)) {
  47. return false;
  48. }
  49. return this.isSkippedByNegativePatterns(entry, negativeRe);
  50. };
  51. /**
  52. * Returns «true» when the «deep» option is disabled or number and depth of the entry is greater that the option value.
  53. */
  54. DeepFilter.prototype.isSkippedByDeepOption = function (entryDepth) {
  55. return !this.options.deep || (typeof this.options.deep === 'number' && entryDepth >= this.options.deep);
  56. };
  57. /**
  58. * Returns «true» when depth parameter is not an Infinity and entry depth greater that the parameter value.
  59. */
  60. DeepFilter.prototype.isSkippedByMaxPatternDepth = function (entryDepth, maxPatternDepth) {
  61. return maxPatternDepth !== Infinity && entryDepth >= maxPatternDepth;
  62. };
  63. /**
  64. * Returns «true» for symlinked directory if the «followSymlinkedDirectories» option is disabled.
  65. */
  66. DeepFilter.prototype.isSkippedSymlinkedDirectory = function (entry) {
  67. return !this.options.followSymlinkedDirectories && entry.isSymbolicLink();
  68. };
  69. /**
  70. * Returns «true» for a directory whose name starts with a period if «dot» option is disabled.
  71. */
  72. DeepFilter.prototype.isSkippedDotDirectory = function (entry) {
  73. return !this.options.dot && pathUtils.isDotDirectory(entry.path);
  74. };
  75. /**
  76. * Returns «true» for a directory whose path math to any negative pattern.
  77. */
  78. DeepFilter.prototype.isSkippedByNegativePatterns = function (entry, negativeRe) {
  79. return !patternUtils.matchAny(entry.path, negativeRe);
  80. };
  81. return DeepFilter;
  82. }());
  83. exports.default = DeepFilter;