Ignore files if they don't match only OR they do match ignore.

This commit is contained in:
Logan Smyth 2017-03-13 16:24:06 -07:00
parent 738bd54bfb
commit dcb0f91f38

View File

@ -126,20 +126,22 @@ export function booleanify(val: any): boolean | any {
export function shouldIgnore(
filename: string,
ignore: Array<RegExp | Function> = [],
ignore: Array<RegExp | Function>,
only?: Array<RegExp | Function>,
): boolean {
filename = filename.replace(/\\/g, "/");
if (ignore && ignore.length) {
for (const pattern of ignore) {
if (matchesPattern(pattern, filename)) return true;
}
}
if (only) {
for (const pattern of only) {
if (_shouldIgnore(pattern, filename)) return false;
if (matchesPattern(pattern, filename)) return false;
}
return true;
} else if (ignore.length) {
for (const pattern of ignore) {
if (_shouldIgnore(pattern, filename)) return true;
}
}
return false;
@ -150,7 +152,7 @@ export function shouldIgnore(
* Otherwise returns result of matching pattern Regex with filename.
*/
function _shouldIgnore(pattern: Function | RegExp, filename: string) {
function matchesPattern(pattern: Function | RegExp, filename: string) {
if (typeof pattern === "function") {
return pattern(filename);
} else {