Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit 607ded0

Browse files
authored
Merge pull request #11 from cjohansen/master
Bring tests back to life and reduce dependencies
2 parents 003bac5 + ebdc8b2 commit 607ded0

File tree

7 files changed

+5937
-147
lines changed

7 files changed

+5937
-147
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- "0.10"
5-
- "0.12"
6-
- "4"
7-
- "5"
4+
- "6"
5+
- "8"
86
before_install:
97
- npm i -g npm

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
environment:
22
matrix:
3-
- nodejs_version: "0.10"
4-
- nodejs_version: "0.12"
5-
- nodejs_version: "4"
6-
- nodejs_version: "5"
3+
- nodejs_version: "6"
4+
- nodejs_version: "8"
75

86
install:
97
- ps: Install-Product node $env:nodejs_version

buster.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/multi-glob.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
var glob = require("glob");
2-
var async = require("async");
3-
var _ = require("lodash");
2+
3+
exports._glob = glob;
4+
5+
function uniq(xs) {
6+
return xs.reduce((unique, x) => {
7+
return unique.indexOf(x) < 0 ? unique.concat(x) : unique;
8+
}, []);
9+
}
10+
11+
function flatten(xs) {
12+
return xs.reduce((flattened, x) => {
13+
return flattened.concat(Array.isArray(x) ? flatten(x) : x);
14+
}, []);
15+
}
416

517
function array(arr) {
618
return Array.isArray(arr) ? arr : [arr];
719
}
820

921
function resolveGlobs(patterns, options) {
1022
options = options || {};
11-
return array(patterns).reduce(function (fns, pattern) {
12-
fns.push(function (done) {
13-
glob(pattern, options, function (err, matches) {
14-
if (!err && options.strict && matches.length === 0) {
15-
done(new Error("'" + pattern + "' matched no files"));
16-
} else {
17-
done(err, matches);
18-
}
23+
return Promise.all(
24+
array(patterns).map(pattern => new Promise((resolve, reject) => {
25+
exports._glob(pattern, options, (err, matches) => {
26+
if (!err && options.strict && matches.length === 0) {
27+
reject(new Error("'" + pattern + "' matched no files"));
28+
} else if (err) {
29+
reject(err);
30+
} else {
31+
resolve(matches);
32+
}
1933
});
20-
});
21-
return fns;
22-
}, []);
34+
}))
35+
);
2336
}
2437

25-
function processSingle(callback) {
26-
return function (err, matches) {
27-
callback(err, _.uniq(_.flatten(_.toArray(matches))));
28-
};
29-
}
38+
exports.glob = function (patterns, options, cb) {
39+
if (typeof options === "function") {
40+
cb = options;
41+
options = null;
42+
}
3043

31-
module.exports = {
32-
glob: function (patterns, options, cb) {
33-
if (typeof options === "function") {
34-
cb = options;
35-
options = null;
36-
}
37-
async.parallel(resolveGlobs(patterns, options), processSingle(cb));
38-
}
44+
resolveGlobs(patterns, options)
45+
.then(matches => cb(null, uniq(flatten(array(matches)))))
46+
.catch(err => cb(err));
3947
};

0 commit comments

Comments
 (0)