pax_global_header00006660000000000000000000000064130543627200014514gustar00rootroot0000000000000052 comment=8210a3c95cabc032088b1a0ff47ccbeb2f83ec52 glob-stream-6.1.0/000077500000000000000000000000001305436272000137345ustar00rootroot00000000000000glob-stream-6.1.0/.editorconfig000066400000000000000000000003051305436272000164070ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false glob-stream-6.1.0/.eslintignore000066400000000000000000000000171305436272000164350ustar00rootroot00000000000000test/fixtures/ glob-stream-6.1.0/.eslintrc000066400000000000000000000000301305436272000155510ustar00rootroot00000000000000{ "extends": "gulp" } glob-stream-6.1.0/.gitignore000066400000000000000000000010311305436272000157170ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules .DS_Store glob-stream-6.1.0/.jscsrc000066400000000000000000000000271305436272000152230ustar00rootroot00000000000000{ "preset": "gulp" } glob-stream-6.1.0/.travis.yml000066400000000000000000000001551305436272000160460ustar00rootroot00000000000000language: node_js node_js: - '6' - '5' - '4' - '0.12' - '0.10' after_script: - npm run coveralls glob-stream-6.1.0/LICENSE000077500000000000000000000022211305436272000147410ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015-2017 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-6.1.0/README.md000066400000000000000000000106101305436272000152110ustar00rootroot00000000000000

