[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
---|
| 4 |
|
---|
| 5 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
---|
| 6 |
|
---|
| 7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
---|
| 8 |
|
---|
| 9 | // A simple implementation of make-array
|
---|
| 10 | function makeArray(subject) {
|
---|
| 11 | return Array.isArray(subject) ? subject : [subject];
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | var EMPTY = '';
|
---|
| 15 | var SPACE = ' ';
|
---|
| 16 | var ESCAPE = '\\';
|
---|
| 17 | var REGEX_TEST_BLANK_LINE = /^\s+$/;
|
---|
| 18 | var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
---|
| 19 | var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
---|
| 20 | var REGEX_SPLITALL_CRLF = /\r?\n/g; // /foo,
|
---|
| 21 | // ./foo,
|
---|
| 22 | // ../foo,
|
---|
| 23 | // .
|
---|
| 24 | // ..
|
---|
| 25 |
|
---|
| 26 | var REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/;
|
---|
| 27 | var SLASH = '/';
|
---|
| 28 | var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol["for"]('node-ignore')
|
---|
| 29 | /* istanbul ignore next */
|
---|
| 30 | : 'node-ignore';
|
---|
| 31 |
|
---|
| 32 | var define = function define(object, key, value) {
|
---|
| 33 | return Object.defineProperty(object, key, {
|
---|
| 34 | value: value
|
---|
| 35 | });
|
---|
| 36 | };
|
---|
| 37 |
|
---|
| 38 | var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
|
---|
| 39 | // The cases are complicated, see test cases for details
|
---|
| 40 |
|
---|
| 41 | var sanitizeRange = function sanitizeRange(range) {
|
---|
| 42 | return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) {
|
---|
| 43 | return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but
|
---|
| 44 | // fatal for JavaScript regular expression, so eliminate it.
|
---|
| 45 | : EMPTY;
|
---|
| 46 | });
|
---|
| 47 | }; // See fixtures #59
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | var cleanRangeBackSlash = function cleanRangeBackSlash(slashes) {
|
---|
| 51 | var length = slashes.length;
|
---|
| 52 | return slashes.slice(0, length - length % 2);
|
---|
| 53 | }; // > If the pattern ends with a slash,
|
---|
| 54 | // > it is removed for the purpose of the following description,
|
---|
| 55 | // > but it would only find a match with a directory.
|
---|
| 56 | // > In other words, foo/ will match a directory foo and paths underneath it,
|
---|
| 57 | // > but will not match a regular file or a symbolic link foo
|
---|
| 58 | // > (this is consistent with the way how pathspec works in general in Git).
|
---|
| 59 | // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
|
---|
| 60 | // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
|
---|
| 61 | // you could use option `mark: true` with `glob`
|
---|
| 62 | // '`foo/`' should not continue with the '`..`'
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | var REPLACERS = [// > Trailing spaces are ignored unless they are quoted with backslash ("\")
|
---|
| 66 | [// (a\ ) -> (a )
|
---|
| 67 | // (a ) -> (a)
|
---|
| 68 | // (a \ ) -> (a )
|
---|
| 69 | /\\?\s+$/, function (match) {
|
---|
| 70 | return match.indexOf('\\') === 0 ? SPACE : EMPTY;
|
---|
| 71 | }], // replace (\ ) with ' '
|
---|
| 72 | [/\\\s/g, function () {
|
---|
| 73 | return SPACE;
|
---|
| 74 | }], // Escape metacharacters
|
---|
| 75 | // which is written down by users but means special for regular expressions.
|
---|
| 76 | // > There are 12 characters with special meanings:
|
---|
| 77 | // > - the backslash \,
|
---|
| 78 | // > - the caret ^,
|
---|
| 79 | // > - the dollar sign $,
|
---|
| 80 | // > - the period or dot .,
|
---|
| 81 | // > - the vertical bar or pipe symbol |,
|
---|
| 82 | // > - the question mark ?,
|
---|
| 83 | // > - the asterisk or star *,
|
---|
| 84 | // > - the plus sign +,
|
---|
| 85 | // > - the opening parenthesis (,
|
---|
| 86 | // > - the closing parenthesis ),
|
---|
| 87 | // > - and the opening square bracket [,
|
---|
| 88 | // > - the opening curly brace {,
|
---|
| 89 | // > These special characters are often called "metacharacters".
|
---|
| 90 | [/[\\$.|*+(){^]/g, function (match) {
|
---|
| 91 | return "\\".concat(match);
|
---|
| 92 | }], [// > a question mark (?) matches a single character
|
---|
| 93 | /(?!\\)\?/g, function () {
|
---|
| 94 | return '[^/]';
|
---|
| 95 | }], // leading slash
|
---|
| 96 | [// > A leading slash matches the beginning of the pathname.
|
---|
| 97 | // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
---|
| 98 | // A leading slash matches the beginning of the pathname
|
---|
| 99 | /^\//, function () {
|
---|
| 100 | return '^';
|
---|
| 101 | }], // replace special metacharacter slash after the leading slash
|
---|
| 102 | [/\//g, function () {
|
---|
| 103 | return '\\/';
|
---|
| 104 | }], [// > A leading "**" followed by a slash means match in all directories.
|
---|
| 105 | // > For example, "**/foo" matches file or directory "foo" anywhere,
|
---|
| 106 | // > the same as pattern "foo".
|
---|
| 107 | // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
---|
| 108 | // > under directory "foo".
|
---|
| 109 | // Notice that the '*'s have been replaced as '\\*'
|
---|
| 110 | /^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo'
|
---|
| 111 | function () {
|
---|
| 112 | return '^(?:.*\\/)?';
|
---|
| 113 | }], // starting
|
---|
| 114 | [// there will be no leading '/'
|
---|
| 115 | // (which has been replaced by section "leading slash")
|
---|
| 116 | // If starts with '**', adding a '^' to the regular expression also works
|
---|
| 117 | /^(?=[^^])/, function startingReplacer() {
|
---|
| 118 | // If has a slash `/` at the beginning or middle
|
---|
| 119 | return !/\/(?!$)/.test(this) // > Prior to 2.22.1
|
---|
| 120 | // > If the pattern does not contain a slash /,
|
---|
| 121 | // > Git treats it as a shell glob pattern
|
---|
| 122 | // Actually, if there is only a trailing slash,
|
---|
| 123 | // git also treats it as a shell glob pattern
|
---|
| 124 | // After 2.22.1 (compatible but clearer)
|
---|
| 125 | // > If there is a separator at the beginning or middle (or both)
|
---|
| 126 | // > of the pattern, then the pattern is relative to the directory
|
---|
| 127 | // > level of the particular .gitignore file itself.
|
---|
| 128 | // > Otherwise the pattern may also match at any level below
|
---|
| 129 | // > the .gitignore level.
|
---|
| 130 | ? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for
|
---|
| 131 | // > consumption by fnmatch(3)
|
---|
| 132 | : '^';
|
---|
| 133 | }], // two globstars
|
---|
| 134 | [// Use lookahead assertions so that we could match more than one `'/**'`
|
---|
| 135 | /\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories
|
---|
| 136 | // should not use '*', or it will be replaced by the next replacer
|
---|
| 137 | // Check if it is not the last `'/**'`
|
---|
| 138 | function (_, index, str) {
|
---|
| 139 | return index + 6 < str.length // case: /**/
|
---|
| 140 | // > A slash followed by two consecutive asterisks then a slash matches
|
---|
| 141 | // > zero or more directories.
|
---|
| 142 | // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
|
---|
| 143 | // '/**/'
|
---|
| 144 | ? '(?:\\/[^\\/]+)*' // case: /**
|
---|
| 145 | // > A trailing `"/**"` matches everything inside.
|
---|
| 146 | // #21: everything inside but it should not include the current folder
|
---|
| 147 | : '\\/.+';
|
---|
| 148 | }], // intermediate wildcards
|
---|
| 149 | [// Never replace escaped '*'
|
---|
| 150 | // ignore rule '\*' will match the path '*'
|
---|
| 151 | // 'abc.*/' -> go
|
---|
| 152 | // 'abc.*' -> skip this rule
|
---|
| 153 | /(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js'
|
---|
| 154 | // '*.js' doesn't match 'abc'
|
---|
| 155 | function (_, p1) {
|
---|
| 156 | return "".concat(p1, "[^\\/]*");
|
---|
| 157 | }], [// unescape, revert step 3 except for back slash
|
---|
| 158 | // For example, if a user escape a '\\*',
|
---|
| 159 | // after step 3, the result will be '\\\\\\*'
|
---|
| 160 | /\\\\\\(?=[$.|*+(){^])/g, function () {
|
---|
| 161 | return ESCAPE;
|
---|
| 162 | }], [// '\\\\' -> '\\'
|
---|
| 163 | /\\\\/g, function () {
|
---|
| 164 | return ESCAPE;
|
---|
| 165 | }], [// > The range notation, e.g. [a-zA-Z],
|
---|
| 166 | // > can be used to match one of the characters in a range.
|
---|
| 167 | // `\` is escaped by step 3
|
---|
| 168 | /(\\)?\[([^\]/]*?)(\\*)($|\])/g, function (match, leadEscape, range, endEscape, close) {
|
---|
| 169 | return leadEscape === ESCAPE // '\\[bar]' -> '\\\\[bar\\]'
|
---|
| 170 | ? "\\[".concat(range).concat(cleanRangeBackSlash(endEscape)).concat(close) : close === ']' ? endEscape.length % 2 === 0 // A normal case, and it is a range notation
|
---|
| 171 | // '[bar]'
|
---|
| 172 | // '[bar\\\\]'
|
---|
| 173 | ? "[".concat(sanitizeRange(range)).concat(endEscape, "]") // Invalid range notaton
|
---|
| 174 | // '[bar\\]' -> '[bar\\\\]'
|
---|
| 175 | : '[]' : '[]';
|
---|
| 176 | }], // ending
|
---|
| 177 | [// 'js' will not match 'js.'
|
---|
| 178 | // 'ab' will not match 'abc'
|
---|
| 179 | /(?:[^*])$/, // WTF!
|
---|
| 180 | // https://git-scm.com/docs/gitignore
|
---|
| 181 | // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
---|
| 182 | // which re-fixes #24, #38
|
---|
| 183 | // > If there is a separator at the end of the pattern then the pattern
|
---|
| 184 | // > will only match directories, otherwise the pattern can match both
|
---|
| 185 | // > files and directories.
|
---|
| 186 | // 'js*' will not match 'a.js'
|
---|
| 187 | // 'js/' will not match 'a.js'
|
---|
| 188 | // 'js' will match 'a.js' and 'a.js/'
|
---|
| 189 | function (match) {
|
---|
| 190 | return /\/$/.test(match) // foo/ will not match 'foo'
|
---|
| 191 | ? "".concat(match, "$") // foo matches 'foo' and 'foo/'
|
---|
| 192 | : "".concat(match, "(?=$|\\/$)");
|
---|
| 193 | }], // trailing wildcard
|
---|
| 194 | [/(\^|\\\/)?\\\*$/, function (_, p1) {
|
---|
| 195 | var prefix = p1 // '\^':
|
---|
| 196 | // '/*' does not match EMPTY
|
---|
| 197 | // '/*' does not match everything
|
---|
| 198 | // '\\\/':
|
---|
| 199 | // 'abc/*' does not match 'abc/'
|
---|
| 200 | ? "".concat(p1, "[^/]+") // 'a*' matches 'a'
|
---|
| 201 | // 'a*' matches 'aa'
|
---|
| 202 | : '[^/]*';
|
---|
| 203 | return "".concat(prefix, "(?=$|\\/$)");
|
---|
| 204 | }]]; // A simple cache, because an ignore rule only has only one certain meaning
|
---|
| 205 |
|
---|
| 206 | var regexCache = Object.create(null); // @param {pattern}
|
---|
| 207 |
|
---|
[e29cc2e] | 208 | var makeRegex = function makeRegex(pattern, ignorecase) {
|
---|
| 209 | var source = regexCache[pattern];
|
---|
| 210 |
|
---|
| 211 | if (!source) {
|
---|
| 212 | source = REPLACERS.reduce(function (prev, current) {
|
---|
| 213 | return prev.replace(current[0], current[1].bind(pattern));
|
---|
| 214 | }, pattern);
|
---|
| 215 | regexCache[pattern] = source;
|
---|
| 216 | }
|
---|
[6a3a178] | 217 |
|
---|
[e29cc2e] | 218 | return ignorecase ? new RegExp(source, 'i') : new RegExp(source);
|
---|
[6a3a178] | 219 | };
|
---|
| 220 |
|
---|
| 221 | var isString = function isString(subject) {
|
---|
| 222 | return typeof subject === 'string';
|
---|
| 223 | }; // > A blank line matches no files, so it can serve as a separator for readability.
|
---|
| 224 |
|
---|
| 225 |
|
---|
| 226 | var checkPattern = function checkPattern(pattern) {
|
---|
| 227 | return pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment.
|
---|
| 228 | && pattern.indexOf('#') !== 0;
|
---|
| 229 | };
|
---|
| 230 |
|
---|
| 231 | var splitPattern = function splitPattern(pattern) {
|
---|
| 232 | return pattern.split(REGEX_SPLITALL_CRLF);
|
---|
| 233 | };
|
---|
| 234 |
|
---|
| 235 | var IgnoreRule = function IgnoreRule(origin, pattern, negative, regex) {
|
---|
| 236 | _classCallCheck(this, IgnoreRule);
|
---|
| 237 |
|
---|
| 238 | this.origin = origin;
|
---|
| 239 | this.pattern = pattern;
|
---|
| 240 | this.negative = negative;
|
---|
| 241 | this.regex = regex;
|
---|
| 242 | };
|
---|
| 243 |
|
---|
| 244 | var createRule = function createRule(pattern, ignorecase) {
|
---|
| 245 | var origin = pattern;
|
---|
| 246 | var negative = false; // > An optional prefix "!" which negates the pattern;
|
---|
| 247 |
|
---|
| 248 | if (pattern.indexOf('!') === 0) {
|
---|
| 249 | negative = true;
|
---|
| 250 | pattern = pattern.substr(1);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that
|
---|
| 254 | // > begin with a literal "!", for example, `"\!important!.txt"`.
|
---|
| 255 | .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that
|
---|
| 256 | // > begin with a hash.
|
---|
| 257 | .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
|
---|
[e29cc2e] | 258 | var regex = makeRegex(pattern, ignorecase);
|
---|
[6a3a178] | 259 | return new IgnoreRule(origin, pattern, negative, regex);
|
---|
| 260 | };
|
---|
| 261 |
|
---|
| 262 | var throwError = function throwError(message, Ctor) {
|
---|
| 263 | throw new Ctor(message);
|
---|
| 264 | };
|
---|
| 265 |
|
---|
| 266 | var checkPath = function checkPath(path, originalPath, doThrow) {
|
---|
| 267 | if (!isString(path)) {
|
---|
| 268 | return doThrow("path must be a string, but got `".concat(originalPath, "`"), TypeError);
|
---|
| 269 | } // We don't know if we should ignore EMPTY, so throw
|
---|
| 270 |
|
---|
| 271 |
|
---|
| 272 | if (!path) {
|
---|
| 273 | return doThrow("path must not be empty", TypeError);
|
---|
| 274 | } // Check if it is a relative path
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | if (checkPath.isNotRelative(path)) {
|
---|
| 278 | var r = '`path.relative()`d';
|
---|
| 279 | return doThrow("path should be a ".concat(r, " string, but got \"").concat(originalPath, "\""), RangeError);
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | return true;
|
---|
| 283 | };
|
---|
| 284 |
|
---|
| 285 | var isNotRelative = function isNotRelative(path) {
|
---|
| 286 | return REGEX_TEST_INVALID_PATH.test(path);
|
---|
| 287 | };
|
---|
| 288 |
|
---|
| 289 | checkPath.isNotRelative = isNotRelative;
|
---|
| 290 |
|
---|
| 291 | checkPath.convert = function (p) {
|
---|
| 292 | return p;
|
---|
| 293 | };
|
---|
| 294 |
|
---|
| 295 | var Ignore = /*#__PURE__*/function () {
|
---|
| 296 | function Ignore() {
|
---|
| 297 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
---|
| 298 | _ref$ignorecase = _ref.ignorecase,
|
---|
| 299 | ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
|
---|
| 300 |
|
---|
| 301 | _classCallCheck(this, Ignore);
|
---|
| 302 |
|
---|
[e29cc2e] | 303 | define(this, KEY_IGNORE, true);
|
---|
[6a3a178] | 304 | this._rules = [];
|
---|
| 305 | this._ignorecase = ignorecase;
|
---|
| 306 |
|
---|
| 307 | this._initCache();
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | _createClass(Ignore, [{
|
---|
| 311 | key: "_initCache",
|
---|
| 312 | value: function _initCache() {
|
---|
| 313 | this._ignoreCache = Object.create(null);
|
---|
| 314 | this._testCache = Object.create(null);
|
---|
| 315 | }
|
---|
| 316 | }, {
|
---|
| 317 | key: "_addPattern",
|
---|
| 318 | value: function _addPattern(pattern) {
|
---|
| 319 | // #32
|
---|
| 320 | if (pattern && pattern[KEY_IGNORE]) {
|
---|
| 321 | this._rules = this._rules.concat(pattern._rules);
|
---|
| 322 | this._added = true;
|
---|
| 323 | return;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | if (checkPattern(pattern)) {
|
---|
| 327 | var rule = createRule(pattern, this._ignorecase);
|
---|
| 328 | this._added = true;
|
---|
| 329 |
|
---|
| 330 | this._rules.push(rule);
|
---|
| 331 | }
|
---|
| 332 | } // @param {Array<string> | string | Ignore} pattern
|
---|
| 333 |
|
---|
| 334 | }, {
|
---|
| 335 | key: "add",
|
---|
| 336 | value: function add(pattern) {
|
---|
| 337 | this._added = false;
|
---|
| 338 | makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore,
|
---|
| 339 | // making the behavior changed.
|
---|
| 340 |
|
---|
| 341 | if (this._added) {
|
---|
| 342 | this._initCache();
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | return this;
|
---|
| 346 | } // legacy
|
---|
| 347 |
|
---|
| 348 | }, {
|
---|
| 349 | key: "addPattern",
|
---|
| 350 | value: function addPattern(pattern) {
|
---|
| 351 | return this.add(pattern);
|
---|
| 352 | } // | ignored : unignored
|
---|
| 353 | // negative | 0:0 | 0:1 | 1:0 | 1:1
|
---|
| 354 | // -------- | ------- | ------- | ------- | --------
|
---|
| 355 | // 0 | TEST | TEST | SKIP | X
|
---|
| 356 | // 1 | TESTIF | SKIP | TEST | X
|
---|
| 357 | // - SKIP: always skip
|
---|
| 358 | // - TEST: always test
|
---|
| 359 | // - TESTIF: only test if checkUnignored
|
---|
| 360 | // - X: that never happen
|
---|
| 361 | // @param {boolean} whether should check if the path is unignored,
|
---|
| 362 | // setting `checkUnignored` to `false` could reduce additional
|
---|
| 363 | // path matching.
|
---|
| 364 | // @returns {TestResult} true if a file is ignored
|
---|
| 365 |
|
---|
| 366 | }, {
|
---|
| 367 | key: "_testOne",
|
---|
| 368 | value: function _testOne(path, checkUnignored) {
|
---|
| 369 | var ignored = false;
|
---|
| 370 | var unignored = false;
|
---|
| 371 |
|
---|
| 372 | this._rules.forEach(function (rule) {
|
---|
| 373 | var negative = rule.negative;
|
---|
| 374 |
|
---|
| 375 | if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
---|
| 376 | return;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | var matched = rule.regex.test(path);
|
---|
| 380 |
|
---|
| 381 | if (matched) {
|
---|
| 382 | ignored = !negative;
|
---|
| 383 | unignored = negative;
|
---|
| 384 | }
|
---|
| 385 | });
|
---|
| 386 |
|
---|
| 387 | return {
|
---|
| 388 | ignored: ignored,
|
---|
| 389 | unignored: unignored
|
---|
| 390 | };
|
---|
| 391 | } // @returns {TestResult}
|
---|
| 392 |
|
---|
| 393 | }, {
|
---|
| 394 | key: "_test",
|
---|
| 395 | value: function _test(originalPath, cache, checkUnignored, slices) {
|
---|
| 396 | var path = originalPath // Supports nullable path
|
---|
| 397 | && checkPath.convert(originalPath);
|
---|
| 398 | checkPath(path, originalPath, throwError);
|
---|
| 399 | return this._t(path, cache, checkUnignored, slices);
|
---|
| 400 | }
|
---|
| 401 | }, {
|
---|
| 402 | key: "_t",
|
---|
| 403 | value: function _t(path, cache, checkUnignored, slices) {
|
---|
| 404 | if (path in cache) {
|
---|
| 405 | return cache[path];
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | if (!slices) {
|
---|
| 409 | // path/to/a.js
|
---|
| 410 | // ['path', 'to', 'a.js']
|
---|
| 411 | slices = path.split(SLASH);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | slices.pop(); // If the path has no parent directory, just test it
|
---|
| 415 |
|
---|
| 416 | if (!slices.length) {
|
---|
| 417 | return cache[path] = this._testOne(path, checkUnignored);
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | var parent = this._t(slices.join(SLASH) + SLASH, cache, checkUnignored, slices); // If the path contains a parent directory, check the parent first
|
---|
| 421 |
|
---|
| 422 |
|
---|
| 423 | return cache[path] = parent.ignored // > It is not possible to re-include a file if a parent directory of
|
---|
| 424 | // > that file is excluded.
|
---|
| 425 | ? parent : this._testOne(path, checkUnignored);
|
---|
| 426 | }
|
---|
| 427 | }, {
|
---|
| 428 | key: "ignores",
|
---|
| 429 | value: function ignores(path) {
|
---|
| 430 | return this._test(path, this._ignoreCache, false).ignored;
|
---|
| 431 | }
|
---|
| 432 | }, {
|
---|
| 433 | key: "createFilter",
|
---|
| 434 | value: function createFilter() {
|
---|
| 435 | var _this = this;
|
---|
| 436 |
|
---|
| 437 | return function (path) {
|
---|
| 438 | return !_this.ignores(path);
|
---|
| 439 | };
|
---|
| 440 | }
|
---|
| 441 | }, {
|
---|
| 442 | key: "filter",
|
---|
| 443 | value: function filter(paths) {
|
---|
| 444 | return makeArray(paths).filter(this.createFilter());
|
---|
| 445 | } // @returns {TestResult}
|
---|
| 446 |
|
---|
| 447 | }, {
|
---|
| 448 | key: "test",
|
---|
| 449 | value: function test(path) {
|
---|
| 450 | return this._test(path, this._testCache, true);
|
---|
| 451 | }
|
---|
| 452 | }]);
|
---|
| 453 |
|
---|
| 454 | return Ignore;
|
---|
| 455 | }();
|
---|
| 456 |
|
---|
| 457 | var factory = function factory(options) {
|
---|
| 458 | return new Ignore(options);
|
---|
| 459 | };
|
---|
| 460 |
|
---|
| 461 | var returnFalse = function returnFalse() {
|
---|
| 462 | return false;
|
---|
| 463 | };
|
---|
| 464 |
|
---|
| 465 | var isPathValid = function isPathValid(path) {
|
---|
| 466 | return checkPath(path && checkPath.convert(path), path, returnFalse);
|
---|
| 467 | };
|
---|
| 468 |
|
---|
| 469 | factory.isPathValid = isPathValid; // Fixes typescript
|
---|
| 470 |
|
---|
| 471 | factory["default"] = factory;
|
---|
| 472 | module.exports = factory; // Windows
|
---|
| 473 | // --------------------------------------------------------------
|
---|
| 474 |
|
---|
| 475 | /* istanbul ignore if */
|
---|
| 476 |
|
---|
| 477 | if ( // Detect `process` so that it can run in browsers.
|
---|
| 478 | typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) {
|
---|
| 479 | /* eslint no-control-regex: "off" */
|
---|
| 480 | var makePosix = function makePosix(str) {
|
---|
| 481 | return /^\\\\\?\\/.test(str) || /[\0-\x1F"<>\|]+/.test(str) ? str : str.replace(/\\/g, '/');
|
---|
| 482 | };
|
---|
| 483 |
|
---|
| 484 | checkPath.convert = makePosix; // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
|
---|
| 485 | // 'd:\\foo'
|
---|
| 486 |
|
---|
| 487 | var REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
---|
| 488 |
|
---|
| 489 | checkPath.isNotRelative = function (path) {
|
---|
| 490 | return REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
---|
| 491 | };
|
---|
| 492 | }
|
---|