pax_global_header 0000666 0000000 0000000 00000000064 12760104532 0014512 g ustar 00root root 0000000 0000000 52 comment=eadafd3cde31c5508547f4ad57b54d92a3003ca2
glob-stream-5.3.4/ 0000775 0000000 0000000 00000000000 12760104532 0013737 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/.editorconfig 0000664 0000000 0000000 00000000317 12760104532 0016415 0 ustar 00root root 0000000 0000000 # editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
glob-stream-5.3.4/.eslintignore 0000664 0000000 0000000 00000000017 12760104532 0016440 0 ustar 00root root 0000000 0000000 test/fixtures/
glob-stream-5.3.4/.eslintrc 0000664 0000000 0000000 00000000030 12760104532 0015554 0 ustar 00root root 0000000 0000000 {
"extends": "gulp"
}
glob-stream-5.3.4/.gitignore 0000664 0000000 0000000 00000000073 12760104532 0015727 0 ustar 00root root 0000000 0000000 .DS_Store
*.log
node_modules
build
*.node
components
.idea
glob-stream-5.3.4/.jscsrc 0000664 0000000 0000000 00000000027 12760104532 0015226 0 ustar 00root root 0000000 0000000 {
"preset": "gulp"
}
glob-stream-5.3.4/.travis.yml 0000664 0000000 0000000 00000000166 12760104532 0016053 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
node_js:
- 'stable'
- '4'
- '0.12'
- '0.10'
after_script:
- npm run coveralls
glob-stream-5.3.4/LICENSE 0000775 0000000 0000000 00000002142 12760104532 0014746 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015 Blaine Bublitz, Eric Schoffstall and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
glob-stream-5.3.4/README.md 0000664 0000000 0000000 00000005334 12760104532 0015223 0 ustar 00root root 0000000 0000000
# glob-stream
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
A wrapper around [node-glob][node-glob-url] to make it streamy.
## Usage
```javascript
var gs = require('glob-stream');
var stream = gs.create('./files/**/*.coffee', { /* options */ });
stream.on('data', function(file){
// file has path, base, and cwd attrs
});
```
You can pass any combination of globs. One caveat is that you can not only pass a glob negation, you must give it at least one positive glob so it knows where to start. All given must match for the file to be returned.
## API
### create(globs, options)
Returns a stream for multiple globs or filters.
### createStream(positiveGlob, negativeGlobs, options)
Returns a stream for a single glob or filter.
### Options
- cwd
- Default is `process.cwd()`
- base
- Default is everything before a glob starts (see [glob-parent][glob-parent-url])
- cwdbase
- Default is `false`
- When true it is the same as saying opt.base = opt.cwd
- allowEmpty
- Default is `false`
- If true, won't emit an error when a glob pointing at a single file fails to match
- Any through2 related options are documented in [through2][through2-url]
This argument is passed directly to [node-glob][node-glob-url] so check there for more options
### Glob
```js
var stream = gs.create(['./**/*.js', '!./node_modules/**/*']);
```
Globs are executed in order, so negations should follow positive globs. For example:
```js
gulp.src(['!b*.js', '*.js'])
```
would not exclude any files, but this would
```js
gulp.src(['*.js', '!b*.js'])
```
## Related
- [globby][globby-url] - Non-streaming `glob` wrapper with support for multiple patterns.
## License
MIT
[globby-url]: https://github.com/sindresorhus/globby
[through2-url]: https://github.com/rvagg/through2
[node-glob-url]: https://github.com/isaacs/node-glob
[glob-parent-url]: https://github.com/es128/glob-parent
[downloads-image]: http://img.shields.io/npm/dm/glob-stream.svg
[npm-url]: https://www.npmjs.com/package/glob-stream
[npm-image]: https://badge.fury.io/js/glob-stream.svg
[travis-url]: https://travis-ci.org/gulpjs/glob-stream
[travis-image]: https://travis-ci.org/gulpjs/glob-stream.svg?branch=master
[coveralls-url]: https://coveralls.io/r/gulpjs/glob-stream
[coveralls-image]: https://coveralls.io/repos/gulpjs/glob-stream/badge.svg
[gitter-url]: https://gitter.im/gulpjs/gulp
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.png
glob-stream-5.3.4/appveyor.yml 0000664 0000000 0000000 00000001123 12760104532 0016324 0 ustar 00root root 0000000 0000000 # Test against these versions of Node.js
environment:
matrix:
# node.js
- nodejs_version: "6.0"
- nodejs_version: "5.0"
- nodejs_version: "4.0"
- nodejs_version: "0.12"
- nodejs_version: "0.10"
# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test
# Don't actually build.
build: off
glob-stream-5.3.4/index.js 0000664 0000000 0000000 00000011666 12760104532 0015416 0 ustar 00root root 0000000 0000000 'use strict';
var through2 = require('through2');
var Combine = require('ordered-read-streams');
var unique = require('unique-stream');
var glob = require('glob');
var micromatch = require('micromatch');
var resolveGlob = require('to-absolute-glob');
var globParent = require('glob-parent');
var path = require('path');
var extend = require('extend');
var sepRe = (process.platform === 'win32' ? /[\/\\]/ : /\/+/);
var gs = {
// Creates a stream for a single glob or filter
createStream: function(ourGlob, negatives, 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);
// Create stream and map events from globber to it
var stream = through2.obj(opt,
negatives.length ? filterNegatives : undefined);
var found = false;
globber.on('error', stream.emit.bind(stream, 'error'));
globber.once('end', function() {
if (opt.allowEmpty !== true && !found && globIsSingular(globber)) {
stream.emit('error',
new Error('File not found with singular glob: ' + ourGlob));
}
stream.end();
});
globber.on('match', function(filename) {
found = true;
stream.write({
cwd: opt.cwd,
base: basePath,
path: path.normalize(filename),
});
});
return stream;
function filterNegatives(filename, enc, cb) {
var matcha = isMatch.bind(null, filename);
if (negatives.every(matcha)) {
cb(null, filename); // Pass
} else {
cb(); // Ignore
}
}
},
// Creates a stream for multiple globs or filters
create: function(globs, opt) {
if (!opt) {
opt = {};
}
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;
}
if (typeof opt.nonull !== 'boolean') {
opt.nonull = false;
}
if (typeof opt.cwdbase !== 'boolean') {
opt.cwdbase = false;
}
if (opt.cwdbase) {
opt.base = opt.cwd;
}
// Only one glob no need to aggregate
if (!Array.isArray(globs)) {
globs = [globs];
}
var positives = [];
var negatives = [];
var ourOpt = extend({}, opt);
delete ourOpt.root;
globs.forEach(function(glob, index) {
if (typeof glob !== 'string' && !(glob instanceof RegExp)) {
throw new Error('Invalid glob at index ' + index);
}
var globArray = isNegative(glob) ? negatives : positives;
// Create Minimatch instances for negative glob patterns
if (globArray === negatives && typeof glob === 'string') {
var ourGlob = resolveGlob(glob, opt);
glob = micromatch.matcher(ourGlob, ourOpt);
}
globArray.push({
index: index,
glob: glob,
});
});
if (positives.length === 0) {
throw new Error('Missing positive glob');
}
// Only one positive glob no need to aggregate
if (positives.length === 1) {
return streamFromPositive(positives[0]);
}
// Create all individual streams
var streams = positives.map(streamFromPositive);
// Then just pipe them to a single unique stream and return it
var aggregate = new Combine(streams);
var uniqueStream = unique('path');
var returnStream = aggregate.pipe(uniqueStream);
aggregate.on('error', function(err) {
returnStream.emit('error', err);
});
return returnStream;
function streamFromPositive(positive) {
var negativeGlobs = negatives.filter(indexGreaterThan(positive.index))
.map(toGlob);
return gs.createStream(positive.glob, negativeGlobs, opt);
}
},
};
function isMatch(file, matcher) {
if (typeof matcher === 'function') {
return matcher(file.path);
}
if (matcher instanceof RegExp) {
return matcher.test(file.path);
}
}
function isNegative(pattern) {
if (typeof pattern === 'string') {
return pattern[0] === '!';
}
if (pattern instanceof RegExp) {
return true;
}
}
function indexGreaterThan(index) {
return function(obj) {
return obj.index > index;
};
}
function toGlob(obj) {
return obj.glob;
}
function globIsSingular(glob) {
var globSet = glob.minimatch.set;
if (globSet.length !== 1) {
return false;
}
return globSet[0].every(function isString(value) {
return typeof value === 'string';
});
}
function getBasePath(ourGlob, opt) {
var basePath;
var parent = globParent(ourGlob);
if (parent === '/' && opt && opt.root) {
basePath = path.normalize(opt.root);
} else {
basePath = resolveGlob(parent, opt);
}
if (!sepRe.test(basePath.charAt(basePath.length - 1))) {
basePath += path.sep;
}
return basePath;
}
module.exports = gs;
glob-stream-5.3.4/package.json 0000664 0000000 0000000 00000002351 12760104532 0016226 0 ustar 00root root 0000000 0000000 {
"name": "glob-stream",
"version": "5.3.4",
"description": "A wrapper around node-glob to make it streamy",
"author": "Gulp Team (http://gulpjs.com/)",
"contributors": [],
"homepage": "http://gulpjs.com",
"repository": "gulpjs/glob-stream",
"license": "MIT",
"engines": {
"node": ">= 0.10"
},
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"lint": "eslint . && jscs . test/",
"pretest": "npm run lint",
"test": "mocha",
"coveralls": "istanbul cover _mocha --report lcovonly && istanbul-coveralls"
},
"dependencies": {
"extend": "^3.0.0",
"glob": "^5.0.3",
"glob-parent": "^2.0.0",
"micromatch": "^2.3.7",
"ordered-read-streams": "^0.3.0",
"through2": "^0.6.0",
"to-absolute-glob": "^0.1.1",
"unique-stream": "^2.0.2"
},
"devDependencies": {
"coveralls": "^2.11.2",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"istanbul": "^0.3.0",
"istanbul-coveralls": "^1.0.1",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"mocha": "^2.0.0",
"mocha-lcov-reporter": "^0.0.2",
"rimraf": "^2.2.5",
"should": "^7.1.0",
"stream-sink": "^1.2.0"
},
"keywords": [
"glob",
"stream"
]
}
glob-stream-5.3.4/test/ 0000775 0000000 0000000 00000000000 12760104532 0014716 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/.eslintrc 0000664 0000000 0000000 00000000035 12760104532 0016540 0 ustar 00root root 0000000 0000000 {
"extends": "gulp/test"
}
glob-stream-5.3.4/test/fixtures/ 0000775 0000000 0000000 00000000000 12760104532 0016567 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/.swag 0000664 0000000 0000000 00000000003 12760104532 0017522 0 ustar 00root root 0000000 0000000 yup glob-stream-5.3.4/test/fixtures/has (parens)/ 0000775 0000000 0000000 00000000000 12760104532 0020734 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/has (parens)/test.dmc 0000664 0000000 0000000 00000000016 12760104532 0022375 0 ustar 00root root 0000000 0000000 this is a test glob-stream-5.3.4/test/fixtures/stuff/ 0000775 0000000 0000000 00000000000 12760104532 0017716 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/stuff/run.dmc 0000664 0000000 0000000 00000000000 12760104532 0021175 0 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/stuff/test.dmc 0000664 0000000 0000000 00000000000 12760104532 0021350 0 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/test.coffee 0000664 0000000 0000000 00000000016 12760104532 0020714 0 ustar 00root root 0000000 0000000 this is a test glob-stream-5.3.4/test/fixtures/whatsgoingon/ 0000775 0000000 0000000 00000000000 12760104532 0021276 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/whatsgoingon/hey/ 0000775 0000000 0000000 00000000000 12760104532 0022063 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/whatsgoingon/hey/isaidhey/ 0000775 0000000 0000000 00000000000 12760104532 0023662 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/ 0000775 0000000 0000000 00000000000 12760104532 0026371 5 ustar 00root root 0000000 0000000 glob-stream-5.3.4/test/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt 0000664 0000000 0000000 00000000022 12760104532 0030103 0 ustar 00root root 0000000 0000000 Heyyyayyyayyyayyyy glob-stream-5.3.4/test/fixtures/whatsgoingon/test.js 0000664 0000000 0000000 00000000004 12760104532 0022605 0 ustar 00root root 0000000 0000000 what glob-stream-5.3.4/test/main.js 0000664 0000000 0000000 00000053146 12760104532 0016211 0 ustar 00root root 0000000 0000000 var gs = require('../');
var through2 = require('through2');
var should = require('should');
var path = require('path');
var join = path.join;
var sep = path.sep;
describe('glob-stream', function() {
describe('create()', function() {
it('should return a folder name stream from a glob', function(done) {
var stream = gs.create('./fixtures/whatsgoingon', { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/whatsgoingon'));
done();
});
});
it('should return only folder name stream from a glob', function(done) {
var folderCount = 0;
var stream = gs.create('./fixtures/whatsgoingon/*/', { cwd: __dirname });
stream.on('error', function(err) {
throw err;
});
stream.on('data', function(file) {
should.exist(file);
should.exist(file.path);
String(join(file.path, '')).should.equal(join(__dirname, './fixtures/whatsgoingon/hey/'));
folderCount++;
});
stream.on('end', function() {
folderCount.should.equal(1);
done();
});
});
it('should return a file name stream from a glob', function(done) {
var stream = gs.create('./fixtures/*.coffee', { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
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) {
this.pause();
setTimeout(function() {
this.push(data);
cb();
this.resume();
}.bind(this), 500);
}));
var count = 0;
should.exist(stream);
stream.on('error', function(err) {
throw err;
});
wrapper.on('data', function() {
count++;
});
wrapper.on('end', function() {
count.should.equal(2);
done();
});
});
it('should return a correctly ordered file name stream for two globs and specified base', function(done) {
var baseDir = join(__dirname, './fixtures');
var globArray = [
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js',
];
var stream = gs.create(globArray, { cwd: baseDir, base: baseDir });
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.base);
file.base.should.equal(baseDir);
});
stream.on('end', function() {
done();
});
});
it('should return a correctly ordered file name stream for two globs and cwdbase', function(done) {
var baseDir = join(__dirname, './fixtures');
var globArray = [
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js',
];
var stream = gs.create(globArray, { cwd: baseDir, cwdbase: true });
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.base);
file.base.should.equal(baseDir);
});
stream.on('end', function() {
done();
});
});
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 });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
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 });
stream2.pipe(stream);
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
it('should return a file name stream from a direct path', function(done) {
var stream = gs.create('./fixtures/test.coffee', { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
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() {
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() {
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 });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(file.path).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
stream.pause();
setTimeout(function() {
stream.resume();
}, 1000);
});
it('should not fuck up direct paths with no cwd', function(done) {
var stream = gs.create(join(__dirname, './fixtures/test.coffee'));
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(process.cwd());
String(file.base).should.equal(join(__dirname, './fixtures/'));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
it('should return a correctly ordered file name stream for three globs with globstars', function(done) {
var globArray = [
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 });
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(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();
});
});
it('should return a correctly ordered file name stream for two globs', function(done) {
var globArray = [
join(__dirname, './fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt'),
join(__dirname, './fixtures/test.coffee'),
join(__dirname, './fixtures/whatsgoingon/test.js'),
];
var stream = gs.create(globArray, { 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);
files[0].path.should.equal(globArray[0]);
files[1].path.should.equal(globArray[1]);
files[2].path.should.equal(globArray[2]);
done();
});
});
it('should return a correctly ordered file name stream for two globs and custom base', function(done) {
var baseDir = join(__dirname, './fixtures');
var globArray = [
'./whatsgoingon/hey/isaidhey/whatsgoingon/test.txt',
'./test.coffee',
'./whatsgoingon/test.js',
];
var stream = gs.create(globArray, { cwd: baseDir, cwdbase: true });
stream.on('error', done);
stream.on('data', function(file) {
should.exist(file);
should.exist(file.base);
file.base.should.equal(baseDir);
});
stream.on('end', function() {
done();
});
});
it('should return a input stream for multiple globs, with negation (globbing)', function(done) {
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
var globArray = [
join(__dirname, './fixtures/stuff/*.dmc'),
'!' + join(__dirname, './fixtures/stuff/test.dmc'),
];
var stream = gs.create(globArray);
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(1);
files[0].path.should.equal(expectedPath);
done();
});
});
it('should return a input stream for multiple globs, with negation (direct)', function(done) {
var expectedPath = join(__dirname, './fixtures/stuff/run.dmc');
var globArray = [
join(__dirname, './fixtures/stuff/run.dmc'),
'!' + join(__dirname, './fixtures/stuff/test.dmc'),
];
var stream = gs.create(globArray);
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(1);
files[0].path.should.equal(expectedPath);
done();
});
});
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'));
stream2.pipe(stream);
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(2);
done();
});
});
it('should return a file name stream with negation from a glob', function(done) {
var stream = gs.create(['./fixtures/**/*.js', '!./**/test.js'], { cwd: __dirname });
should.exist(stream);
stream.on('error', function(err) {
throw err;
});
stream.on('data', function(file) {
throw new Error('file ' + file.path + ' should have been negated');
});
stream.on('end', function() {
done();
});
});
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 });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
it('should respect the globs array order', function(done) {
var stream = gs.create(['./fixtures/stuff/*', '!./fixtures/stuff/*.dmc', './fixtures/stuff/run.dmc'], { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures', 'stuff' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/stuff/run.dmc'));
done();
});
});
it('should ignore leading negative globs', function(done) {
var stream = gs.create(['!./fixtures/stuff/*.dmc', './fixtures/stuff/run.dmc'], { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures', 'stuff' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/stuff/run.dmc'));
done();
});
});
it('should handle RegExps as negative matchers', function(done) {
var stream = gs.create(['./fixtures/stuff/*.dmc', /run/], { cwd: __dirname });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures', 'stuff' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/stuff/run.dmc'));
done();
});
});
it('should throw on invalid glob argument', function() {
gs.create.bind(gs, 42, { cwd: __dirname }).should.throw(/Invalid glob .* 0/);
gs.create.bind(gs, ['.', 42], { cwd: __dirname }).should.throw(/Invalid glob .* 1/);
});
it('should throw on missing positive glob', function() {
gs.create.bind(gs, '!c', { cwd: __dirname }).should.throw(/Missing positive glob/);
gs.create.bind(gs, ['!a', '!b'], { cwd: __dirname }).should.throw(/Missing positive glob/);
});
it('should emit error on singular glob when file not found', function(done) {
var stream = gs.create('notfound');
should.exist(stream);
stream.on('error', function(err) {
err.should.match(/File not found with singular glob/);
done();
});
});
it('should emit error when a glob in multiple globs not found', function(done) {
var stream = gs.create(['notfound', './fixtures/whatsgoingon'], { cwd: __dirname });
should.exist(stream);
stream.on('error', function(err) {
err.should.match(/File not found with singular glob/);
done();
});
});
it('should resolve relative paths when root option is given', function(done) {
var stream = gs.create('./fixtures/test.coffee', { cwd: __dirname, root: __dirname + '/fixtures' });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
it('should resolve absolute paths when root option is given', function(done) {
var stream = gs.create('/test.coffee', { cwd: __dirname, root: __dirname + '/fixtures' });
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(__dirname);
String(file.base).should.equal(join(__dirname, 'fixtures' + sep));
String(join(file.path,'')).should.equal(join(__dirname, './fixtures/test.coffee'));
done();
});
});
it('should not emit error on glob containing {} when not found', function(done) {
var stream = gs.create('notfound{a,b}');
should.exist(stream);
stream.on('error', function() {
throw new Error('Error was emitted');
});
stream.resume();
stream.once('end', done);
});
it('should not emit error on singular glob when allowEmpty is true', function(done) {
var stream = gs.create('notfound', { allowEmpty: true });
should.exist(stream);
stream.on('error', function() {
throw new Error('Error was emitted');
});
stream.resume();
stream.once('end', done);
});
it('should pass options to through2',function(done) {
var stream = gs.create(['./fixtures/stuff/run.dmc'], { cwd: __dirname, objectMode: false });
should.exist(stream);
stream.on('error', function(err) {
err.should.match(/Invalid non-string\/buffer chunk/);
done();
});
});
});
});