glob-stream
Advanced tools
Comparing version 3.1.11 to 3.1.12
@@ -15,4 +15,4 @@ /*jslint node: true */ | ||
var isMatch = function(file, pattern) { | ||
if (typeof pattern === 'string') return minimatch(file.path, pattern); | ||
var isMatch = function(file, opt, pattern) { | ||
if (typeof pattern === 'string') return minimatch(file.path, pattern, opt); | ||
if (pattern instanceof RegExp) return pattern.test(file.path); | ||
@@ -47,2 +47,3 @@ return true; // unknown glob type? | ||
if (typeof opt.cwd !== 'string') opt.cwd = process.cwd(); | ||
if (typeof opt.dot !== 'boolean') opt.dot = false; | ||
if (typeof opt.silent !== 'boolean') opt.silent = true; | ||
@@ -52,3 +53,3 @@ if (typeof opt.nonull !== 'boolean') opt.nonull = false; | ||
if (opt.cwdbase) opt.base = opt.cwd; | ||
// remove path relativity to make globs make sense | ||
@@ -83,3 +84,3 @@ ourGlob = unrelative(opt.cwd, ourGlob); | ||
var filterStream = map(function(filename, cb) { | ||
var matcha = isMatch.bind(null, filename); | ||
var matcha = isMatch.bind(null, filename, opt); | ||
if (negatives.every(matcha)) return cb(null, filename); // pass | ||
@@ -86,0 +87,0 @@ cb(); // ignore |
{ | ||
"name": "glob-stream", | ||
"description": "File system globs as a stream", | ||
"version": "3.1.11", | ||
"version": "3.1.12", | ||
"homepage": "http://github.com/wearefractal/glob-stream", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/wearefractal/glob-stream.git", |
158
test/main.js
@@ -12,3 +12,3 @@ var gs = require('../'); | ||
it('should return a folder name stream from a glob', function(done) { | ||
var stream = gs.create("./fixtures/whatsgoingon", {cwd: __dirname}); | ||
var stream = gs.create('./fixtures/whatsgoingon', {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -24,4 +24,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, "./fixtures/whatsgoingon")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/whatsgoingon')); | ||
done(); | ||
@@ -32,3 +32,3 @@ }); | ||
it('should return a file name stream from a glob', function(done) { | ||
var stream = gs.create("./fixtures/*.coffee", {cwd: __dirname}); | ||
var stream = gs.create('./fixtures/*.coffee', {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -44,4 +44,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -52,3 +52,3 @@ }); | ||
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 stream = gs.create('./fixtures/stuff/*.dmc', {cwd: __dirname}); | ||
var wrapper = stream.pipe(through(function(data){ | ||
@@ -79,8 +79,8 @@ this.pause(); | ||
it('should return a correctly ordered file name stream for two globs and specified base', function(done) { | ||
var baseDir = join(__dirname, "./fixtures"); | ||
var baseDir = join(__dirname, './fixtures'); | ||
var globArray = [ | ||
"./whatsgoingon/key/isaidhey/whatsgoingon/test.txt", | ||
"./test.coffee", | ||
"./whatsgoingon/test.js" | ||
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt', | ||
'./test.coffee', | ||
'./whatsgoingon/test.js' | ||
]; | ||
@@ -102,8 +102,8 @@ var stream = gs.create(globArray, {cwd: baseDir, base: baseDir}); | ||
it('should return a correctly ordered file name stream for two globs and cwdbase', function(done) { | ||
var baseDir = join(__dirname, "./fixtures"); | ||
var baseDir = join(__dirname, './fixtures'); | ||
var globArray = [ | ||
"./whatsgoingon/key/isaidhey/whatsgoingon/test.txt", | ||
"./test.coffee", | ||
"./whatsgoingon/test.js" | ||
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt', | ||
'./test.coffee', | ||
'./whatsgoingon/test.js' | ||
]; | ||
@@ -125,3 +125,3 @@ var stream = gs.create(globArray, {cwd: baseDir, cwdbase: true}); | ||
it('should return a file name stream that does not duplicate', function(done) { | ||
var stream = gs.create(["./fixtures/test.coffee", "./fixtures/test.coffee"], {cwd: __dirname}); | ||
var stream = gs.create(['./fixtures/test.coffee', './fixtures/test.coffee'], {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -137,4 +137,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(file.path).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -145,4 +145,4 @@ }); | ||
it('should return a file name stream that does not duplicate when piped twice', function(done) { | ||
var stream = gs.create("./fixtures/test.coffee", {cwd: __dirname}); | ||
var stream2 = gs.create("./fixtures/test.coffee", {cwd: __dirname}); | ||
var stream = gs.create('./fixtures/test.coffee', {cwd: __dirname}); | ||
var stream2 = gs.create('./fixtures/test.coffee', {cwd: __dirname}); | ||
stream2.pipe(stream); | ||
@@ -160,4 +160,4 @@ | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(file.path).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -169,3 +169,3 @@ }); | ||
it('should return a file name stream from a direct path', function(done) { | ||
var stream = gs.create("./fixtures/test.coffee", {cwd: __dirname}); | ||
var stream = gs.create('./fixtures/test.coffee', {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -181,4 +181,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(file.path).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -188,4 +188,46 @@ }); | ||
it('should not return a file name stream with dotfiles without dot option', function(done) { | ||
var stream = gs.create('./fixtures/*swag', {cwd: __dirname}); | ||
should.exist(stream); | ||
stream.on('error', function(err) { | ||
throw err; | ||
}); | ||
stream.once('data', function(file) { | ||
throw new Error('It matched!'); | ||
}); | ||
stream.once('end', done); | ||
}); | ||
it('should return a file name stream with dotfiles with dot option', function(done) { | ||
var stream = gs.create('./fixtures/*swag', {cwd: __dirname, dot: true}); | ||
should.exist(stream); | ||
stream.on('error', function(err) { | ||
throw err; | ||
}); | ||
stream.once('data', function(file) { | ||
should.exist(file); | ||
should.exist(file.path); | ||
should.exist(file.base); | ||
should.exist(file.cwd); | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(file.path).should.equal(join(__dirname, './fixtures/.swag')); | ||
done(); | ||
}); | ||
}); | ||
it('should return a file name stream with dotfiles negated', function(done) { | ||
var stream = gs.create(['./fixtures/*swag', '!./fixtures/**'], {cwd: __dirname, dot: true}); | ||
should.exist(stream); | ||
stream.on('error', function(err) { | ||
throw err; | ||
}); | ||
stream.once('data', function(file) { | ||
throw new Error('It matched!'); | ||
}); | ||
stream.once('end', done); | ||
}); | ||
it('should return a file name stream from a direct path and pause/buffer items', function(done) { | ||
var stream = gs.create("./fixtures/test.coffee", {cwd: __dirname}); | ||
var stream = gs.create('./fixtures/test.coffee', {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -201,4 +243,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(file.path).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -213,3 +255,3 @@ }); | ||
it('should not fuck up direct paths with no cwd', function(done) { | ||
var stream = gs.create(join(__dirname, "./fixtures/test.coffee")); | ||
var stream = gs.create(join(__dirname, './fixtures/test.coffee')); | ||
should.exist(stream); | ||
@@ -225,4 +267,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(process.cwd()); | ||
String(file.base).should.equal(join(__dirname, "./fixtures/")); | ||
String(join(file.path,'')).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, './fixtures/')); | ||
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -234,5 +276,5 @@ }); | ||
var globArray = [ | ||
join(__dirname, "./fixtures/**/test.txt"), | ||
join(__dirname, "./fixtures/**/test.coffee"), | ||
join(__dirname, "./fixtures/**/test.js") | ||
join(__dirname, './fixtures/**/test.txt'), | ||
join(__dirname, './fixtures/**/test.coffee'), | ||
join(__dirname, './fixtures/**/test.js') | ||
]; | ||
@@ -259,5 +301,5 @@ var stream = gs.create(globArray, {cwd: __dirname}); | ||
var globArray = [ | ||
join(__dirname, "./fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt"), | ||
join(__dirname, "./fixtures/test.coffee"), | ||
join(__dirname, "./fixtures/whatsgoingon/test.js") | ||
join(__dirname, './fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt'), | ||
join(__dirname, './fixtures/test.coffee'), | ||
join(__dirname, './fixtures/whatsgoingon/test.js') | ||
]; | ||
@@ -281,10 +323,10 @@ var stream = gs.create(globArray, {cwd: __dirname}); | ||
}); | ||
it('should return a correctly ordered file name stream for two globs and custom base', function(done) { | ||
var baseDir = join(__dirname, "./fixtures"); | ||
var baseDir = join(__dirname, './fixtures'); | ||
var globArray = [ | ||
"./whatsgoingon/key/isaidhey/whatsgoingon/test.txt", | ||
"./test.coffee", | ||
"./whatsgoingon/test.js" | ||
'./whatsgoingon/key/isaidhey/whatsgoingon/test.txt', | ||
'./test.coffee', | ||
'./whatsgoingon/test.js' | ||
]; | ||
@@ -306,6 +348,6 @@ var stream = gs.create(globArray, {cwd: baseDir, cwdbase: true}); | ||
it('should return a input stream for multiple globs, with negation (globbing)', function(done) { | ||
var expectedPath = join(__dirname, "./fixtures/stuff/run.dmc"); | ||
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc'); | ||
var globArray = [ | ||
join(__dirname, "./fixtures/stuff/*.dmc"), | ||
'!' + join(__dirname, "./fixtures/stuff/test.dmc"), | ||
join(__dirname, './fixtures/stuff/*.dmc'), | ||
'!' + join(__dirname, './fixtures/stuff/test.dmc'), | ||
]; | ||
@@ -329,6 +371,6 @@ var stream = gs.create(globArray); | ||
it('should return a input stream for multiple globs, with negation (direct)', function(done) { | ||
var expectedPath = join(__dirname, "./fixtures/stuff/run.dmc"); | ||
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc'); | ||
var globArray = [ | ||
join(__dirname, "./fixtures/stuff/run.dmc"), | ||
'!' + join(__dirname, "./fixtures/stuff/test.dmc"), | ||
join(__dirname, './fixtures/stuff/run.dmc'), | ||
'!' + join(__dirname, './fixtures/stuff/test.dmc'), | ||
]; | ||
@@ -352,4 +394,4 @@ var stream = gs.create(globArray); | ||
it('should return a input stream that can be piped to other input streams and remove duplicates', function(done) { | ||
var stream = gs.create(join(__dirname, "./fixtures/stuff/*.dmc")); | ||
var stream2 = gs.create(join(__dirname, "./fixtures/stuff/*.dmc")); | ||
var stream = gs.create(join(__dirname, './fixtures/stuff/*.dmc')); | ||
var stream2 = gs.create(join(__dirname, './fixtures/stuff/*.dmc')); | ||
@@ -372,3 +414,3 @@ stream2.pipe(stream); | ||
it('should return a file name stream with negation from a glob', function(done) { | ||
var stream = gs.create(["./fixtures/**/*.js", "!./**/test.js"], {cwd: __dirname}); | ||
var stream = gs.create(['./fixtures/**/*.js', '!./**/test.js'], {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -379,3 +421,3 @@ stream.on('error', function(err) { | ||
stream.on('data', function(file) { | ||
throw new Error("file "+file.path+" should have been negated"); | ||
throw new Error('file '+file.path+' should have been negated'); | ||
}); | ||
@@ -388,3 +430,3 @@ stream.on('end', function() { | ||
it('should return a file name stream from two globs and a negative', function(done) { | ||
var stream = gs.create(["./fixtures/*.coffee", "./fixtures/whatsgoingon/*.coffee"], {cwd: __dirname}); | ||
var stream = gs.create(['./fixtures/*.coffee', './fixtures/whatsgoingon/*.coffee'], {cwd: __dirname}); | ||
should.exist(stream); | ||
@@ -400,4 +442,4 @@ stream.on('error', function(err) { | ||
String(file.cwd).should.equal(__dirname); | ||
String(file.base).should.equal(join(__dirname, "fixtures"+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, "./fixtures/test.coffee")); | ||
String(file.base).should.equal(join(__dirname, 'fixtures'+sep)); | ||
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee')); | ||
done(); | ||
@@ -404,0 +446,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22097
13
477