legacy.js 20 KB

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