forked from daren.hsu/line_push
update
This commit is contained in:
+26
-6
@@ -298,7 +298,19 @@ interface TestResult {
|
||||
- `{ignored: false, unignored: true}`: the `pathname` is unignored
|
||||
- `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.
|
||||
|
||||
## `options.ignorecase` since 4.0.0
|
||||
## static `ignore.isPathValid(pathname): boolean` since 5.0.0
|
||||
|
||||
Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname).
|
||||
|
||||
This method is **NOT** used to check if an ignore pattern is valid.
|
||||
|
||||
```js
|
||||
ignore.isPathValid('./foo') // false
|
||||
```
|
||||
|
||||
## ignore(options)
|
||||
|
||||
### `options.ignorecase` since 4.0.0
|
||||
|
||||
Similar as the `core.ignorecase` option of [git-config](https://git-scm.com/docs/git-config), `node-ignore` will be case insensitive if `options.ignorecase` is set to `true` (the default value), otherwise case sensitive.
|
||||
|
||||
@@ -312,14 +324,20 @@ ig.add('*.png')
|
||||
ig.ignores('*.PNG') // false
|
||||
```
|
||||
|
||||
## static `ignore.isPathValid(pathname): boolean` since 5.0.0
|
||||
### `options.ignoreCase?: boolean` since 5.2.0
|
||||
|
||||
Check whether the `pathname` is an valid `path.relative()`d path according to the [convention](#1-pathname-should-be-a-pathrelatived-pathname).
|
||||
Which is alternative to `options.ignoreCase`
|
||||
|
||||
This method is **NOT** used to check if an ignore pattern is valid.
|
||||
### `options.allowRelativePaths?: boolean` since 5.2.0
|
||||
|
||||
This option brings backward compatibility with projects which based on `ignore@4.x`. If `options.allowRelativePaths` is `true`, `ignore` will not check whether the given path to be tested is [`path.relative()`d](#pathname-conventions).
|
||||
|
||||
However, passing a relative path, such as `'./foo'` or `'../foo'`, to test if it is ignored or not is not a good practise, which might lead to unexpected behavior
|
||||
|
||||
```js
|
||||
ignore.isPathValid('./foo') // false
|
||||
ignore({
|
||||
allowRelativePaths: true
|
||||
}).ignores('../foo/bar.js') // And it will not throw
|
||||
```
|
||||
|
||||
****
|
||||
@@ -328,7 +346,9 @@ ignore.isPathValid('./foo') // false
|
||||
|
||||
## Upgrade 4.x -> 5.x
|
||||
|
||||
Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, while `ignore < 5.0.0` did not make sure what the return value was, as well as
|
||||
Since `5.0.0`, if an invalid `Pathname` passed into `ig.ignores()`, an error will be thrown, unless `options.allowRelative = true` is passed to the `Ignore` factory.
|
||||
|
||||
While `ignore < 5.0.0` did not make sure what the return value was, as well as
|
||||
|
||||
```ts
|
||||
.ignores(pathname: Pathname): boolean
|
||||
|
||||
+7
-9
@@ -7,17 +7,11 @@ interface TestResult {
|
||||
|
||||
export interface Ignore {
|
||||
/**
|
||||
* Adds a rule rules to the current manager.
|
||||
* @param {string | Ignore} pattern
|
||||
* @returns IgnoreBase
|
||||
*/
|
||||
add(pattern: string | Ignore): this
|
||||
/**
|
||||
* Adds several rules to the current manager.
|
||||
* Adds one or several rules to the current manager.
|
||||
* @param {string[]} patterns
|
||||
* @returns IgnoreBase
|
||||
*/
|
||||
add(patterns: (string | Ignore)[]): this
|
||||
add(patterns: string | Ignore | readonly (string | Ignore)[]): this
|
||||
|
||||
/**
|
||||
* Filters the given array of pathnames, and returns the filtered array.
|
||||
@@ -25,7 +19,8 @@ export interface Ignore {
|
||||
* @param paths the array of paths to be filtered.
|
||||
* @returns The filtered array of paths
|
||||
*/
|
||||
filter(pathnames: Pathname[]): Pathname[]
|
||||
filter(pathnames: readonly Pathname[]): Pathname[]
|
||||
|
||||
/**
|
||||
* Creates a filter function which could filter
|
||||
* an array of paths with Array.prototype.filter.
|
||||
@@ -49,6 +44,9 @@ export interface Ignore {
|
||||
|
||||
interface Options {
|
||||
ignorecase?: boolean
|
||||
// For compatibility
|
||||
ignoreCase?: boolean
|
||||
allowRelativePaths?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+30
-24
@@ -30,6 +30,8 @@ const define = (object, key, value) =>
|
||||
|
||||
const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g
|
||||
|
||||
const RETURN_FALSE = () => false
|
||||
|
||||
// Sanitize the range of a regular expression
|
||||
// The cases are complicated, see test cases for details
|
||||
const sanitizeRange = range => range.replace(
|
||||
@@ -288,22 +290,18 @@ const REPLACERS = [
|
||||
const regexCache = Object.create(null)
|
||||
|
||||
// @param {pattern}
|
||||
const makeRegex = (pattern, negative, ignorecase) => {
|
||||
const r = regexCache[pattern]
|
||||
if (r) {
|
||||
return r
|
||||
const makeRegex = (pattern, ignoreCase) => {
|
||||
let source = regexCache[pattern]
|
||||
|
||||
if (!source) {
|
||||
source = REPLACERS.reduce(
|
||||
(prev, current) => prev.replace(current[0], current[1].bind(pattern)),
|
||||
pattern
|
||||
)
|
||||
regexCache[pattern] = source
|
||||
}
|
||||
|
||||
// const replacers = negative
|
||||
// ? NEGATIVE_REPLACERS
|
||||
// : POSITIVE_REPLACERS
|
||||
|
||||
const source = REPLACERS.reduce(
|
||||
(prev, current) => prev.replace(current[0], current[1].bind(pattern)),
|
||||
pattern
|
||||
)
|
||||
|
||||
return regexCache[pattern] = ignorecase
|
||||
return ignoreCase
|
||||
? new RegExp(source, 'i')
|
||||
: new RegExp(source)
|
||||
}
|
||||
@@ -334,7 +332,7 @@ class IgnoreRule {
|
||||
}
|
||||
}
|
||||
|
||||
const createRule = (pattern, ignorecase) => {
|
||||
const createRule = (pattern, ignoreCase) => {
|
||||
const origin = pattern
|
||||
let negative = false
|
||||
|
||||
@@ -352,7 +350,7 @@ const createRule = (pattern, ignorecase) => {
|
||||
// > begin with a hash.
|
||||
.replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#')
|
||||
|
||||
const regex = makeRegex(pattern, negative, ignorecase)
|
||||
const regex = makeRegex(pattern, ignoreCase)
|
||||
|
||||
return new IgnoreRule(
|
||||
origin,
|
||||
@@ -398,11 +396,15 @@ checkPath.convert = p => p
|
||||
|
||||
class Ignore {
|
||||
constructor ({
|
||||
ignorecase = true
|
||||
ignorecase = true,
|
||||
ignoreCase = ignorecase,
|
||||
allowRelativePaths = false
|
||||
} = {}) {
|
||||
this._rules = []
|
||||
this._ignorecase = ignorecase
|
||||
define(this, KEY_IGNORE, true)
|
||||
|
||||
this._rules = []
|
||||
this._ignoreCase = ignoreCase
|
||||
this._allowRelativePaths = allowRelativePaths
|
||||
this._initCache()
|
||||
}
|
||||
|
||||
@@ -420,7 +422,7 @@ class Ignore {
|
||||
}
|
||||
|
||||
if (checkPattern(pattern)) {
|
||||
const rule = createRule(pattern, this._ignorecase)
|
||||
const rule = createRule(pattern, this._ignoreCase)
|
||||
this._added = true
|
||||
this._rules.push(rule)
|
||||
}
|
||||
@@ -499,7 +501,13 @@ class Ignore {
|
||||
// Supports nullable path
|
||||
&& checkPath.convert(originalPath)
|
||||
|
||||
checkPath(path, originalPath, throwError)
|
||||
checkPath(
|
||||
path,
|
||||
originalPath,
|
||||
this._allowRelativePaths
|
||||
? RETURN_FALSE
|
||||
: throwError
|
||||
)
|
||||
|
||||
return this._t(path, cache, checkUnignored, slices)
|
||||
}
|
||||
@@ -557,10 +565,8 @@ class Ignore {
|
||||
|
||||
const factory = options => new Ignore(options)
|
||||
|
||||
const returnFalse = () => false
|
||||
|
||||
const isPathValid = path =>
|
||||
checkPath(path && checkPath.convert(path), path, returnFalse)
|
||||
checkPath(path && checkPath.convert(path), path, RETURN_FALSE)
|
||||
|
||||
factory.isPathValid = isPathValid
|
||||
|
||||
|
||||
+28
-25
@@ -35,9 +35,14 @@ var define = function define(object, key, value) {
|
||||
});
|
||||
};
|
||||
|
||||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g; // Sanitize the range of a regular expression
|
||||
var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
|
||||
|
||||
var RETURN_FALSE = function RETURN_FALSE() {
|
||||
return false;
|
||||
}; // 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
|
||||
@@ -205,20 +210,17 @@ function (match) {
|
||||
|
||||
var regexCache = Object.create(null); // @param {pattern}
|
||||
|
||||
var makeRegex = function makeRegex(pattern, negative, ignorecase) {
|
||||
var r = regexCache[pattern];
|
||||
var makeRegex = function makeRegex(pattern, ignoreCase) {
|
||||
var source = regexCache[pattern];
|
||||
|
||||
if (r) {
|
||||
return r;
|
||||
} // const replacers = negative
|
||||
// ? NEGATIVE_REPLACERS
|
||||
// : POSITIVE_REPLACERS
|
||||
if (!source) {
|
||||
source = REPLACERS.reduce(function (prev, current) {
|
||||
return prev.replace(current[0], current[1].bind(pattern));
|
||||
}, pattern);
|
||||
regexCache[pattern] = source;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
return ignoreCase ? new RegExp(source, 'i') : new RegExp(source);
|
||||
};
|
||||
|
||||
var isString = function isString(subject) {
|
||||
@@ -244,7 +246,7 @@ var IgnoreRule = function IgnoreRule(origin, pattern, negative, regex) {
|
||||
this.regex = regex;
|
||||
};
|
||||
|
||||
var createRule = function createRule(pattern, ignorecase) {
|
||||
var createRule = function createRule(pattern, ignoreCase) {
|
||||
var origin = pattern;
|
||||
var negative = false; // > An optional prefix "!" which negates the pattern;
|
||||
|
||||
@@ -258,7 +260,7 @@ var createRule = function createRule(pattern, ignorecase) {
|
||||
.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);
|
||||
var regex = makeRegex(pattern, ignoreCase);
|
||||
return new IgnoreRule(origin, pattern, negative, regex);
|
||||
};
|
||||
|
||||
@@ -299,13 +301,18 @@ var Ignore = /*#__PURE__*/function () {
|
||||
function Ignore() {
|
||||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
||||
_ref$ignorecase = _ref.ignorecase,
|
||||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase;
|
||||
ignorecase = _ref$ignorecase === void 0 ? true : _ref$ignorecase,
|
||||
_ref$ignoreCase = _ref.ignoreCase,
|
||||
ignoreCase = _ref$ignoreCase === void 0 ? ignorecase : _ref$ignoreCase,
|
||||
_ref$allowRelativePat = _ref.allowRelativePaths,
|
||||
allowRelativePaths = _ref$allowRelativePat === void 0 ? false : _ref$allowRelativePat;
|
||||
|
||||
_classCallCheck(this, Ignore);
|
||||
|
||||
this._rules = [];
|
||||
this._ignorecase = ignorecase;
|
||||
define(this, KEY_IGNORE, true);
|
||||
this._rules = [];
|
||||
this._ignoreCase = ignoreCase;
|
||||
this._allowRelativePaths = allowRelativePaths;
|
||||
|
||||
this._initCache();
|
||||
}
|
||||
@@ -327,7 +334,7 @@ var Ignore = /*#__PURE__*/function () {
|
||||
}
|
||||
|
||||
if (checkPattern(pattern)) {
|
||||
var rule = createRule(pattern, this._ignorecase);
|
||||
var rule = createRule(pattern, this._ignoreCase);
|
||||
this._added = true;
|
||||
|
||||
this._rules.push(rule);
|
||||
@@ -398,7 +405,7 @@ var Ignore = /*#__PURE__*/function () {
|
||||
value: function _test(originalPath, cache, checkUnignored, slices) {
|
||||
var path = originalPath // Supports nullable path
|
||||
&& checkPath.convert(originalPath);
|
||||
checkPath(path, originalPath, throwError);
|
||||
checkPath(path, originalPath, this._allowRelativePaths ? RETURN_FALSE : throwError);
|
||||
return this._t(path, cache, checkUnignored, slices);
|
||||
}
|
||||
}, {
|
||||
@@ -461,12 +468,8 @@ var factory = function factory(options) {
|
||||
return new Ignore(options);
|
||||
};
|
||||
|
||||
var returnFalse = function returnFalse() {
|
||||
return false;
|
||||
};
|
||||
|
||||
var isPathValid = function isPathValid(path) {
|
||||
return checkPath(path && checkPath.convert(path), path, returnFalse);
|
||||
return checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
||||
};
|
||||
|
||||
factory.isPathValid = isPathValid; // Fixes typescript
|
||||
|
||||
+17
-16
@@ -1,34 +1,34 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"ignore@5.1.8",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"ignore@5.2.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "ignore@5.1.8",
|
||||
"_id": "ignore@5.1.8",
|
||||
"_from": "ignore@5.2.0",
|
||||
"_id": "ignore@5.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==",
|
||||
"_integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==",
|
||||
"_location": "/ignore",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "ignore@5.1.8",
|
||||
"raw": "ignore@5.2.0",
|
||||
"name": "ignore",
|
||||
"escapedName": "ignore",
|
||||
"rawSpec": "5.1.8",
|
||||
"rawSpec": "5.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "5.1.8"
|
||||
"fetchSpec": "5.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@nuxt/builder",
|
||||
"/eslint-plugin-node",
|
||||
"/globby"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz",
|
||||
"_spec": "5.1.8",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz",
|
||||
"_spec": "5.2.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "kael"
|
||||
},
|
||||
@@ -88,16 +88,17 @@
|
||||
"build": "babel -o legacy.js index.js",
|
||||
"posttest": "tap --coverage-report=html && codecov",
|
||||
"prepublishOnly": "npm run build",
|
||||
"tap": "tap --reporter classic",
|
||||
"test": "npm run test:only",
|
||||
"test:cases": "tap test/*.js --coverage",
|
||||
"test:git": "tap test/git-check-ignore.js",
|
||||
"test:ignore": "tap test/ignore.js",
|
||||
"test:cases": "npm run tap test/*.js -- --coverage",
|
||||
"test:git": "npm run tap test/git-check-ignore.js",
|
||||
"test:ignore": "npm run tap test/ignore.js",
|
||||
"test:lint": "eslint .",
|
||||
"test:only": "npm run test:lint && npm run test:tsc && npm run test:ts && npm run test:cases",
|
||||
"test:others": "tap test/others.js",
|
||||
"test:others": "npm run tap test/others.js",
|
||||
"test:ts": "node ./test/ts/simple.js",
|
||||
"test:tsc": "tsc ./test/ts/simple.ts --lib ES6",
|
||||
"test:win32": "IGNORE_TEST_WIN32=1 npm run test"
|
||||
},
|
||||
"version": "5.1.8"
|
||||
"version": "5.2.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user