Skip to content

Commit

Permalink
Fixed code to use the correct relative path wrt the current working d…
Browse files Browse the repository at this point in the history
…irectory.
  • Loading branch information
cb1kenobi committed Feb 29, 2016
1 parent 3310ca3 commit 5fd40bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var gutil = require('gulp-util');
var multimatch = require('multimatch');
var path = require('path');
var streamfilter = require('streamfilter');

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

return streamfilter(function (file, enc, cb) {
var match = typeof pattern === 'function' ? pattern(file) :
multimatch(file.relative, pattern, options).length > 0;
multimatch(path.relative(file.cwd, file.path), pattern, options).length > 0;

cb(!match);
}, {
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,34 @@ describe('filter()', function () {
stream.write(new gutil.File({path: 'app.js'}));
stream.end();
});

it('should filter with respect to current working directory', function (cb) {
var stream = filter('test/**/*.js');
var buffer = [];

stream.on('data', function (file) {
buffer.push(file);
});

stream.on('end', function () {
assert.equal(buffer.length, 1);
assert.equal(buffer[0].relative, 'included.js');
cb();
});

// mimic gulp.src('test/**/*.js')
stream.write(new gutil.File({
base: path.join(__dirname, 'test'),
path: path.join(__dirname, 'test', 'included.js')
}));

stream.write(new gutil.File({
base: __dirname,
path: path.join(__dirname, 'ignored.js')
}));

stream.end();
});
});

describe('filter.restore', function () {
Expand Down

0 comments on commit 5fd40bc

Please sign in to comment.