123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.default = globsToMatcher;
- function _micromatch() {
- const data = _interopRequireDefault(require('micromatch'));
- _micromatch = function () {
- return data;
- };
- return data;
- }
- var _replacePathSepForGlob = _interopRequireDefault(
- require('./replacePathSepForGlob')
- );
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
- const globsToMatchersMap = new Map();
- const micromatchOptions = {
- dot: true
- };
- function globsToMatcher(globs) {
- if (globs.length === 0) {
-
-
- return () => false;
- }
- const matchers = globs.map(glob => {
- if (!globsToMatchersMap.has(glob)) {
-
-
- const {negated} = _micromatch().default.scan(glob, micromatchOptions);
- const matcher = {
- isMatch: _micromatch().default.matcher(glob, micromatchOptions),
- negated
- };
- globsToMatchersMap.set(glob, matcher);
- }
- return globsToMatchersMap.get(glob);
- });
- return path => {
- const replacedPath = (0, _replacePathSepForGlob.default)(path);
- let kept = undefined;
- let negatives = 0;
- for (let i = 0; i < matchers.length; i++) {
- const {isMatch, negated} = matchers[i];
- if (negated) {
- negatives++;
- }
- const matched = isMatch(replacedPath);
- if (!matched && negated) {
-
-
-
- kept = false;
- } else if (matched && !negated) {
-
-
- kept = true;
- }
- }
-
-
-
-
-
- return negatives === matchers.length ? kept !== false : !!kept;
- };
- }
|