Skip to content

Commit

Permalink
Fix: Ensure basePath is resolved first (fixes gulpjs/gulp#1744) (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb authored and phated committed Aug 23, 2016
1 parent e993cb5 commit 0b71d70
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ var gs = {
// Creates a stream for a single glob or filter
createStream: function(ourGlob, negatives, opt) {

// Remove path relativity to make globs make sense
ourGlob = resolveGlob(ourGlob, opt);
var ourOpt = extend({}, opt);
delete ourOpt.root;

// Extract base path from glob
var basePath = ourOpt.base || getBasePath(ourGlob, opt);

// Remove path relativity to make globs make sense
ourGlob = resolveGlob(ourGlob, opt);

// Create globbing stuff
var globber = new glob.Glob(ourGlob, ourOpt);

// Extract base path from glob
var basePath = opt.base || globParent(ourGlob) + path.sep;

// Create stream and map events from globber to it
var stream = through2.obj(opt,
negatives.length ? filterNegatives : undefined);
Expand Down Expand Up @@ -188,4 +189,8 @@ function globIsSingular(glob) {
});
}

function getBasePath(ourGlob, opt) {
return resolveGlob(globParent(ourGlob) + path.sep, opt);
}

module.exports = gs;
1 change: 1 addition & 0 deletions test/fixtures/has (parens)/test.dmc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test
45 changes: 44 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,46 @@ describe('glob-stream', function() {
});
});

it('should handle ( ) in directory paths', function(done) {
var cwd = join(__dirname, './fixtures/has (parens)');
var stream = gs.create('*.dmc', { cwd: cwd });
should.exist(stream);
stream.on('error', function(err) {
throw err;
});
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
should.exist(file.base);
should.exist(file.cwd);
String(file.cwd).should.equal(cwd);
String(file.base).should.equal(cwd + sep);
String(join(file.path,'')).should.equal(join(cwd, 'test.dmc'));
done();
});
});

it('should find files in paths that contain ( )', function(done) {
var stream = gs.create('./fixtures/**/*.dmc', { cwd: __dirname });
var files = [];
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(3);
path.basename(files[0].path).should.equal('test.dmc');
files[0].path.should.equal(join(__dirname, 'fixtures/has (parens)/test.dmc'));
path.basename(files[1].path).should.equal('run.dmc');
files[1].path.should.equal(join(__dirname, 'fixtures/stuff/run.dmc'));
path.basename(files[2].path).should.equal('test.dmc');
files[2].path.should.equal(join(__dirname, 'fixtures/stuff/test.dmc'));
done();
});
});

it('should return a file name stream from a glob and respect state', function(done) {
var stream = gs.create('./fixtures/stuff/*.dmc', { cwd: __dirname });
var wrapper = stream.pipe(through2.obj(function(data, enc, cb) {
Expand Down Expand Up @@ -274,6 +314,7 @@ describe('glob-stream', function() {
join(__dirname, './fixtures/**/test.txt'),
join(__dirname, './fixtures/**/test.coffee'),
join(__dirname, './fixtures/**/test.js'),
join(__dirname, './fixtures/**/test.dmc'),
];
var stream = gs.create(globArray, { cwd: __dirname });

Expand All @@ -285,10 +326,12 @@ describe('glob-stream', function() {
files.push(file);
});
stream.on('end', function() {
files.length.should.equal(3);
files.length.should.equal(5);
path.basename(files[0].path).should.equal('test.txt');
path.basename(files[1].path).should.equal('test.coffee');
path.basename(files[2].path).should.equal('test.js');
path.basename(files[3].path).should.equal('test.dmc');
path.basename(files[4].path).should.equal('test.dmc');
done();
});
});
Expand Down

0 comments on commit 0b71d70

Please sign in to comment.