-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Match properly when using / in include/exclude (#5)
- Loading branch information
1 parent
68ba692
commit 861e9d6
Showing
4 changed files
with
44 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
import { isMatch } from 'micromatch'; | ||
import { isMatch } from 'picomatch'; | ||
|
||
// This fix is needed for picomatch library | ||
// Otherwise there will be error when matching log groups for example | ||
function fixMatchString(str: string): string { | ||
return str.replace(/\//g, '-'); | ||
} | ||
|
||
function matchIncluded(str: string, included: string[]): boolean { | ||
return included.length === 0 || isMatch(str, included); | ||
} | ||
|
||
function matchExcluded(str: string, excluded: string[]): boolean { | ||
return excluded.length === 0 || !isMatch(str, excluded); | ||
} | ||
|
||
export default function match(str: string, include: string[], exclude: string[]): boolean { | ||
const matchStr = str.replace(/\//g, '-'); | ||
return (include.length === 0 || isMatch(matchStr, include)) && (exclude.length === 0 || !isMatch(matchStr, exclude)); | ||
const matchStr = fixMatchString(str); | ||
const included = include.map(str => fixMatchString(str)); | ||
const excluded = exclude.map(str => fixMatchString(str)); | ||
|
||
return matchIncluded(matchStr, included) && matchExcluded(matchStr, excluded); | ||
} |