Skip to content

Commit 68133f8

Browse files
committed
fix: the baseNameMatch option now work
1 parent f4c443a commit 68133f8

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ Enable a [case-sensitive](https://en.wikipedia.org/wiki/Case_sensitivity) mode f
290290

291291
Allow glob patterns without slashes to match a file path based on its basename. For example, `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
292292

293+
> :book: This option has no affect to negative patterns from any source (patterns, `ignore`).
294+
293295
#### suppressErrors
294296

295297
* Type: `boolean`

src/providers/filters/deep.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ describe('Providers → Filters → Deep', () => {
108108
assert.ok(!actual);
109109
});
110110

111+
it('should return `treu` when the positive pattern has no affect to depth reading, but the `baseNameMatch` is enabled', () => {
112+
const filter = getFilter('.', ['*'], [], { baseNameMatch: true });
113+
const entry = tests.entry.builder().path('root/directory').directory().build();
114+
115+
const actual = filter(entry);
116+
117+
assert.ok(actual);
118+
});
119+
111120
it('should return `true` when the negative pattern has no effect to depth reading', () => {
112121
const filter = getFilter('.', ['**/*'], ['**/*']);
113122
const entry = tests.entry.builder().path('root/directory').directory().build();

src/providers/filters/deep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class DeepFilter {
6060
}
6161

6262
private _isSkippedByMaxPatternDepth(entryDepth: number, maxPatternDepth: number): boolean {
63-
return maxPatternDepth !== Infinity && entryDepth > maxPatternDepth;
63+
return !this._settings.baseNameMatch && maxPatternDepth !== Infinity && entryDepth > maxPatternDepth;
6464
}
6565

6666
private _isSkippedSymbolicLink(entry: Entry): boolean {

src/providers/filters/entry.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Providers → Filters → Entry', () => {
109109
assert.ok(!actual);
110110
});
111111

112-
it('should return `false` when an entry do not match to the negative pattern', () => {
112+
it('should return `true` when an entry do not match to the negative pattern', () => {
113113
const filter = getFilter(['**/*'], ['*'], { absolute: true });
114114

115115
const entry = tests.entry.builder().path('root/file.txt').file().build();
@@ -120,6 +120,28 @@ describe('Providers → Filters → Entry', () => {
120120
});
121121
});
122122

123+
describe('options.baseNameMatch', () => {
124+
it('should return `false` when an option is disabled', () => {
125+
const filter = getFilter(['*'], []);
126+
127+
const entry = tests.entry.builder().path('root/file.txt').file().build();
128+
129+
const actual = filter(entry);
130+
131+
assert.ok(!actual);
132+
});
133+
134+
it('should return `true` when an option is enabled', () => {
135+
const filter = getFilter(['*'], [], { baseNameMatch: true });
136+
137+
const entry = tests.entry.builder().path('root/file.txt').file().build();
138+
139+
const actual = filter(entry);
140+
141+
assert.ok(actual);
142+
});
143+
});
144+
123145
describe('Pattern', () => {
124146
it('should return `false` when an entry match to the negative pattern', () => {
125147
const filter = getFilter(['**/*'], ['**/*']);

src/providers/filters/entry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default class EntryFilter {
3131
return false;
3232
}
3333

34-
return this._isMatchToPatterns(entry.path, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
34+
const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
35+
36+
return this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
3537
}
3638

3739
private _isDuplicateEntry(entry: Entry): boolean {

src/tests/smoke/match-base.smoke.ts renamed to src/tests/smoke/base-name-match.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as smoke from './smoke';
22

33
smoke.suite('Smoke → MatchBase', [
44
{
5-
broken: true,
6-
issue: 199,
75
pattern: '*.md',
86
cwd: 'fixtures',
97
globOptions: { matchBase: true },

0 commit comments

Comments
 (0)