UNPKG

701 BPlain TextView Raw
1import path from 'path';
2
3import minimatch from 'minimatch';
4import { normalizeFileName } from '@stryker-mutator/util';
5
6/**
7 * A helper class for matching files using the `disableTypeChecks` setting.
8 */
9export class FileMatcher {
10 private readonly pattern: boolean | string;
11
12 constructor(pattern: boolean | string) {
13 if (typeof pattern === 'string') {
14 this.pattern = normalizeFileName(path.resolve(pattern));
15 } else {
16 this.pattern = pattern;
17 }
18 }
19
20 public matches(fileName: string): boolean {
21 if (typeof this.pattern === 'string') {
22 return minimatch(normalizeFileName(path.resolve(fileName)), this.pattern);
23 } else {
24 return this.pattern;
25 }
26 }
27}