make path patterns used by only and ignore **very** liberal, this will ease a lot of pain in dealing with them
This commit is contained in:
parent
4d4493f325
commit
5ae3dc01f1
@ -13,6 +13,11 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.4.2
|
||||
|
||||
* **Polish**
|
||||
* `ignore` and `only` patterns are now **very** liberal. The pattern can now exist anywhere in the path.
|
||||
|
||||
## 5.4.1
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import "./patch";
|
||||
|
||||
import escapeRegExp from "lodash/string/escapeRegExp";
|
||||
|
||||
import startsWith from "lodash/string/startsWith";
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import * as messages from "./messages";
|
||||
@ -69,9 +69,22 @@ export function list(val: string): Array<string> {
|
||||
|
||||
export function regexify(val: any): RegExp {
|
||||
if (!val) return new RegExp(/.^/);
|
||||
|
||||
if (Array.isArray(val)) val = new RegExp(val.map(escapeRegExp).join("|"), "i");
|
||||
if (isString(val)) return minimatch.makeRe(val, { nocase: true });
|
||||
|
||||
if (isString(val)) {
|
||||
// normalise path separators
|
||||
val = slash(val);
|
||||
|
||||
// remove relative separator if present
|
||||
if (startsWith(val, "./")) val = val.slice(2);
|
||||
|
||||
var regex = minimatch.makeRe(val, { nocase: true });
|
||||
return new RegExp(regex.source.slice(1, -1), "i");
|
||||
}
|
||||
|
||||
if (isRegExp(val)) return val;
|
||||
|
||||
throw new TypeError("illegal type for regexify");
|
||||
}
|
||||
|
||||
@ -95,40 +108,16 @@ export function booleanify(val: any): boolean {
|
||||
}
|
||||
|
||||
export function shouldIgnore(filename, ignore, only) {
|
||||
if (!ignore.length && !only.length) return false;
|
||||
|
||||
filename = slash(filename);
|
||||
|
||||
var filenames = [];
|
||||
|
||||
// try and match each section of the path
|
||||
var parts = filename.split("/");
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (!part) continue;
|
||||
|
||||
filenames.push(part);
|
||||
filenames.push(parts.slice(0, i + 1).join("/"));
|
||||
}
|
||||
|
||||
if (only.length) {
|
||||
var matches = false;
|
||||
|
||||
for (let filename of (filenames: Array)) {
|
||||
for (var pattern of (only: Array)) {
|
||||
if (pattern.test(filename)) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (var pattern of (only: Array)) {
|
||||
if (pattern.test(filename)) return false;
|
||||
}
|
||||
|
||||
return !matches;
|
||||
return true;
|
||||
} else if (ignore.length) {
|
||||
for (let filename of (filenames: Array)) {
|
||||
for (var pattern of (ignore: Array)) {
|
||||
if (pattern.test(filename)) return true;
|
||||
}
|
||||
for (var pattern of (ignore: Array)) {
|
||||
if (pattern.test(filename)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,9 +80,16 @@ suite("util", function () {
|
||||
assert.deepEqual(util.regexify(null), /.^/);
|
||||
assert.deepEqual(util.regexify(""), /.^/);
|
||||
assert.deepEqual(util.regexify(["foo", "bar"]), /foo|bar/i);
|
||||
assert.deepEqual(util.regexify("foobar"), /^(?:(?=.)foobar)$/i);
|
||||
assert.deepEqual(util.regexify("foobar"), /(?:(?=.)foobar)/i);
|
||||
assert.deepEqual(util.regexify(/foobar/), /foobar/);
|
||||
|
||||
assert.ok(util.regexify("foo/bar").test("bar/foo/bar"));
|
||||
assert.ok(util.regexify("foo/*").test("foo/bar.js"));
|
||||
assert.ok(util.regexify("*.js").test("bar.js"));
|
||||
assert.ok(util.regexify("./foo").test("foo"));
|
||||
assert.ok(util.regexify("./foo/bar.js").test("foo/bar.js"));
|
||||
assert.ok(util.regexify("foobar").test("foobar"));
|
||||
|
||||
assert.throws(function () {
|
||||
util.regexify({});
|
||||
}, /illegal type for regexify/);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user