@@ -22,6 +22,7 @@ class Walker extends EE {
22
22
this . result = this . parent ? this . parent . result : new Set ( )
23
23
this . entries = null
24
24
this . sawError = false
25
+ this . exact = opts . exact
25
26
}
26
27
27
28
sort ( a , b ) {
@@ -164,7 +165,7 @@ class Walker extends EE {
164
165
} else {
165
166
// is a directory
166
167
if ( dir ) {
167
- this . walker ( entry , { isSymbolicLink } , then )
168
+ this . walker ( entry , { isSymbolicLink, exact : file || this . filterEntry ( entry + '/' ) } , then )
168
169
} else {
169
170
then ( )
170
171
}
@@ -208,15 +209,19 @@ class Walker extends EE {
208
209
new Walker ( this . walkerOpt ( entry , opts ) ) . on ( 'done' , then ) . start ( )
209
210
}
210
211
211
- filterEntry ( entry , partial ) {
212
+ filterEntry ( entry , partial , entryBasename ) {
212
213
let included = true
213
214
214
215
// this = /a/b/c
215
216
// entry = d
216
217
// parent /a/b sees c/d
217
218
if ( this . parent && this . parent . filterEntry ) {
218
- var pt = this . basename + '/' + entry
219
- included = this . parent . filterEntry ( pt , partial )
219
+ const parentEntry = this . basename + '/' + entry
220
+ const parentBasename = entryBasename || entry
221
+ included = this . parent . filterEntry ( parentEntry , partial , parentBasename )
222
+ if ( ! included && ! this . exact ) {
223
+ return false
224
+ }
220
225
}
221
226
222
227
this . ignoreFiles . forEach ( f => {
@@ -226,17 +231,28 @@ class Walker extends EE {
226
231
// so if it's negated, and already included, no need to check
227
232
// likewise if it's neither negated nor included
228
233
if ( rule . negate !== included ) {
234
+ const isRelativeRule = entryBasename && rule . globParts . some ( part =>
235
+ part . length <= ( part . slice ( - 1 ) [ 0 ] ? 1 : 2 )
236
+ )
237
+
229
238
// first, match against /foo/bar
230
239
// then, against foo/bar
231
240
// then, in the case of partials, match with a /
241
+ // then, if also the rule is relative, match against basename
232
242
const match = rule . match ( '/' + entry ) ||
233
243
rule . match ( entry ) ||
234
- ( ! ! partial && (
244
+ ! ! partial && (
235
245
rule . match ( '/' + entry + '/' ) ||
236
- rule . match ( entry + '/' ) ) ) ||
237
- ( ! ! partial && rule . negate && (
238
- rule . match ( '/' + entry , true ) ||
239
- rule . match ( entry , true ) ) )
246
+ rule . match ( entry + '/' ) ||
247
+ rule . negate && (
248
+ rule . match ( '/' + entry , true ) ||
249
+ rule . match ( entry , true ) ) ||
250
+ isRelativeRule && (
251
+ rule . match ( '/' + entryBasename + '/' ) ||
252
+ rule . match ( entryBasename + '/' ) ||
253
+ rule . negate && (
254
+ rule . match ( '/' + entryBasename , true ) ||
255
+ rule . match ( entryBasename , true ) ) ) )
240
256
241
257
if ( match ) {
242
258
included = rule . negate
0 commit comments