Comparing version 4.0.0 to 4.1.0
71
index.js
@@ -9,46 +9,39 @@ 'use strict'; | ||
function sortPatterns(patterns) { | ||
var globP = pify(glob, Promise).bind(glob); | ||
function isNegative(pattern) { | ||
return pattern[0] === '!'; | ||
} | ||
function generateGlobTasks(patterns, opts) { | ||
var globTasks = []; | ||
patterns = arrify(patterns); | ||
opts = objectAssign({ignore: []}, opts); | ||
var positives = []; | ||
var negatives = []; | ||
patterns.forEach(function (pattern, i) { | ||
if (isNegative(pattern)) { | ||
return; | ||
} | ||
patterns.forEach(function (pattern, index) { | ||
var isNegative = pattern[0] === '!'; | ||
(isNegative ? negatives : positives).push({ | ||
index: index, | ||
pattern: isNegative ? pattern.slice(1) : pattern | ||
var ignore = patterns.slice(i).filter(isNegative).map(function (pattern) { | ||
return pattern.slice(1); | ||
}); | ||
}); | ||
return { | ||
positives: positives, | ||
negatives: negatives | ||
}; | ||
} | ||
function setIgnore(opts, negatives, positiveIndex) { | ||
opts = objectAssign({}, opts); | ||
var negativePatterns = negatives.filter(function (negative) { | ||
return negative.index > positiveIndex; | ||
}).map(function (negative) { | ||
return negative.pattern; | ||
globTasks.push({ | ||
pattern: pattern, | ||
opts: objectAssign({}, opts, { | ||
ignore: opts.ignore.concat(ignore) | ||
}) | ||
}); | ||
}); | ||
opts.ignore = (opts.ignore || []).concat(negativePatterns); | ||
return opts; | ||
return globTasks; | ||
} | ||
module.exports = function (patterns, opts) { | ||
var sortedPatterns = sortPatterns(patterns); | ||
opts = opts || {}; | ||
var globTasks = generateGlobTasks(patterns, opts); | ||
if (sortedPatterns.positives.length === 0) { | ||
return Promise.resolve([]); | ||
} | ||
return Promise.all(sortedPatterns.positives.map(function (positive) { | ||
var globOpts = setIgnore(opts, sortedPatterns.negatives, positive.index); | ||
return pify(glob, Promise)(positive.pattern, globOpts); | ||
return Promise.all(globTasks.map(function (task) { | ||
return globP(task.pattern, task.opts); | ||
})).then(function (paths) { | ||
@@ -60,11 +53,9 @@ return arrayUnion.apply(null, paths); | ||
module.exports.sync = function (patterns, opts) { | ||
var sortedPatterns = sortPatterns(patterns); | ||
var globTasks = generateGlobTasks(patterns, opts); | ||
if (sortedPatterns.positives.length === 0) { | ||
return []; | ||
} | ||
return sortedPatterns.positives.reduce(function (ret, positive) { | ||
return arrayUnion(ret, glob.sync(positive.pattern, setIgnore(opts, sortedPatterns.negatives, positive.index))); | ||
return globTasks.reduce(function (matches, task) { | ||
return arrayUnion(matches, glob.sync(task.pattern, task.opts)); | ||
}, []); | ||
}; | ||
module.exports.generateGlobTasks = generateGlobTasks; |
{ | ||
"name": "globby", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Extends `glob` with support for multiple patterns and exposes a Promise API", | ||
@@ -65,3 +65,3 @@ "license": "MIT", | ||
"globby": "sindresorhus/globby#master", | ||
"matcha": "^0.6.0", | ||
"matcha": "^0.7.0", | ||
"mocha": "*", | ||
@@ -68,0 +68,0 @@ "rimraf": "^2.2.8", |
@@ -35,3 +35,3 @@ # globby [![Build Status](https://travis-ci.org/sindresorhus/globby.svg?branch=master)](https://travis-ci.org/sindresorhus/globby) | ||
Returns a promise that resolves to an array of matching paths. | ||
Returns a Promise for an array of matching paths. | ||
@@ -42,5 +42,9 @@ ### globby.sync(patterns, [options]) | ||
### globby.generateGlobTasks(patterns, [options]) | ||
Returns an array of objects in the format `{ pattern: string, opts: Object }`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-glob). This is useful for other globbing-related packages. | ||
#### patterns | ||
Type: `string`, `array` | ||
Type: `string`, `Array` | ||
@@ -51,3 +55,3 @@ See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). | ||
Type: `object` | ||
Type: `Object` | ||
@@ -67,3 +71,3 @@ See the `node-glob` [options](https://github.com/isaacs/node-glob#options). | ||
[Various patterns and expected matches](https://github.com/sindresorhus/multimatch/blob/master/test.js). | ||
[Various patterns and expected matches.](https://github.com/sindresorhus/multimatch/blob/master/test.js) | ||
@@ -73,4 +77,5 @@ | ||
- [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem. | ||
- [glob-stream](https://github.com/wearefractal/glob-stream) - Streaming alternative. | ||
- [multimatch](https://github.com/sindresorhus/multimatch) - Match against a list instead of the filesystem | ||
- [glob-stream](https://github.com/wearefractal/glob-stream) - Streaming alternative | ||
- [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching | ||
@@ -80,2 +85,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
81
5916
46