1
1
import { isNegatedGlob } from './utilities'
2
- import micromatch from 'micromatch '
2
+ import picomatch from 'picomatch '
3
3
4
- // ! Don't use platform specific path separators in the glob patterns for globby/micromatch
4
+ // ! Don't use platform specific path separators in the glob patterns for globby/picomatch
5
5
// as it only works with forward slashes!
6
6
7
7
interface ApplyGlobsOptions {
@@ -14,28 +14,27 @@ export function createFilterAccordingToGlobs({ inclusions, exclusions }: ApplyGl
14
14
const thereAreExclusions = Array . isArray ( exclusions )
15
15
const inclusionsEmpty = thereAreInclusions && inclusions . length === 0
16
16
17
- function filterAccordingToGlobs ( path : string ) {
18
- const matchesInclusionPatterns =
19
- ! thereAreInclusions || inclusions . some ( ( pattern ) => micromatch . isMatch ( path , pattern ) )
20
- let isIgnored = false
17
+ const isIncluded = thereAreInclusions ? picomatch ( inclusions ) : ( ) => true
18
+
19
+ const positiveExclusionPatterns =
20
+ ( thereAreExclusions && exclusions . filter ( ( pattern ) => ! isNegatedGlob ( pattern ) ) ) || [ ]
21
+ const negativeExclusionPatterns =
22
+ ( thereAreExclusions && exclusions . filter ( ( pattern ) => isNegatedGlob ( pattern ) ) . map ( ( pattern ) => pattern . slice ( 1 ) ) ) ||
23
+ [ ]
24
+
25
+ const isPositivelyExcluded = picomatch ( positiveExclusionPatterns )
26
+ const isReIncluded = picomatch ( negativeExclusionPatterns )
21
27
28
+ function filterAccordingToGlobs ( path : string ) {
22
29
if ( inclusionsEmpty ) {
23
30
return false
24
31
}
25
32
33
+ const matchesInclusionPatterns = isIncluded ( path )
34
+ let isIgnored = false
35
+
26
36
if ( matchesInclusionPatterns && thereAreExclusions ) {
27
- isIgnored = exclusions
28
- . filter ( ( pattern ) => ! isNegatedGlob ( pattern ) )
29
- . some ( ( pattern ) => micromatch . isMatch ( path , pattern ) )
30
-
31
- // If the path is ignored, check for any negated patterns that would include it back
32
- if ( isIgnored ) {
33
- const isNegated = exclusions . some (
34
- ( ignorePattern ) => isNegatedGlob ( ignorePattern ) && micromatch . isMatch ( path , ignorePattern . slice ( 1 ) ) ,
35
- )
36
-
37
- isIgnored = ! isNegated
38
- }
37
+ isIgnored = isPositivelyExcluded ( path ) && ! isReIncluded ( path )
39
38
}
40
39
41
40
return matchesInclusionPatterns && ! isIgnored
0 commit comments