ignore
Advanced tools
Comparing version 5.0.5 to 5.0.6
@@ -30,4 +30,4 @@ # `node-ignore` 5 ChangeLog | ||
- **FEATURE**: supports the missing character ranges and sets, such as `*.[a-z]` and `*.[jJ][pP][gG]` | ||
- **FEATURE**: new option: `ignorecase` to make `ignore` case sensitive. | ||
- **FEATURE**: new option: `ignorecase` to make `ignore` case insensitive. | ||
- **FEATURE**: supports question mark which matches a single character. | ||
- **PATCH**: fixes typescript declaration. |
296
legacy.js
@@ -1,5 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -15,4 +17,3 @@ | ||
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/; | ||
var REGEX_SPLITALL_CRLF = /\r?\n/g; | ||
// /foo, | ||
var REGEX_SPLITALL_CRLF = /\r?\n/g; // /foo, | ||
// ./foo, | ||
@@ -22,4 +23,4 @@ // ../foo, | ||
// .. | ||
var REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/; | ||
var SLASH = '/'; | ||
@@ -31,19 +32,17 @@ var KEY_IGNORE = typeof Symbol !== 'undefined' ? Symbol.for('node-ignore') | ||
var define = function define(object, key, value) { | ||
return Object.defineProperty(object, key, { value }); | ||
return Object.defineProperty(object, key, { | ||
value: value | ||
}); | ||
}; | ||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; | ||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression | ||
// The cases are complicated, see test cases for details | ||
// Sanitize the range of a regular expression | ||
// The cases are complicated, see test cases for details | ||
var sanitizeRange = function sanitizeRange(range) { | ||
return range.replace(REGEX_REGEXP_RANGE, function (match, from, to) { | ||
return from.charCodeAt(0) <= to.charCodeAt(0) ? match | ||
// Invalid range (out of order) which is ok for gitignore rules but | ||
return from.charCodeAt(0) <= to.charCodeAt(0) ? match // Invalid range (out of order) which is ok for gitignore rules but | ||
// fatal for JavaScript regular expression, so eliminate it. | ||
: ''; | ||
}); | ||
}; | ||
// > If the pattern ends with a slash, | ||
}; // > If the pattern ends with a slash, | ||
// > it is removed for the purpose of the following description, | ||
@@ -57,9 +56,7 @@ // > but it would only find a match with a directory. | ||
// you could use option `mark: true` with `glob` | ||
// '`foo/`' should not continue with the '`..`' | ||
var DEFAULT_REPLACER_PREFIX = [ | ||
// > Trailing spaces are ignored unless they are quoted with backslash ("\") | ||
[ | ||
// (a\ ) -> (a ) | ||
var DEFAULT_REPLACER_PREFIX = [// > Trailing spaces are ignored unless they are quoted with backslash ("\") | ||
[// (a\ ) -> (a ) | ||
// (a ) -> (a) | ||
@@ -69,12 +66,7 @@ // (a \ ) -> (a ) | ||
return match.indexOf('\\') === 0 ? ' ' : ''; | ||
}], | ||
// replace (\ ) with ' ' | ||
}], // replace (\ ) with ' ' | ||
[/\\\s/g, function () { | ||
return ' '; | ||
}], | ||
// Escape metacharacters | ||
}], // Escape metacharacters | ||
// which is written down by users but means special for regular expressions. | ||
// > There are 12 characters with special meanings: | ||
@@ -95,18 +87,12 @@ // > - the backslash \, | ||
[/[\\^$.|*+(){]/g, function (match) { | ||
return `\\${match}`; | ||
}], [ | ||
// > [abc] matches any character inside the brackets | ||
return "\\".concat(match); | ||
}], [// > [abc] matches any character inside the brackets | ||
// > (in this case a, b, or c); | ||
/\[([^\]/]*)($|\])/g, function (match, p1, p2) { | ||
return p2 === ']' ? `[${sanitizeRange(p1)}]` : `\\${match}`; | ||
}], [ | ||
// > a question mark (?) matches a single character | ||
return p2 === ']' ? "[".concat(sanitizeRange(p1), "]") : "\\".concat(match); | ||
}], [// > a question mark (?) matches a single character | ||
/(?!\\)\?/g, function () { | ||
return '[^/]'; | ||
}], | ||
// leading slash | ||
[ | ||
// > A leading slash matches the beginning of the pathname. | ||
}], // leading slash | ||
[// > A leading slash matches the beginning of the pathname. | ||
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". | ||
@@ -116,9 +102,6 @@ // A leading slash matches the beginning of the pathname | ||
return '^'; | ||
}], | ||
// replace special metacharacter slash after the leading slash | ||
}], // replace special metacharacter slash after the leading slash | ||
[/\//g, function () { | ||
return '\\/'; | ||
}], [ | ||
// > A leading "**" followed by a slash means match in all directories. | ||
}], [// > A leading "**" followed by a slash means match in all directories. | ||
// > For example, "**/foo" matches file or directory "foo" anywhere, | ||
@@ -129,41 +112,25 @@ // > the same as pattern "foo". | ||
// Notice that the '*'s have been replaced as '\\*' | ||
/^\^*\\\*\\\*\\\//, | ||
// '**/foo' <-> 'foo' | ||
/^\^*\\\*\\\*\\\//, // '**/foo' <-> 'foo' | ||
function () { | ||
return '^(?:.*\\/)?'; | ||
}]]; | ||
var DEFAULT_REPLACER_SUFFIX = [ | ||
// starting | ||
[ | ||
// there will be no leading '/' | ||
var DEFAULT_REPLACER_SUFFIX = [// starting | ||
[// there will be no leading '/' | ||
// (which has been replaced by section "leading slash") | ||
// If starts with '**', adding a '^' to the regular expression also works | ||
/^(?=[^^])/, function startingReplacer() { | ||
return !/\/(?!$)/.test(this) | ||
// > If the pattern does not contain a slash /, | ||
return !/\/(?!$)/.test(this) // > If the pattern does not contain a slash /, | ||
// > Git treats it as a shell glob pattern | ||
// Actually, if there is only a trailing slash, | ||
// git also treats it as a shell glob pattern | ||
? '(?:^|\\/)' | ||
// > Otherwise, Git treats the pattern as a shell glob suitable for | ||
? '(?:^|\\/)' // > Otherwise, Git treats the pattern as a shell glob suitable for | ||
// > consumption by fnmatch(3) | ||
: '^'; | ||
}], | ||
// two globstars | ||
[ | ||
// Use lookahead assertions so that we could match more than one `'/**'` | ||
/\\\/\\\*\\\*(?=\\\/|$)/g, | ||
// Zero, one or several directories | ||
}], // two globstars | ||
[// Use lookahead assertions so that we could match more than one `'/**'` | ||
/\\\/\\\*\\\*(?=\\\/|$)/g, // Zero, one or several directories | ||
// should not use '*', or it will be replaced by the next replacer | ||
// Check if it is not the last `'/**'` | ||
function (_, index, str) { | ||
return index + 6 < str.length | ||
// case: /**/ | ||
return index + 6 < str.length // case: /**/ | ||
// > A slash followed by two consecutive asterisks then a slash matches | ||
@@ -173,51 +140,31 @@ // > zero or more directories. | ||
// '/**/' | ||
? '(?:\\/[^\\/]+)*' | ||
// case: /** | ||
? '(?:\\/[^\\/]+)*' // case: /** | ||
// > A trailing `"/**"` matches everything inside. | ||
// #21: everything inside but it should not include the current folder | ||
: '\\/.+'; | ||
}], | ||
// intermediate wildcards | ||
[ | ||
// Never replace escaped '*' | ||
}], // intermediate wildcards | ||
[// Never replace escaped '*' | ||
// ignore rule '\*' will match the path '*' | ||
// 'abc.*/' -> go | ||
// 'abc.*' -> skip this rule | ||
/(^|[^\\]+)\\\*(?=.+)/g, | ||
// '*.js' matches '.js' | ||
/(^|[^\\]+)\\\*(?=.+)/g, // '*.js' matches '.js' | ||
// '*.js' doesn't match 'abc' | ||
function (_, p1) { | ||
return `${p1}[^\\/]*`; | ||
}], | ||
// trailing wildcard | ||
return "".concat(p1, "[^\\/]*"); | ||
}], // trailing wildcard | ||
[/(\^|\\\/)?\\\*$/, function (_, p1) { | ||
var prefix = p1 | ||
// '\^': | ||
var prefix = p1 // '\^': | ||
// '/*' does not match '' | ||
// '/*' does not match everything | ||
// '\\\/': | ||
// 'abc/*' does not match 'abc/' | ||
? `${p1}[^/]+` | ||
// 'a*' matches 'a' | ||
? "".concat(p1, "[^/]+") // 'a*' matches 'a' | ||
// 'a*' matches 'aa' | ||
: '[^/]*'; | ||
return `${prefix}(?=$|\\/$)`; | ||
}], [ | ||
// unescape | ||
return "".concat(prefix, "(?=$|\\/$)"); | ||
}], [// unescape | ||
/\\\\\\/g, function () { | ||
return '\\'; | ||
}]]; | ||
var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [ | ||
// 'f' | ||
var POSITIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// 'f' | ||
// matches | ||
@@ -233,23 +180,15 @@ // - /f(end) | ||
// -> (^|/)f(/|$) | ||
// ending | ||
[ | ||
// 'js' will not match 'js.' | ||
[// 'js' will not match 'js.' | ||
// 'ab' will not match 'abc' | ||
/(?:[^*/])$/, | ||
// 'js*' will not match 'a.js' | ||
/(?:[^*/])$/, // 'js*' will not match 'a.js' | ||
// 'js/' will not match 'a.js' | ||
// 'js' will match 'a.js' and 'a.js/' | ||
function (match) { | ||
return `${match}(?=$|\\/)`; | ||
return "".concat(match, "(?=$|\\/)"); | ||
}]], DEFAULT_REPLACER_SUFFIX); | ||
var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [ | ||
// #24, #38 | ||
var NEGATIVE_REPLACERS = [].concat(DEFAULT_REPLACER_PREFIX, [// #24, #38 | ||
// The MISSING rule of [gitignore docs](https://git-scm.com/docs/gitignore) | ||
// A negative pattern without a trailing wildcard should not | ||
// re-include the things inside that directory. | ||
// eg: | ||
@@ -259,11 +198,10 @@ // ['node_modules/*', '!node_modules'] | ||
[/(?:[^*])$/, function (match) { | ||
return `${match}(?=$|\\/$)`; | ||
}]], DEFAULT_REPLACER_SUFFIX); | ||
return "".concat(match, "(?=$|\\/$)"); | ||
}]], DEFAULT_REPLACER_SUFFIX); // A simple cache, because an ignore rule only has only one certain meaning | ||
// A simple cache, because an ignore rule only has only one certain meaning | ||
var regexCache = Object.create(null); | ||
var regexCache = Object.create(null); // @param {pattern} | ||
// @param {pattern} | ||
var makeRegex = function makeRegex(pattern, negative, ignorecase) { | ||
var r = regexCache[pattern]; | ||
if (r) { | ||
@@ -274,7 +212,5 @@ return r; | ||
var replacers = negative ? NEGATIVE_REPLACERS : POSITIVE_REPLACERS; | ||
var source = replacers.reduce(function (prev, current) { | ||
return prev.replace(current[0], current[1].bind(pattern)); | ||
}, pattern); | ||
return regexCache[pattern] = ignorecase ? new RegExp(source, 'i') : new RegExp(source); | ||
@@ -285,9 +221,7 @@ }; | ||
return typeof subject === 'string'; | ||
}; | ||
}; // > A blank line matches no files, so it can serve as a separator for readability. | ||
// > A blank line matches no files, so it can serve as a separator for readability. | ||
var checkPattern = function checkPattern(pattern) { | ||
return pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) | ||
// > A line starting with # serves as a comment. | ||
return pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) // > A line starting with # serves as a comment. | ||
&& pattern.indexOf('#') !== 0; | ||
@@ -311,5 +245,4 @@ }; | ||
var origin = pattern; | ||
var negative = false; | ||
var negative = false; // > An optional prefix "!" which negates the pattern; | ||
// > An optional prefix "!" which negates the pattern; | ||
if (pattern.indexOf('!') === 0) { | ||
@@ -320,12 +253,8 @@ negative = true; | ||
pattern = pattern | ||
// > Put a backslash ("\") in front of the first "!" for patterns that | ||
pattern = pattern // > Put a backslash ("\") in front of the first "!" for patterns that | ||
// > begin with a literal "!", for example, `"\!important!.txt"`. | ||
.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') | ||
// > Put a backslash ("\") in front of the first hash for patterns that | ||
.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!') // > Put a backslash ("\") in front of the first hash for patterns that | ||
// > begin with a hash. | ||
.replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#'); | ||
var regex = makeRegex(pattern, negative, ignorecase); | ||
return new IgnoreRule(origin, pattern, negative, regex); | ||
@@ -344,14 +273,14 @@ }; | ||
if (!isString(path)) { | ||
return doThrow(`path must be a string, but got \`${path}\``, TypeError); | ||
} | ||
return doThrow("path must be a string, but got `".concat(path, "`"), TypeError); | ||
} // We don't know if we should ignore '', so throw | ||
// We don't know if we should ignore '', so throw | ||
if (!path) { | ||
return doThrow(`path must not be empty`, TypeError); | ||
} | ||
return doThrow("path must not be empty", TypeError); | ||
} // | ||
// | ||
if (REGEX_TEST_INVALID_PATH.test(path)) { | ||
var r = '`path.relative()`d'; | ||
return doThrow(`path should be a ${r} string, but got "${path}"`, RangeError); | ||
return doThrow("path should be a ".concat(r, " string, but got \"").concat(path, "\""), RangeError); | ||
} | ||
@@ -362,7 +291,9 @@ | ||
var Ignore = function () { | ||
var Ignore = | ||
/*#__PURE__*/ | ||
function () { | ||
function Ignore() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$ignorecase = _ref.ignorecase, | ||
ignorecase = _ref$ignorecase === undefined ? true : _ref$ignorecase; | ||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase; | ||
@@ -374,2 +305,3 @@ _classCallCheck(this, Ignore); | ||
define(this, KEY_IGNORE, true); | ||
this._initCache(); | ||
@@ -379,3 +311,3 @@ } | ||
_createClass(Ignore, [{ | ||
key: '_initCache', | ||
key: "_initCache", | ||
value: function _initCache() { | ||
@@ -386,3 +318,3 @@ this._ignoreCache = Object.create(null); | ||
}, { | ||
key: '_addPattern', | ||
key: "_addPattern", | ||
value: function _addPattern(pattern) { | ||
@@ -399,17 +331,14 @@ // #32 | ||
this._added = true; | ||
this._rules.push(rule); | ||
} | ||
} | ||
} // @param {Array<string> | string | Ignore} pattern | ||
// @param {Array<string> | string | Ignore} pattern | ||
}, { | ||
key: 'add', | ||
key: "add", | ||
value: function add(pattern) { | ||
this._added = false; | ||
makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this); // Some rules have just added to the ignore, | ||
// making the behavior changed. | ||
makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._addPattern, this); | ||
// Some rules have just added to the ignore, | ||
// making the behavior changed. | ||
if (this._added) { | ||
@@ -420,13 +349,9 @@ this._initCache(); | ||
return this; | ||
} | ||
} // legacy | ||
// legacy | ||
}, { | ||
key: 'addPattern', | ||
key: "addPattern", | ||
value: function addPattern(pattern) { | ||
return this.add(pattern); | ||
} | ||
// | ignored : unignored | ||
} // | ignored : unignored | ||
// negative | 0:0 | 0:1 | 1:0 | 1:1 | ||
@@ -436,3 +361,2 @@ // -------- | ------- | ------- | ------- | -------- | ||
// 1 | TESTIF | SKIP | TEST | X | ||
// - SKIP: always skip | ||
@@ -442,11 +366,9 @@ // - TEST: always test | ||
// - X: that never happen | ||
// @param {boolean} whether should check if the path is unignored, | ||
// setting `checkUnignored` to `false` could reduce additional | ||
// path matching. | ||
// @returns {TestResult} true if a file is ignored | ||
}, { | ||
key: '_testOne', | ||
key: "_testOne", | ||
value: function _testOne(path, checkUnignored) { | ||
@@ -472,11 +394,9 @@ var ignored = false; | ||
return { | ||
ignored, | ||
unignored | ||
ignored: ignored, | ||
unignored: unignored | ||
}; | ||
} | ||
} // @returns {TestResult} | ||
// @returns {TestResult} | ||
}, { | ||
key: '_test', | ||
key: "_test", | ||
value: function _test(path, cache, checkUnignored, slices) { | ||
@@ -495,5 +415,4 @@ checkPath(path, throwError); | ||
slices.pop(); | ||
slices.pop(); // If the path has no parent directory, just test it | ||
// If the path has no parent directory, just test it | ||
if (!slices.length) { | ||
@@ -503,7 +422,6 @@ return cache[path] = this._testOne(path, checkUnignored); | ||
var parent = this._test(slices.join(SLASH) + SLASH, cache, checkUnignored, slices); | ||
var parent = this._test(slices.join(SLASH) + SLASH, cache, checkUnignored, slices); // If the path contains a parent directory, check the parent first | ||
// If the path contains a parent directory, check the parent first | ||
return cache[path] = parent.ignored | ||
// > It is not possible to re-include a file if a parent directory of | ||
return cache[path] = parent.ignored // > It is not possible to re-include a file if a parent directory of | ||
// > that file is excluded. | ||
@@ -513,3 +431,3 @@ ? parent : this._testOne(path, checkUnignored); | ||
}, { | ||
key: 'ignores', | ||
key: "ignores", | ||
value: function ignores(path) { | ||
@@ -519,3 +437,3 @@ return this._test(path, this._ignoreCache, false).ignored; | ||
}, { | ||
key: 'createFilter', | ||
key: "createFilter", | ||
value: function createFilter() { | ||
@@ -529,11 +447,9 @@ var _this = this; | ||
}, { | ||
key: 'filter', | ||
key: "filter", | ||
value: function filter(paths) { | ||
return makeArray(paths).filter(this.createFilter()); | ||
} | ||
} // @returns {TestResult} | ||
// @returns {TestResult} | ||
}, { | ||
key: 'test', | ||
key: "test", | ||
value: function test(path) { | ||
@@ -555,21 +471,17 @@ return this._test(path, this._testCache, true); | ||
factory.isPathValid = isPathValid; | ||
factory.isPathValid = isPathValid; // Fixes typescript | ||
// Fixes typescript | ||
factory.default = factory; | ||
module.exports = factory; // Windows | ||
// -------------------------------------------------------------- | ||
module.exports = factory; | ||
/* istanbul ignore if */ | ||
// Windows | ||
// -------------------------------------------------------------- | ||
/* istanbul ignore if */ | ||
if ( | ||
// Detect `process` so that it can run in browsers. | ||
if ( // Detect `process` so that it can run in browsers. | ||
typeof process !== 'undefined' && (process.env && process.env.IGNORE_TEST_WIN32 || process.platform === 'win32')) { | ||
var test = Ignore.prototype._test; | ||
/* eslint no-control-regex: "off" */ | ||
/* eslint no-control-regex: "off" */ | ||
var makePosix = function makePosix(str) { | ||
return (/^\\\\\?\\/.test(str) || /[\0-\x1F"<>\|]+/.test(str) ? str : str.replace(/\\/g, '/') | ||
); | ||
return /^\\\\\?\\/.test(str) || /[\0-\x1F"<>\|]+/.test(str) ? str : str.replace(/\\/g, '/'); | ||
}; | ||
@@ -580,3 +492,3 @@ | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -583,0 +495,0 @@ } |
{ | ||
"name": "ignore", | ||
"version": "5.0.5", | ||
"version": "5.0.6", | ||
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.", | ||
@@ -12,3 +12,3 @@ "files": [ | ||
"scripts": { | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"build": "babel -o legacy.js index.js", | ||
@@ -51,16 +51,17 @@ "test:lint": "eslint .", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"codecov": "^3.1.0", | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.4", | ||
"@babel/preset-env": "^7.3.4", | ||
"codecov": "^3.2.0", | ||
"debug": "^4.1.1", | ||
"eslint": "^5.12.0", | ||
"eslint-config-ostai": "^1.4.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint": "^5.15.2", | ||
"eslint-config-ostai": "^2.0.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"mkdirp": "^0.5.1", | ||
"pre-suf": "^1.1.0", | ||
"pre-suf": "^1.1.1", | ||
"rimraf": "^2.6.3", | ||
"spawn-sync": "^2.0.0", | ||
"tap": "^12.1.1", | ||
"tap": "^12.6.0", | ||
"tmp": "0.0.33", | ||
"typescript": "^3.2.2" | ||
"typescript": "^3.3.3333" | ||
}, | ||
@@ -67,0 +68,0 @@ "engines": { |
45467
15
927