Skip to content

Commit dba2c54

Browse files
committed
chore: replace micromatch with picomatch
1 parent fdaa41b commit dba2c54

File tree

3 files changed

+39
-47
lines changed

3 files changed

+39
-47
lines changed

packages/steiger/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
"globby": "^14.0.2",
5151
"immer": "^10.1.1",
5252
"lodash-es": "^4.17.21",
53-
"micromatch": "^4.0.8",
5453
"patronum": "^2.3.0",
5554
"picocolors": "^1.1.1",
55+
"picomatch": "^4.0.3",
5656
"prexit": "^2.3.0",
5757
"yargs": "^17.7.2",
5858
"zod": "^3.24.1",
@@ -66,7 +66,7 @@
6666
"@steiger/types": "workspace:*",
6767
"@total-typescript/ts-reset": "^0.6.1",
6868
"@types/lodash-es": "^4.17.12",
69-
"@types/micromatch": "^4.0.9",
69+
"@types/picomatch": "^4.0.1",
7070
"@types/yargs": "^17.0.33",
7171
"memfs": "^4.17.0",
7272
"tsup": "^8.3.5",

packages/steiger/src/shared/globs/create-filter-according-to-globs.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isNegatedGlob } from './utilities'
2-
import micromatch from 'micromatch'
2+
import picomatch from 'picomatch'
33

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
55
// as it only works with forward slashes!
66

77
interface ApplyGlobsOptions {
@@ -14,28 +14,27 @@ export function createFilterAccordingToGlobs({ inclusions, exclusions }: ApplyGl
1414
const thereAreExclusions = Array.isArray(exclusions)
1515
const inclusionsEmpty = thereAreInclusions && inclusions.length === 0
1616

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)
2127

28+
function filterAccordingToGlobs(path: string) {
2229
if (inclusionsEmpty) {
2330
return false
2431
}
2532

33+
const matchesInclusionPatterns = isIncluded(path)
34+
let isIgnored = false
35+
2636
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)
3938
}
4039

4140
return matchesInclusionPatterns && !isIgnored

pnpm-lock.yaml

Lines changed: 20 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)