@@ -11,31 +11,6 @@ var minimatch = require('minimatch');
11
11
var glob2base = require ( 'glob2base' ) ;
12
12
var path = require ( 'path' ) ;
13
13
14
- var isMatch = function ( file , opt , pattern ) {
15
- if ( typeof pattern === 'string' ) return minimatch ( file . path , pattern , opt ) ;
16
- if ( pattern instanceof RegExp ) return pattern . test ( file . path ) ;
17
- return true ; // unknown glob type?
18
- } ;
19
-
20
- var isNegative = function ( pattern ) {
21
- if ( typeof pattern !== 'string' ) return true ;
22
- if ( pattern [ 0 ] === '!' ) return true ;
23
- return false ;
24
- } ;
25
-
26
- var isPositive = function ( pattern ) {
27
- return ! isNegative ( pattern ) ;
28
- } ;
29
-
30
- var unrelative = function ( cwd , glob ) {
31
- var mod = '' ;
32
- if ( glob [ 0 ] === '!' ) {
33
- mod = glob [ 0 ] ;
34
- glob = glob . slice ( 1 ) ;
35
- }
36
- return mod + path . resolve ( cwd , glob ) ;
37
- } ;
38
-
39
14
var gs = {
40
15
// creates a stream for a single glob or filter
41
16
createStream : function ( ourGlob , negatives , opt ) {
@@ -58,18 +33,8 @@ var gs = {
58
33
// extract base path from glob
59
34
var basePath = opt . base ? opt . base : glob2base ( globber ) ;
60
35
61
- // needed filtering, check against negatives
62
- function filterNegatives ( filename , enc , cb ) {
63
- var matcha = isMatch . bind ( null , filename , opt ) ;
64
- if ( negatives . every ( matcha ) ) {
65
- cb ( null , filename ) ; // pass
66
- } else {
67
- cb ( ) ; // ignore
68
- }
69
- } ;
70
-
71
36
// create stream and map events from globber to it
72
- var stream = through2 . obj ( negatives . length !== 0 ? filterNegatives : undefined ) ;
37
+ var stream = through2 . obj ( negatives . length ? filterNegatives : undefined ) ;
73
38
74
39
globber . on ( 'error' , stream . emit . bind ( stream , 'error' ) ) ;
75
40
globber . on ( 'end' , function ( /* some args here so can't use bind directly */ ) {
@@ -84,6 +49,15 @@ var gs = {
84
49
} ) ;
85
50
86
51
return stream ;
52
+
53
+ function filterNegatives ( filename , enc , cb ) {
54
+ var matcha = isMatch . bind ( null , filename , opt ) ;
55
+ if ( negatives . every ( matcha ) ) {
56
+ cb ( null , filename ) ; // pass
57
+ } else {
58
+ cb ( ) ; // ignore
59
+ }
60
+ }
87
61
} ,
88
62
89
63
// creates a stream for multiple globs or filters
@@ -116,4 +90,30 @@ var gs = {
116
90
}
117
91
} ;
118
92
93
+ function isMatch ( file , opt , pattern ) {
94
+ if ( typeof pattern === 'string' ) return minimatch ( file . path , pattern , opt ) ;
95
+ if ( pattern instanceof RegExp ) return pattern . test ( file . path ) ;
96
+ return true ; // unknown glob type?
97
+ }
98
+
99
+ function isNegative ( pattern ) {
100
+ if ( typeof pattern !== 'string' ) return true ;
101
+ if ( pattern [ 0 ] === '!' ) return true ;
102
+ return false ;
103
+ }
104
+
105
+ function isPositive ( pattern ) {
106
+ return ! isNegative ( pattern ) ;
107
+ }
108
+
109
+ function unrelative ( cwd , glob ) {
110
+ var mod = '' ;
111
+ if ( glob [ 0 ] === '!' ) {
112
+ mod = glob [ 0 ] ;
113
+ glob = glob . slice ( 1 ) ;
114
+ }
115
+ return mod + path . resolve ( cwd , glob ) ;
116
+ }
117
+
118
+
119
119
module . exports = gs ;
0 commit comments