File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
var gutil = require ( 'gulp-util' ) ;
3
3
var multimatch = require ( 'multimatch' ) ;
4
+ var path = require ( 'path' ) ;
4
5
var streamfilter = require ( 'streamfilter' ) ;
5
6
6
7
module . exports = function ( pattern , options ) {
@@ -13,7 +14,7 @@ module.exports = function (pattern, options) {
13
14
14
15
return streamfilter ( function ( file , enc , cb ) {
15
16
var match = typeof pattern === 'function' ? pattern ( file ) :
16
- multimatch ( file . relative , pattern , options ) . length > 0 ;
17
+ multimatch ( path . relative ( file . cwd , file . path ) , pattern , options ) . length > 0 ;
17
18
18
19
cb ( ! match ) ;
19
20
} , {
Original file line number Diff line number Diff line change @@ -131,6 +131,34 @@ describe('filter()', function () {
131
131
stream . write ( new gutil . File ( { path : 'app.js' } ) ) ;
132
132
stream . end ( ) ;
133
133
} ) ;
134
+
135
+ it ( 'should filter with respect to current working directory' , function ( cb ) {
136
+ var stream = filter ( 'test/**/*.js' ) ;
137
+ var buffer = [ ] ;
138
+
139
+ stream . on ( 'data' , function ( file ) {
140
+ buffer . push ( file ) ;
141
+ } ) ;
142
+
143
+ stream . on ( 'end' , function ( ) {
144
+ assert . equal ( buffer . length , 1 ) ;
145
+ assert . equal ( buffer [ 0 ] . relative , 'included.js' ) ;
146
+ cb ( ) ;
147
+ } ) ;
148
+
149
+ // mimic gulp.src('test/**/*.js')
150
+ stream . write ( new gutil . File ( {
151
+ base : path . join ( __dirname , 'test' ) ,
152
+ path : path . join ( __dirname , 'test' , 'included.js' )
153
+ } ) ) ;
154
+
155
+ stream . write ( new gutil . File ( {
156
+ base : __dirname ,
157
+ path : path . join ( __dirname , 'ignored.js' )
158
+ } ) ) ;
159
+
160
+ stream . end ( ) ;
161
+ } ) ;
134
162
} ) ;
135
163
136
164
describe ( 'filter.restore' , function ( ) {
You can’t perform that action at this time.
0 commit comments