# glob-stream [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] A [Readable Stream][readable-stream-url] interface over [node-glob][node-glob-url]. ## Usage ```javascript var gs = require('glob-stream'); var readable = gs('./files/**/*.coffee', { /* options */ }); var writable = /* your WriteableStream */ readable.pipe(writable); ``` You can pass any combination of glob strings. One caveat is that you cannot __only__ pass a negative glob, you must give it at least one positive glob so it knows where to start. If given a non-glob path (also referred to as a singular glob), only one file will be emitted. If given a singular glob and no files match, an error is emitted (see also [`options.allowEmpty`][allow-empty-url]). ## API ### `globStream(globs, options)` Takes a glob string or an array of glob strings as the first argument and an options object as the second. Returns a stream of objects that contain `cwd`, `base` and `path` properties. #### Options ##### `options.allowEmpty` Whether or not to error upon an empty singular glob. Type: `Boolean` Default: `false` (error upon no match) ##### `options.dot` Whether or not to treat dotfiles as regular files. This is passed through to [node-glob][node-glob-url]. Type: `Boolean` Default: `false` ##### `options.silent` Whether or not to suppress warnings on stderr from [node-glob][node-glob-url]. This is passed through to [node-glob][node-glob-url]. Type: `Boolean` Default: `true` ##### `options.cwd` The current working directory that the glob is resolved against. Type: `String` Default: `process.cwd()` ##### `options.root` The root path that the glob is resolved against. __Note: This is never passed to [node-glob][node-glob-url] because it is pre-resolved against your paths.__ Type: `String` Default: `undefined` (use the filesystem root) ##### `options.base` The absolute segment of the glob path that isn't a glob. This value is attached to each glob object and is useful for relative pathing. Type: `String` Default: The absolute path segement before a glob starts (see [glob-parent][glob-parent-url]) ##### `options.cwdbase` Whether or not the `cwd` and `base` should be the same. Type: `Boolean` Default: `false` ##### `options.uniqueBy` Filters stream to remove duplicates based on the string property name or the result of function. When using a function, the function receives the streamed data (objects containing `cwd`, `base`, `path` properties) to compare against. Type: `String` or `Function` Default: `'path'` ##### other Any glob-related options are documented in [node-glob][node-glob-url]. Those options are forwarded verbatim, with the exception of `root` and `ignore`. `root` is pre-resolved and `ignore` is joined with all negative globs. #### Globbing & Negation ```js var stream = gs(['./**/*.js', '!./node_modules/**/*']); ``` Globs are executed in order, so negations should follow positive globs. For example: The following would __not__ exclude any files: ```js gs(['!b*.js', '*.js']) ``` However, this would exclude all files that started with `b`: ```js gs(['*.js', '!b*.js']) ``` ## License MIT [node-glob-url]: https://github.com/isaacs/node-glob [glob-parent-url]: https://github.com/es128/glob-parent [allow-empty-url]: #optionsallowempty [readable-stream-url]: https://nodejs.org/api/stream.html#stream_readable_streams [downloads-image]: http://img.shields.io/npm/dm/glob-stream.svg [npm-url]: https://www.npmjs.com/package/glob-stream [npm-image]: http://img.shields.io/npm/v/glob-stream.svg [travis-url]: https://travis-ci.org/gulpjs/glob-stream [travis-image]: http://img.shields.io/travis/gulpjs/glob-stream.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/glob-stream [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/glob-stream.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/glob-stream [coveralls-image]: http://img.shields.io/coveralls/gulpjs/glob-stream.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg glob-stream-6.1.0/appveyor.yml000066400000000000000000000007211305436272000163240ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "5" - nodejs_version: "6" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" glob-stream-6.1.0/index.js000066400000000000000000000044751305436272000154130ustar00rootroot00000000000000'use strict'; var Combine = require('ordered-read-streams'); var unique = require('unique-stream'); var pumpify = require('pumpify'); var isNegatedGlob = require('is-negated-glob'); var extend = require('extend'); var GlobStream = require('./readable'); function globStream(globs, opt) { if (!opt) { opt = {}; } var ourOpt = extend({}, opt); var ignore = ourOpt.ignore; ourOpt.cwd = typeof ourOpt.cwd === 'string' ? ourOpt.cwd : process.cwd(); ourOpt.dot = typeof ourOpt.dot === 'boolean' ? ourOpt.dot : false; ourOpt.silent = typeof ourOpt.silent === 'boolean' ? ourOpt.silent : true; ourOpt.cwdbase = typeof ourOpt.cwdbase === 'boolean' ? ourOpt.cwdbase : false; ourOpt.uniqueBy = typeof ourOpt.uniqueBy === 'string' || typeof ourOpt.uniqueBy === 'function' ? ourOpt.uniqueBy : 'path'; if (ourOpt.cwdbase) { ourOpt.base = ourOpt.cwd; } // Normalize string `ignore` to array if (typeof ignore === 'string') { ignore = [ignore]; } // Ensure `ignore` is an array if (!Array.isArray(ignore)) { ignore = []; } // Only one glob no need to aggregate if (!Array.isArray(globs)) { globs = [globs]; } var positives = []; var negatives = []; globs.forEach(sortGlobs); function sortGlobs(globString, index) { if (typeof globString !== 'string') { throw new Error('Invalid glob at index ' + index); } var glob = isNegatedGlob(globString); var globArray = glob.negated ? negatives : positives; globArray.push({ index: index, glob: glob.pattern, }); } if (positives.length === 0) { throw new Error('Missing positive glob'); } // 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(ourOpt.uniqueBy); return pumpify.obj(aggregate, uniqueStream); function streamFromPositive(positive) { var negativeGlobs = negatives .filter(indexGreaterThan(positive.index)) .map(toGlob) .concat(ignore); return new GlobStream(positive.glob, negativeGlobs, ourOpt); } } function indexGreaterThan(index) { return function(obj) { return obj.index > index; }; } function toGlob(obj) { return obj.glob; } module.exports = globStream; glob-stream-6.1.0/package.json000066400000000000000000000026521305436272000162270ustar00rootroot00000000000000{ "name": "glob-stream", "version": "6.1.0", "description": "A Readable Stream interface over node-glob.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Eric Schoffstall ", "Blaine Bublitz " ], "repository": "gulpjs/glob-stream", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "index.js", "readable.js", "LICENSE" ], "scripts": { "lint": "eslint . && jscs index.js readable.js test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "extend": "^3.0.0", "glob": "^7.1.1", "glob-parent": "^3.1.0", "is-negated-glob": "^1.0.0", "ordered-read-streams": "^1.0.0", "pumpify": "^1.3.5", "readable-stream": "^2.1.5", "remove-trailing-separator": "^1.0.1", "to-absolute-glob": "^2.0.0", "unique-stream": "^2.0.2" }, "devDependencies": { "eslint": "^1.10.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.19.0", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.4.0", "jscs-preset-gulp": "^1.0.0", "mississippi": "^1.2.0", "mocha": "^2.4.5" }, "keywords": [ "glob", "stream", "gulp", "readable", "fs", "files" ] } glob-stream-6.1.0/readable.js000066400000000000000000000051741305436272000160400ustar00rootroot00000000000000'use strict'; var inherits = require('util').inherits; var glob = require('glob'); var extend = require('extend'); var Readable = require('readable-stream').Readable; var globParent = require('glob-parent'); var toAbsoluteGlob = require('to-absolute-glob'); var removeTrailingSeparator = require('remove-trailing-separator'); var globErrMessage1 = 'File not found with singular glob: '; var globErrMessage2 = ' (if this was purposeful, use `allowEmpty` option)'; function getBasePath(ourGlob, opt) { return globParent(toAbsoluteGlob(ourGlob, opt)); } 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 GlobStream(ourGlob, negatives, opt) { if (!(this instanceof GlobStream)) { return new GlobStream(ourGlob, negatives, opt); } var ourOpt = extend({}, opt); Readable.call(this, { objectMode: true, highWaterMark: ourOpt.highWaterMark || 16, }); // Delete `highWaterMark` after inheriting from Readable delete ourOpt.highWaterMark; var self = this; function resolveNegatives(negative) { return toAbsoluteGlob(negative, ourOpt); } var ourNegatives = negatives.map(resolveNegatives); ourOpt.ignore = ourNegatives; var cwd = ourOpt.cwd; var allowEmpty = ourOpt.allowEmpty || false; // Extract base path from glob var basePath = ourOpt.base || getBasePath(ourGlob, ourOpt); // Remove path relativity to make globs make sense ourGlob = toAbsoluteGlob(ourGlob, ourOpt); // Delete `root` after all resolving done delete ourOpt.root; var globber = new glob.Glob(ourGlob, ourOpt); this._globber = globber; var found = false; globber.on('match', function(filepath) { found = true; var obj = { cwd: cwd, base: basePath, path: removeTrailingSeparator(filepath), }; if (!self.push(obj)) { globber.pause(); } }); globber.once('end', function() { if (allowEmpty !== true && !found && globIsSingular(globber)) { var err = new Error(globErrMessage1 + ourGlob + globErrMessage2); return self.destroy(err); } self.push(null); }); function onError(err) { self.destroy(err); } globber.once('error', onError); } inherits(GlobStream, Readable); GlobStream.prototype._read = function() { this._globber.resume(); }; GlobStream.prototype.destroy = function(err) { var self = this; this._globber.abort(); process.nextTick(function() { if (err) { self.emit('error', err); } self.emit('close'); }); }; module.exports = GlobStream; glob-stream-6.1.0/test/000077500000000000000000000000001305436272000147135ustar00rootroot00000000000000glob-stream-6.1.0/test/.eslintrc000066400000000000000000000000351305436272000165350ustar00rootroot00000000000000{ "extends": "gulp/test" } glob-stream-6.1.0/test/fixtures/000077500000000000000000000000001305436272000165645ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/.swag000066400000000000000000000000031305436272000175170ustar00rootroot00000000000000yupglob-stream-6.1.0/test/fixtures/has (parens)/000077500000000000000000000000001305436272000207315ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/has (parens)/test.dmc000066400000000000000000000000161305436272000223720ustar00rootroot00000000000000this is a testglob-stream-6.1.0/test/fixtures/stuff/000077500000000000000000000000001305436272000177135ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/stuff/run.dmc000066400000000000000000000000001305436272000211720ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/stuff/test.dmc000066400000000000000000000000001305436272000213450ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/test.coffee000066400000000000000000000000161305436272000207110ustar00rootroot00000000000000this is a testglob-stream-6.1.0/test/fixtures/whatsgoingon/000077500000000000000000000000001305436272000212735ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/whatsgoingon/hey/000077500000000000000000000000001305436272000220605ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/whatsgoingon/hey/isaidhey/000077500000000000000000000000001305436272000236575ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/000077500000000000000000000000001305436272000263665ustar00rootroot00000000000000glob-stream-6.1.0/test/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt000066400000000000000000000000221305436272000301000ustar00rootroot00000000000000Heyyyayyyayyyayyyyglob-stream-6.1.0/test/fixtures/whatsgoingon/test.js000066400000000000000000000000041305436272000226020ustar00rootroot00000000000000whatglob-stream-6.1.0/test/index.js000066400000000000000000000457251305436272000163750ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var miss = require('mississippi'); var globStream = require('../'); function deWindows(p) { return p.replace(/\\/g, '/'); } var pipe = miss.pipe; var concat = miss.concat; var through2 = miss.through; var dir = deWindows(__dirname); describe('glob-stream', function() { it('streams a single object when given a directory path', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/whatsgoingon', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/whatsgoingon', { cwd: dir }), concat(assert), ], done); }); it('streams a single object when given a file path', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/test.coffee', { cwd: dir }), concat(assert), ], done); }); it('streams only objects with directory paths when given a directory glob', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/whatsgoingon', path: dir + '/fixtures/whatsgoingon/hey', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/whatsgoingon/*/', { cwd: dir }), concat(assert), ], done); }); it('streams only objects with file paths from a non-directory glob', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/*.coffee', { cwd: dir }), concat(assert), ], done); }); it('properly handles ( ) in cwd path', function(done) { var cwd = dir + '/fixtures/has (parens)'; var expected = { cwd: cwd, base: cwd, path: cwd + '/test.dmc', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('*.dmc', { cwd: cwd }), concat(assert), ], done); }); it('sets the correct base when ( ) in glob', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/has (parens)', path: dir + '/fixtures/has (parens)/test.dmc', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/has (parens)/*.dmc', { cwd: dir }), concat(assert), ], done); }); it('finds files in paths that contain ( ) when they match the glob', function(done) { var expected = [ { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/has (parens)/test.dmc', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/stuff/run.dmc', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/stuff/test.dmc', }, ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(3); expect(pathObjs).toInclude(expected[0]); expect(pathObjs).toInclude(expected[1]); expect(pathObjs).toInclude(expected[2]); } pipe([ globStream('./fixtures/**/*.dmc', { cwd: dir }), concat(assert), ], done); }); // TODO: This doesn't seem to be testing that backpressure is respected it('respects backpressure and stream state', function(done) { var delayStream = through2.obj(function(data, enc, cb) { var self = this; self.pause(); setTimeout(function() { cb(null, data); self.resume(); }, 500); }); function assert(pathObjs) { expect(pathObjs.length).toEqual(2); } pipe([ globStream('./fixtures/stuff/*.dmc', { cwd: dir }), delayStream, concat(assert), ], done); }); it('properly orders objects when given multiple paths and specified base', function(done) { var base = dir + '/fixtures'; var expected = [ { cwd: base, base: base, path: base + '/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', }, { cwd: base, base: base, path: base + '/test.coffee', }, { cwd: base, base: base, path: base + '/whatsgoingon/test.js', }, ]; var paths = [ './whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', './test.coffee', './whatsgoingon/test.js', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(3); expect(pathObjs).toEqual(expected); } pipe([ globStream(paths, { cwd: base, base: base }), concat(assert), ], done); }); it('properly orders objects when given multiple paths and cwdbase', function(done) { var base = dir + '/fixtures'; var expected = [ { cwd: base, base: base, path: base + '/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', }, { cwd: base, base: base, path: base + '/test.coffee', }, { cwd: base, base: base, path: base + '/whatsgoingon/test.js', }, ]; var paths = [ './whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', './test.coffee', './whatsgoingon/test.js', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(3); expect(pathObjs).toEqual(expected); } pipe([ globStream(paths, { cwd: base, cwdbase: true }), concat(assert), ], done); }); it('properly orders objects when given multiple globs with globstars', function(done) { var expected = [ { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/whatsgoingon/test.js', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/has (parens)/test.dmc', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/stuff/test.dmc', }, ]; var globs = [ './fixtures/**/test.txt', './fixtures/**/test.coffee', './fixtures/**/test.js', './fixtures/**/test.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(5); expect(pathObjs).toEqual(expected); } pipe([ globStream(globs, { cwd: dir }), concat(assert), ], done); }); it('properly orders objects when given multiple absolute paths and no cwd', function(done) { var expected = [ { cwd: process.cwd(), base: dir + '/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon', path: dir + '/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', }, { cwd: process.cwd(), base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }, { cwd: process.cwd(), base: dir + '/fixtures/whatsgoingon', path: dir + '/fixtures/whatsgoingon/test.js', }, ]; var paths = [ dir + '/fixtures/whatsgoingon/hey/isaidhey/whatsgoingon/test.txt', dir + '/fixtures/test.coffee', dir + '/fixtures/whatsgoingon/test.js', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(3); expect(pathObjs).toEqual(expected); } pipe([ globStream(paths), concat(assert), ], done); }); it('removes duplicate objects from the stream using default (path) filter', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(['./fixtures/test.coffee', './fixtures/*.coffee'], { cwd: dir }), concat(assert), ], done); }); it('removes duplicate objects from the stream using custom string filter', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(['./fixtures/stuff/run.dmc', './fixtures/stuff/test.dmc'], { cwd: dir, uniqueBy: 'base' }), concat(assert), ], done); }); it('removes duplicate objects from the stream using custom function filter', function(done) { var expected = [ { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }, { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/test.dmc', }, ]; var uniqueBy = function(data) { return data.path; }; function assert(pathObjs) { expect(pathObjs.length).toEqual(2); expect(pathObjs).toInclude(expected[0]); expect(pathObjs).toInclude(expected[1]); } pipe([ globStream('./fixtures/stuff/*.dmc', { cwd: dir, uniqueBy: uniqueBy }), concat(assert), ], done); }); it('ignores dotfiles without dot option', function(done) { function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream('./fixtures/*swag', { cwd: dir }), concat(assert), ], done); }); it('finds dotfiles with dot option', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/.swag', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/*swag', { cwd: dir, dot: true }), concat(assert), ], done); }); it('removes dotfiles that match negative globs with dot option', function(done) { function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream(['./fixtures/*swag', '!./fixtures/**'], { cwd: dir, dot: true }), concat(assert), ], done); }); it('respects pause/resume', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } var stream = globStream('./fixtures/test.coffee', { cwd: dir }); stream.pause(); pipe([ stream, concat(assert), ], done); setTimeout(function() { stream.resume(); }, 1000); }); it('works with direct paths and no cwd', function(done) { var expected = { cwd: process.cwd(), base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(dir + '/fixtures/test.coffee'), concat(assert), ], done); }); it('supports negative globs', function(done) { var expected = { cwd: process.cwd(), base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; var globs = [ dir + '/fixtures/stuff/*.dmc', '!' + dir + '/fixtures/stuff/*test.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(globs), concat(assert), ], done); }); it('supports negative file paths', function(done) { var expected = { cwd: process.cwd(), base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; var paths = [ dir + '/fixtures/stuff/*.dmc', '!' + dir + '/fixtures/stuff/test.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(paths), concat(assert), ], done); }); it('does not error when a negative glob removes all matches from a positive glob', function(done) { function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream(['./fixtures/**/*.js', '!./**/test.js'], { cwd: dir }), concat(assert), ], done); }); it('respects order of negative globs', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; var globs = [ './fixtures/stuff/*', '!./fixtures/stuff/*.dmc', './fixtures/stuff/run.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(globs, { cwd: dir }), concat(assert), ], done); }); it('ignores leading negative globs', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; var globs = [ '!./fixtures/stuff/*.dmc', './fixtures/stuff/run.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream(globs, { cwd: dir }), concat(assert), ], done); }); it('throws on invalid glob argument', function(done) { expect(globStream.bind(globStream, 42, { cwd: dir })).toThrow(/Invalid glob .* 0/); expect(globStream.bind(globStream, ['.', 42], { cwd: dir })).toThrow(/Invalid glob .* 1/); done(); }); it('throws on missing positive glob', function(done) { expect(globStream.bind(globStream, '!c', { cwd: dir })).toThrow(/Missing positive glob/); expect(globStream.bind(globStream, ['!a', '!b'], { cwd: dir })).toThrow(/Missing positive glob/); done(); }); it('emits an error when file not found on singular path', function(done) { function assert(err) { expect(err).toMatch(/File not found with singular glob/); done(); } pipe([ globStream('notfound'), concat(), ], assert); }); it('does not emit an error when file not found on glob containing {}', function(done) { function assert(err) { expect(err).toNotExist(); done(); } pipe([ globStream('notfound{a,b}'), concat(), ], assert); }); it('does not emit an error on singular path when allowEmpty is true', function(done) { function assert(err) { expect(err).toNotExist(); done(); } pipe([ globStream('notfound', { allowEmpty: true }), concat(), ], assert); }); it('emits an error when a singular path in multiple paths not found', function(done) { function assert(err) { expect(err).toMatch(/File not found with singular glob/); done(); } pipe([ globStream(['notfound', './fixtures/whatsgoingon'], { cwd: dir }), concat(), ], assert); }); it('emits an error when a singular path in multiple paths/globs not found', function(done) { function assert(err) { expect(err).toMatch(/File not found with singular glob/); done(); } pipe([ globStream(['notfound', './fixtures/*.coffee'], { cwd: dir }), concat(), ], assert); }); it('resolves absolute paths when root option is given', function(done) { var expected = { cwd: process.cwd(), base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('/test.coffee', { root: dir + '/fixtures' }), concat(assert), ], done); }); }); describe('options', function() { it('avoids mutation of options', function(done) { var defaultedOpts = { cwd: process.cwd(), dot: false, silent: true, nonull: false, cwdbase: false, }; var opts = {}; var stream = globStream(dir + '/fixtures/stuff/run.dmc', opts); expect(Object.keys(opts).length).toEqual(0); expect(opts).toNotEqual(defaultedOpts); pipe([ stream, concat(), ], done); }); describe('silent', function() { it('accepts a boolean', function(done) { pipe([ globStream(dir + '/fixtures/stuff/run.dmc', { silent: false }), concat(), ], done); }); }); describe('nonull', function() { it('accepts a boolean', function(done) { pipe([ globStream('notfound{a,b}', { nonull: true }), concat(), ], done); }); it('does not have any effect on our results', function(done) { function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream('notfound{a,b}', { nonull: true }), concat(assert), ], done); }); }); describe('ignore', function() { it('accepts a string (in addition to array)', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/stuff/*.dmc', { cwd: dir, ignore: './fixtures/stuff/test.dmc' }), concat(assert), ], done); }); it('supports the ignore option instead of negation', function(done) { var expected = { cwd: dir, base: dir + '/fixtures/stuff', path: dir + '/fixtures/stuff/run.dmc', }; function assert(pathObjs) { expect(pathObjs.length).toEqual(1); expect(pathObjs[0]).toEqual(expected); } pipe([ globStream('./fixtures/stuff/*.dmc', { cwd: dir, ignore: ['./fixtures/stuff/test.dmc'] }), concat(assert), ], done); }); it('supports the ignore option with dot option', function(done) { function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream('./fixtures/*swag', { cwd: dir, dot: true, ignore: ['./fixtures/**'] }), concat(assert), ], done); }); it('merges ignore option and negative globs', function(done) { var globs = [ './fixtures/stuff/*.dmc', '!./fixtures/stuff/test.dmc', ]; function assert(pathObjs) { expect(pathObjs.length).toEqual(0); } pipe([ globStream(globs, { cwd: dir, ignore: ['./fixtures/stuff/run.dmc'] }), concat(assert), ], done); }); }); }); glob-stream-6.1.0/test/readable.js000066400000000000000000000100251305436272000170060ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var miss = require('mississippi'); var stream = require('../readable'); // Need to wrap this to cause node-glob to emit an error var fs = require('fs'); function deWindows(p) { return p.replace(/\\/g, '/'); } var pipe = miss.pipe; var concat = miss.concat; var through = miss.through; var dir = deWindows(__dirname); describe('readable stream', function() { it('emits an error if there are no matches', function(done) { function assert(err) { expect(err.message).toMatch(/^File not found with singular glob/g); done(); } pipe([ stream('notfound', [], { cwd: dir }), concat(), ], assert); }); it('throws an error if you try to write to it', function(done) { var gs = stream('notfound', [], { cwd: dir }); try { gs.write({}); } catch (err) { expect(err).toExist(); done(); } }); it('does not throw an error if you push to it', function(done) { var stub = { cwd: dir, base: dir, path: dir, }; var gs = stream('./fixtures/test.coffee', [], { cwd: dir }); gs.push(stub); function assert(pathObjs) { expect(pathObjs.length).toEqual(2); expect(pathObjs[0]).toEqual(stub); } pipe([ gs, concat(assert), ], done); }); it('accepts a file path', function(done) { var expected = { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/test.coffee', }; function assert(pathObjs) { expect(pathObjs.length).toBe(1); expect(pathObjs[0]).toMatch(expected); } pipe([ stream('./fixtures/test.coffee', [], { cwd: dir }), concat(assert), ], done); }); it('accepts a glob', function(done) { var expected = [ { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/has (parens)/test.dmc', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/stuff/run.dmc', }, { cwd: dir, base: dir + '/fixtures', path: dir + '/fixtures/stuff/test.dmc', }, ]; function assert(pathObjs) { expect(pathObjs.length).toBe(3); expect(pathObjs).toInclude(expected[0]); expect(pathObjs).toInclude(expected[1]); expect(pathObjs).toInclude(expected[2]); } pipe([ stream('./fixtures/**/*.dmc', [], { cwd: dir }), concat(assert), ], done); }); it('pauses the globber upon backpressure', function(done) { var gs = stream('./fixtures/**/*.dmc', [], { cwd: dir, highWaterMark: 1 }); var spy = expect.spyOn(gs._globber, 'pause').andCallThrough(); function waiter(pathObj, _, cb) { setTimeout(function() { cb(null, pathObj); }, 500); } function assert(pathObjs) { expect(pathObjs.length).toEqual(3); expect(spy.calls.length).toEqual(2); spy.restore(); } pipe([ gs, through.obj({ highWaterMark: 1 }, waiter), concat(assert), ], done); }); it('destroys the stream with an error if no match is found', function(done) { var gs = stream('notfound', []); var spy = expect.spyOn(gs, 'destroy').andCallThrough(); function assert(err) { spy.restore(); expect(spy).toHaveBeenCalledWith(err); expect(err).toMatch(/File not found with singular glob/); done(); } pipe([ gs, concat(), ], assert); }); it('destroys the stream if node-glob errors', function(done) { var expectedError = new Error('Stubbed error'); var gs = stream('./fixtures/**/*.dmc', [], { cwd: dir, silent: true }); function stubError(dirpath, cb) { cb(expectedError); } var spy = expect.spyOn(gs, 'destroy').andCallThrough(); var fsStub = expect.spyOn(fs, 'readdir').andCall(stubError); function assert(err) { fsStub.restore(); spy.restore(); expect(spy).toHaveBeenCalledWith(err); expect(err).toBe(expectedError); done(); } pipe([ gs, concat(), ], assert); }); });