function resolveUp(patterns, options) { if (!isValidGlob(patterns)) { throw new Error('resolve-up expects a string or array as the first argument.'); } var opts = extend({fast: true}, options); var dirs = paths(opts).concat(opts.paths || []); var len = dirs.length; var idx = -1; var res = []; while (++idx < len) { opts.cwd = dirs[idx]; if (!opts.cwd) continue; opts.cwd = path.resolve(opts.cwd); var key = opts.cwd + '=' + patterns; if (cache[key]) { res.push.apply(res, cache[key]); } else { var files = resolve(glob.sync(patterns, opts), opts); cache[key] = files; res.push.apply(res, files); } } return unique(res); };
function src(glob, opt) { if (!opt) { opt = {}; } var options = assign({}, opt, { buffer: defaultTo(boolean(opt.buffer), true), read: defaultTo(boolean(opt.read), true), since: date(opt.since), stripBOM: defaultTo(boolean(opt.stripBOM), true), sourcemaps: defaultTo(boolean(opt.sourcemaps), false), passthrough: defaultTo(boolean(opt.passthrough), false), followSymlinks: defaultTo(boolean(opt.followSymlinks), true), }); // Don't pass `read` option on to through2 var read = options.read !== false; options.read = undefined; var inputPass; if (!isValidGlob(glob)) { throw new Error('Invalid glob argument: ' + glob); } var globStream = gs.create(glob, options); var outputStream = globStream .pipe(wrapWithVinylFile(options)); if (options.since != null) { outputStream = outputStream .pipe(filterSince(options.since)); } if (read) { outputStream = outputStream .pipe(getContents(options)); } if (options.passthrough === true) { inputPass = through2.obj(options); outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass)); } if (options.sourcemaps === true) { outputStream = outputStream .pipe(sourcemaps.init({ loadMaps: true })); } globStream.on('error', outputStream.emit.bind(outputStream, 'error')); return outputStream; }
function src(glob, opt) { var options = assign({ read: true, buffer: true, stripBOM: true, sourcemaps: false, passthrough: false, followSymlinks: true, }, opt); // Don't pass `read` option on to through2 var read = options.read !== false; options.read = undefined; var inputPass; if (!isValidGlob(glob)) { throw new Error('Invalid glob argument: ' + glob); } var globStream = gs.create(glob, options); var outputStream = globStream .pipe(resolveSymlinks(options)) .pipe(through2.obj(options, createFile)); if (options.since != null) { outputStream = outputStream .pipe(filterSince(options.since)); } if (read) { outputStream = outputStream .pipe(getContents(options)); } if (options.passthrough === true) { inputPass = through2.obj(options); outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass)); } if (options.sourcemaps === true) { outputStream = outputStream .pipe(sourcemaps.init({ loadMaps: true })); } globStream.on('error', outputStream.emit.bind(outputStream, 'error')); return outputStream; }
module.exports = function(patterns, config, cb) { if (typeof config === 'function') { cb = config; config = {}; } if (typeof cb !== 'function') { throw new Error('expected a callback function.'); } if (!isValidGlob(patterns)) { cb(new Error('invalid glob pattern: ' + patterns)); return; } // shallow clone options var options = Object.assign({cwd: ''}, config); options.cwd = utils.cwd(options); patterns = utils.arrayify(patterns); if (!hasGlob(patterns)) { patterns = utils.getPaths(patterns, options); cb(null, patterns); return; } var sifted = utils.sift(patterns, options); var Glob = glob.Glob; var cache = []; var res; function updateOptions(inclusive) { return utils.setIgnores(options, sifted.excludes, inclusive.index); } reduce(sifted.includes, [], function(acc, include, next) { var opts = updateOptions(include); if (acc.glob) { opts.cache = acc.glob.cache; } res = new Glob(include.pattern, opts, function(err, files) { if (err) { next(err); return; } cache.push(res.cache); acc = acc.concat(files); acc.glob = res; next(null, acc); }); }, function(err, files) { if (err) { cb(err); return; } Object.defineProperty(files, 'cache', { configurable: true, get: function() { return utils.createCache(cache); } }); delete files.glob; cb(null, files); }); };