Skip to content

Commit b0728ab

Browse files
committed
Merge pull request #59 from cb1kenobi/relative-fix
Fixed code to use the correct relative path wrt the current working directory.
2 parents 3310ca3 + 5fd40bc commit b0728ab

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
var gutil = require('gulp-util');
33
var multimatch = require('multimatch');
4+
var path = require('path');
45
var streamfilter = require('streamfilter');
56

67
module.exports = function (pattern, options) {
@@ -13,7 +14,7 @@ module.exports = function (pattern, options) {
1314

1415
return streamfilter(function (file, enc, cb) {
1516
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;
1718

1819
cb(!match);
1920
}, {

test.js

+28
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ describe('filter()', function () {
131131
stream.write(new gutil.File({path: 'app.js'}));
132132
stream.end();
133133
});
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+
});
134162
});
135163

136164
describe('filter.restore', function () {

0 commit comments

Comments
 (0)