Ignore files if they don't match only OR they do match ignore.
This commit is contained in:
parent
738bd54bfb
commit
dcb0f91f38
@ -126,20 +126,22 @@ export function booleanify(val: any): boolean | any {
|
|||||||
|
|
||||||
export function shouldIgnore(
|
export function shouldIgnore(
|
||||||
filename: string,
|
filename: string,
|
||||||
ignore: Array<RegExp | Function> = [],
|
ignore: Array<RegExp | Function>,
|
||||||
only?: Array<RegExp | Function>,
|
only?: Array<RegExp | Function>,
|
||||||
): boolean {
|
): boolean {
|
||||||
filename = filename.replace(/\\/g, "/");
|
filename = filename.replace(/\\/g, "/");
|
||||||
|
|
||||||
|
if (ignore && ignore.length) {
|
||||||
|
for (const pattern of ignore) {
|
||||||
|
if (matchesPattern(pattern, filename)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (only) {
|
if (only) {
|
||||||
for (const pattern of only) {
|
for (const pattern of only) {
|
||||||
if (_shouldIgnore(pattern, filename)) return false;
|
if (matchesPattern(pattern, filename)) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (ignore.length) {
|
|
||||||
for (const pattern of ignore) {
|
|
||||||
if (_shouldIgnore(pattern, filename)) return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -150,7 +152,7 @@ export function shouldIgnore(
|
|||||||
* Otherwise returns result of matching pattern Regex with filename.
|
* 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") {
|
if (typeof pattern === "function") {
|
||||||
return pattern(filename);
|
return pattern(filename);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user