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