@@ -12,6 +12,7 @@ var globParent = require('glob-parent');
1212var normalizePath = require ( 'normalize-path' ) ;
1313var isNegatedGlob = require ( 'is-negated-glob' ) ;
1414var toAbsoluteGlob = require ( '@gulpjs/to-absolute-glob' ) ;
15+ var mapSeries = require ( 'now-and-later' ) . mapSeries ;
1516
1617var globErrMessage1 = 'File not found with singular glob: ' ;
1718var globErrMessage2 = ' (if this was purposeful, use `allowEmpty` option)' ;
@@ -55,6 +56,14 @@ function walkdir() {
5556 queue . push ( filepath ) ;
5657 } ;
5758
59+ function isDefined ( value ) {
60+ return typeof value !== 'undefined' ;
61+ }
62+
63+ function queuePush ( value ) {
64+ queue . push ( value ) ;
65+ }
66+
5867 function readdir ( filepath , cb ) {
5968 fs . readdir ( filepath , readdirOpts , onReaddir ) ;
6069
@@ -63,29 +72,45 @@ function walkdir() {
6372 return cb ( err ) ;
6473 }
6574
66- dirents . forEach ( processDirent ) ;
75+ mapSeries ( dirents , processDirents , function ( err , dirs ) {
76+ if ( err ) {
77+ return cb ( err ) ;
78+ }
6779
68- cb ( ) ;
80+ dirs . filter ( isDefined ) . forEach ( queuePush ) ;
81+
82+ cb ( ) ;
83+ } ) ;
6984 }
7085
71- function processDirent ( dirent ) {
86+ function processDirents ( dirent , key , cb ) {
7287 var nextpath = path . join ( filepath , dirent . name ) ;
7388 ee . emit ( 'path' , nextpath , dirent ) ;
7489
7590 if ( dirent . isDirectory ( ) ) {
76- queue . push ( nextpath ) ;
77- } else if ( dirent . isSymbolicLink ( ) ) {
91+ cb ( null , nextpath ) ;
92+
93+ return ;
94+ }
95+
96+ if ( dirent . isSymbolicLink ( ) ) {
7897 // If it's a symlink, check if the symlink points to a directory
7998 fs . stat ( nextpath , function ( err , stats ) {
8099 if ( err ) {
81100 return cb ( err ) ;
82101 }
83102
84103 if ( stats . isDirectory ( ) ) {
85- queue . push ( nextpath ) ;
104+ cb ( null , nextpath ) ;
105+ } else {
106+ cb ( ) ;
86107 }
87108 } ) ;
109+
110+ return ;
88111 }
112+
113+ cb ( ) ;
89114 }
90115 }
91116
0 commit comments