1
1
module . exports = minimatch
2
2
minimatch . Minimatch = Minimatch
3
3
4
- var LRU = require ( "lru-cache" )
5
- , cache = minimatch . cache = new LRU ( { max : 100 } )
6
- , GLOBSTAR = minimatch . GLOBSTAR = Minimatch . GLOBSTAR = { }
7
- , sigmund = require ( "sigmund" )
4
+ var GLOBSTAR = minimatch . GLOBSTAR = Minimatch . GLOBSTAR = { }
5
+ , expand = require ( "brace-expansion" )
8
6
9
7
// any single thing other than /
10
8
// don't need to escape / when using new RegExp()
@@ -99,7 +97,7 @@ function minimatch (p, pattern, options) {
99
97
100
98
function Minimatch ( pattern , options ) {
101
99
if ( ! ( this instanceof Minimatch ) ) {
102
- return new Minimatch ( pattern , options , cache )
100
+ return new Minimatch ( pattern , options )
103
101
}
104
102
105
103
if ( typeof pattern !== "string" ) {
@@ -109,14 +107,6 @@ function Minimatch (pattern, options) {
109
107
if ( ! options ) options = { }
110
108
pattern = pattern . trim ( )
111
109
112
- // lru storage.
113
- // these things aren't particularly big, but walking down the string
114
- // and turning it into a regexp can get pretty costly.
115
- var cacheKey = pattern + "\n" + sigmund ( options )
116
- var cached = minimatch . cache . get ( cacheKey )
117
- if ( cached ) return cached
118
- minimatch . cache . set ( cacheKey , this )
119
-
120
110
this . options = options
121
111
this . set = [ ]
122
112
this . pattern = pattern
@@ -218,19 +208,19 @@ function parseNegate () {
218
208
// a{2..}b -> a{2..}b
219
209
// a{b}c -> a{b}c
220
210
minimatch . braceExpand = function ( pattern , options ) {
221
- return new Minimatch ( pattern , options ) . braceExpand ( )
211
+ return braceExpand ( pattern , options )
222
212
}
223
213
224
214
Minimatch . prototype . braceExpand = braceExpand
225
215
226
- function pad ( n , width , z ) {
227
- z = z || '0' ;
228
- n = n + '' ;
229
- return n . length >= width ? n : new Array ( width - n . length + 1 ) . join ( z ) + n ;
230
- }
231
-
232
216
function braceExpand ( pattern , options ) {
233
- options = options || this . options
217
+ if ( ! options ) {
218
+ if ( this instanceof Minimatch )
219
+ options = this . options
220
+ else
221
+ options = { }
222
+ }
223
+
234
224
pattern = typeof pattern === "undefined"
235
225
? this . pattern : pattern
236
226
@@ -244,187 +234,7 @@ function braceExpand (pattern, options) {
244
234
return [ pattern ]
245
235
}
246
236
247
- var escaping = false
248
-
249
- // examples and comments refer to this crazy pattern:
250
- // a{b,c{d,e},{f,g}h }x{y,z}
251
- // expected:
252
- // abxy
253
- // abxz
254
- // acdxy
255
- // acdxz
256
- // acexy
257
- // acexz
258
- // afhxy
259
- // afhxz
260
- // aghxy
261
- // aghxz
262
-
263
- // everything before the first \{ is just a prefix.
264
- // So, we pluck that off, and work with the rest,
265
- // and then prepend it to everything we find.
266
- if ( pattern . charAt ( 0 ) !== "{" ) {
267
- this . debug ( pattern )
268
- var prefix = null
269
- for ( var i = 0 , l = pattern . length ; i < l ; i ++ ) {
270
- var c = pattern . charAt ( i )
271
- this . debug ( i , c )
272
- if ( c === "\\" ) {
273
- escaping = ! escaping
274
- } else if ( c === "{" && ! escaping ) {
275
- prefix = pattern . substr ( 0 , i )
276
- break
277
- }
278
- }
279
-
280
- // actually no sets, all { were escaped.
281
- if ( prefix === null ) {
282
- this . debug ( "no sets" )
283
- return [ pattern ]
284
- }
285
-
286
- var tail = braceExpand . call ( this , pattern . substr ( i ) , options )
287
- return tail . map ( function ( t ) {
288
- return prefix + t
289
- } )
290
- }
291
-
292
- // now we have something like:
293
- // {b,c{d,e},{f,g}h }x{y,z}
294
- // walk through the set, expanding each part, until
295
- // the set ends. then, we'll expand the suffix.
296
- // If the set only has a single member, then'll put the {} back
297
-
298
- // first, handle numeric sets, since they're easier
299
- var numset = pattern . match ( / ^ \{ ( - ? [ 0 - 9 ] + ) \. \. ( - ? [ 0 - 9 ] + ) \} / )
300
- if ( numset ) {
301
- this . debug ( "numset" , numset [ 1 ] , numset [ 2 ] )
302
- var suf = braceExpand . call ( this , pattern . substr ( numset [ 0 ] . length ) , options )
303
- , start = + numset [ 1 ]
304
- , needPadding = numset [ 1 ] [ 0 ] === '0'
305
- , startWidth = numset [ 1 ] . length
306
- , padded
307
- , end = + numset [ 2 ]
308
- , inc = start > end ? - 1 : 1
309
- , set = [ ]
310
-
311
- for ( var i = start ; i != ( end + inc ) ; i += inc ) {
312
- padded = needPadding ? pad ( i , startWidth ) : i + ''
313
- // append all the suffixes
314
- for ( var ii = 0 , ll = suf . length ; ii < ll ; ii ++ ) {
315
- set . push ( padded + suf [ ii ] )
316
- }
317
- }
318
- return set
319
- }
320
-
321
- // ok, walk through the set
322
- // We hope, somewhat optimistically, that there
323
- // will be a } at the end.
324
- // If the closing brace isn't found, then the pattern is
325
- // interpreted as braceExpand("\\" + pattern) so that
326
- // the leading \{ will be interpreted literally.
327
- var i = 1 // skip the \{
328
- , depth = 1
329
- , set = [ ]
330
- , member = ""
331
- , sawEnd = false
332
- , escaping = false
333
-
334
- function addMember ( ) {
335
- set . push ( member )
336
- member = ""
337
- }
338
-
339
- this . debug ( "Entering for" )
340
- FOR: for ( i = 1 , l = pattern . length ; i < l ; i ++ ) {
341
- var c = pattern . charAt ( i )
342
- this . debug ( "" , i , c )
343
-
344
- if ( escaping ) {
345
- escaping = false
346
- member += "\\" + c
347
- } else {
348
- switch ( c ) {
349
- case "\\" :
350
- escaping = true
351
- continue
352
-
353
- case "{" :
354
- depth ++
355
- member += "{"
356
- continue
357
-
358
- case "}" :
359
- depth --
360
- // if this closes the actual set, then we're done
361
- if ( depth === 0 ) {
362
- addMember ( )
363
- // pluck off the close-brace
364
- i ++
365
- break FOR
366
- } else {
367
- member += c
368
- continue
369
- }
370
-
371
- case "," :
372
- if ( depth === 1 ) {
373
- addMember ( )
374
- } else {
375
- member += c
376
- }
377
- continue
378
-
379
- default :
380
- member += c
381
- continue
382
- } // switch
383
- } // else
384
- } // for
385
-
386
- // now we've either finished the set, and the suffix is
387
- // pattern.substr(i), or we have *not* closed the set,
388
- // and need to escape the leading brace
389
- if ( depth !== 0 ) {
390
- this . debug ( "didn't close" , pattern )
391
- return braceExpand . call ( this , "\\" + pattern , options )
392
- }
393
-
394
- // x{y,z} -> ["xy", "xz"]
395
- this . debug ( "set" , set )
396
- this . debug ( "suffix" , pattern . substr ( i ) )
397
- var suf = braceExpand . call ( this , pattern . substr ( i ) , options )
398
- // ["b", "c{d,e}","{f,g}h"] ->
399
- // [["b"], ["cd", "ce"], ["fh", "gh"]]
400
- var addBraces = set . length === 1
401
- this . debug ( "set pre-expanded" , set )
402
- set = set . map ( function ( p ) {
403
- return braceExpand . call ( this , p , options )
404
- } , this )
405
- this . debug ( "set expanded" , set )
406
-
407
-
408
- // [["b"], ["cd", "ce"], ["fh", "gh"]] ->
409
- // ["b", "cd", "ce", "fh", "gh"]
410
- set = set . reduce ( function ( l , r ) {
411
- return l . concat ( r )
412
- } )
413
-
414
- if ( addBraces ) {
415
- set = set . map ( function ( s ) {
416
- return "{" + s + "}"
417
- } )
418
- }
419
-
420
- // now attach the suffixes.
421
- var ret = [ ]
422
- for ( var i = 0 , l = set . length ; i < l ; i ++ ) {
423
- for ( var ii = 0 , ll = suf . length ; ii < ll ; ii ++ ) {
424
- ret . push ( set [ i ] + suf [ ii ] )
425
- }
426
- }
427
- return ret
237
+ return expand ( pattern )
428
238
}
429
239
430
240
// parse a component of the expanded set.
0 commit comments