@@ -5,7 +5,6 @@ var Combine = require('ordered-read-streams');
5
5
var unique = require ( 'unique-stream' ) ;
6
6
7
7
var glob = require ( 'glob' ) ;
8
- var micromatch = require ( 'micromatch' ) ;
9
8
var resolveGlob = require ( 'to-absolute-glob' ) ;
10
9
var globParent = require ( 'glob-parent' ) ;
11
10
var path = require ( 'path' ) ;
@@ -15,10 +14,16 @@ var sepRe = (process.platform === 'win32' ? /[\/\\]/ : /\/+/);
15
14
var gs = {
16
15
// Creates a stream for a single glob or filter
17
16
createStream : function ( ourGlob , negatives , opt ) {
17
+ function resolveNegatives ( negative ) {
18
+ return resolveGlob ( negative , opt ) ;
19
+ }
18
20
19
21
var ourOpt = extend ( { } , opt ) ;
20
22
delete ourOpt . root ;
21
23
24
+ var ourNegatives = negatives . map ( resolveNegatives ) ;
25
+ ourOpt . ignore = ourNegatives ;
26
+
22
27
// Extract base path from glob
23
28
var basePath = ourOpt . base || getBasePath ( ourGlob , opt ) ;
24
29
@@ -29,8 +34,7 @@ var gs = {
29
34
var globber = new glob . Glob ( ourGlob , ourOpt ) ;
30
35
31
36
// Create stream and map events from globber to it
32
- var stream = through2 . obj ( opt ,
33
- negatives . length ? filterNegatives : undefined ) ;
37
+ var stream = through2 . obj ( ourOpt ) ;
34
38
35
39
var found = false ;
36
40
@@ -52,17 +56,7 @@ var gs = {
52
56
path : path . normalize ( filename ) ,
53
57
} ) ;
54
58
} ) ;
55
-
56
59
return stream ;
57
-
58
- function filterNegatives ( filename , enc , cb ) {
59
- var matcha = isMatch . bind ( null , filename ) ;
60
- if ( negatives . every ( matcha ) ) {
61
- cb ( null , filename ) ; // Pass
62
- } else {
63
- cb ( ) ; // Ignore
64
- }
65
- }
66
60
} ,
67
61
68
62
// Creates a stream for multiple globs or filters
@@ -97,22 +91,13 @@ var gs = {
97
91
var positives = [ ] ;
98
92
var negatives = [ ] ;
99
93
100
- var ourOpt = extend ( { } , opt ) ;
101
- delete ourOpt . root ;
102
-
103
94
globs . forEach ( function ( glob , index ) {
104
- if ( typeof glob !== 'string' && ! ( glob instanceof RegExp ) ) {
95
+ if ( typeof glob !== 'string' ) {
105
96
throw new Error ( 'Invalid glob at index ' + index ) ;
106
97
}
107
98
108
99
var globArray = isNegative ( glob ) ? negatives : positives ;
109
100
110
- // Create Minimatch instances for negative glob patterns
111
- if ( globArray === negatives && typeof glob === 'string' ) {
112
- var ourGlob = resolveGlob ( glob , opt ) ;
113
- glob = micromatch . matcher ( ourGlob , ourOpt ) ;
114
- }
115
-
116
101
globArray . push ( {
117
102
index : index ,
118
103
glob : glob ,
@@ -144,28 +129,18 @@ var gs = {
144
129
145
130
function streamFromPositive ( positive ) {
146
131
var negativeGlobs = negatives . filter ( indexGreaterThan ( positive . index ) )
147
- . map ( toGlob ) ;
132
+ . map ( toGlob )
133
+ . map ( stripExclamationMark ) ;
148
134
return gs . createStream ( positive . glob , negativeGlobs , opt ) ;
149
135
}
150
136
} ,
151
137
} ;
152
138
153
- function isMatch ( file , matcher ) {
154
- if ( typeof matcher === 'function' ) {
155
- return matcher ( file . path ) ;
156
- }
157
- if ( matcher instanceof RegExp ) {
158
- return matcher . test ( file . path ) ;
159
- }
160
- }
161
139
162
140
function isNegative ( pattern ) {
163
141
if ( typeof pattern === 'string' ) {
164
142
return pattern [ 0 ] === '!' ;
165
143
}
166
- if ( pattern instanceof RegExp ) {
167
- return true ;
168
- }
169
144
}
170
145
171
146
function indexGreaterThan ( index ) {
@@ -180,7 +155,6 @@ function toGlob(obj) {
180
155
181
156
function globIsSingular ( glob ) {
182
157
var globSet = glob . minimatch . set ;
183
-
184
158
if ( globSet . length !== 1 ) {
185
159
return false ;
186
160
}
@@ -206,4 +180,8 @@ function getBasePath(ourGlob, opt) {
206
180
return basePath ;
207
181
}
208
182
183
+ function stripExclamationMark ( glob ) {
184
+ return glob . slice ( 1 ) ;
185
+ }
186
+
209
187
module . exports = gs ;
0 commit comments