1*1aeb130dSKudo Chienimport minimatch from 'minimatch'; 2*1aeb130dSKudo Chien 3*1aeb130dSKudo Chien/** 4*1aeb130dSKudo Chien * Indicate the given `filePath` should be excluded by `ignorePaths` 5*1aeb130dSKudo Chien */ 6*1aeb130dSKudo Chienexport function isIgnoredPath( 7*1aeb130dSKudo Chien filePath: string, 8*1aeb130dSKudo Chien ignorePaths: string[], 9*1aeb130dSKudo Chien minimatchOptions: minimatch.IOptions = { dot: true } 10*1aeb130dSKudo Chien): boolean { 11*1aeb130dSKudo Chien const minimatchObjs = ignorePaths.map( 12*1aeb130dSKudo Chien (ignorePath) => new minimatch.Minimatch(ignorePath, minimatchOptions) 13*1aeb130dSKudo Chien ); 14*1aeb130dSKudo Chien 15*1aeb130dSKudo Chien let result = false; 16*1aeb130dSKudo Chien for (const minimatchObj of minimatchObjs) { 17*1aeb130dSKudo Chien const currMatch = minimatchObj.match(filePath); 18*1aeb130dSKudo Chien if (minimatchObj.negate && result && !currMatch) { 19*1aeb130dSKudo Chien // Special handler for negate (!pattern). 20*1aeb130dSKudo Chien // As long as previous match result is true and not matched from the current negate pattern, we should early return. 21*1aeb130dSKudo Chien return false; 22*1aeb130dSKudo Chien } 23*1aeb130dSKudo Chien result ||= currMatch; 24*1aeb130dSKudo Chien } 25*1aeb130dSKudo Chien return result; 26*1aeb130dSKudo Chien} 27