11var glob = require ( "glob" ) ;
2- var async = require ( "async" ) ;
32
43exports . _glob = glob ;
54
@@ -21,30 +20,28 @@ function array(arr) {
2120
2221function resolveGlobs ( patterns , options ) {
2322 options = options || { } ;
24- return array ( patterns ) . reduce ( function ( fns , pattern ) {
25- fns . push ( function ( done ) {
26- exports . _glob ( pattern , options , function ( err , matches ) {
27- if ( ! err && options . strict && matches . length === 0 ) {
28- done ( new Error ( "'" + pattern + "' matched no files" ) ) ;
29- } else {
30- done ( err , matches ) ;
31- }
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+ }
3233 } ) ;
33- } ) ;
34- return fns ;
35- } , [ ] ) ;
36- }
37-
38- function processSingle ( callback ) {
39- return function ( err , matches ) {
40- callback ( err , uniq ( flatten ( array ( matches ) ) ) ) ;
41- } ;
34+ } ) )
35+ ) ;
4236}
4337
4438exports . glob = function ( patterns , options , cb ) {
4539 if ( typeof options === "function" ) {
4640 cb = options ;
4741 options = null ;
4842 }
49- async . parallel ( resolveGlobs ( patterns , options ) , processSingle ( cb ) ) ;
43+
44+ resolveGlobs ( patterns , options )
45+ . then ( matches => cb ( null , uniq ( flatten ( array ( matches ) ) ) ) )
46+ . catch ( err => cb ( err ) ) ;
5047} ;
0 commit comments