Visitar URL original
stop using `picomatch.makeRe` on partial matcher · SuperchupuDev/tinyglobby@63333fa · GitHub
Skip to content

Commit 63333fa

Browse files
committed
stop using picomatch.makeRe on partial matcher
for some reason `makeRe` makes some patterns not work, like `+++` (???) no idea why best to just use a classic matcher like always i really hope this doesnt harm performance closes #162
1 parent 8590700 commit 63333fa

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎src/utils.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { posix } from 'node:path';
2-
import picomatch from 'picomatch';
2+
import picomatch, { type Matcher } from 'picomatch';
33

44
// The `Array.isArray` type guard doesn't work for readonly arrays.
55
export const isReadonlyArray: (arg: unknown) => arg is readonly unknown[] = Array.isArray;
@@ -28,17 +28,17 @@ export function getPartialMatcher(patterns: string[], options: PartialMatcherOpt
2828
// you might find this code pattern odd, but apparently it's faster than using `.push()`
2929
const patternsCount = patterns.length;
3030
const patternsParts: string[][] = Array(patternsCount);
31-
const regexes: RegExp[][] = Array(patternsCount);
31+
const matchers: Matcher[][] = Array(patternsCount);
3232
const globstarEnabled = !options.noglobstar;
3333
for (let i = 0; i < patternsCount; i++) {
3434
const parts = splitPattern(patterns[i]);
3535
patternsParts[i] = parts;
3636
const partsCount = parts.length;
37-
const partRegexes = Array(partsCount);
37+
const partMatchers: Matcher[] = Array(partsCount);
3838
for (let j = 0; j < partsCount; j++) {
39-
partRegexes[j] = picomatch.makeRe(parts[j], options);
39+
partMatchers[j] = picomatch(parts[j], options);
4040
}
41-
regexes[i] = partRegexes;
41+
matchers[i] = partMatchers;
4242
}
4343
return (input: string) => {
4444
// no need to `splitPattern` as this is indeed not a pattern
@@ -52,7 +52,7 @@ export function getPartialMatcher(patterns: string[], options: PartialMatcherOpt
5252
}
5353
for (let i = 0; i < patterns.length; i++) {
5454
const patternParts = patternsParts[i];
55-
const regex = regexes[i];
55+
const matcher = matchers[i];
5656
const inputPatternCount = inputParts.length;
5757
const minParts = Math.min(inputPatternCount, patternParts.length);
5858
let j = 0;
@@ -66,7 +66,7 @@ export function getPartialMatcher(patterns: string[], options: PartialMatcherOpt
6666
return true;
6767
}
6868

69-
const match = regex[j].test(inputParts[j]);
69+
const match = matcher[j](inputParts[j]);
7070

7171
if (!match) {
7272
break;

‎test/utils/partial-matcher.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ describe('getPartialMatcher', () => {
116116
assert.ok(!matcher('test/utilg/a/c'));
117117
});
118118

119+
test('patterns that break picomatch.makeRe', () => {
120+
const matcher = getPartialMatcher(['+++']);
121+
assert.ok(matcher('+++'));
122+
});
123+
119124
test('..', () => {
120125
const matcher = getPartialMatcher(['../test/util?/a']);
121126
assert.ok(matcher('..'));

0 commit comments

Comments
 (0)