@@ -12,6 +12,7 @@ var globParent = require('glob-parent');
12
12
var normalizePath = require ( 'normalize-path' ) ;
13
13
var isNegatedGlob = require ( 'is-negated-glob' ) ;
14
14
var toAbsoluteGlob = require ( '@gulpjs/to-absolute-glob' ) ;
15
+ var mapSeries = require ( 'now-and-later' ) . mapSeries ;
15
16
16
17
var globErrMessage1 = 'File not found with singular glob: ' ;
17
18
var globErrMessage2 = ' (if this was purposeful, use `allowEmpty` option)' ;
@@ -55,6 +56,14 @@ function walkdir() {
55
56
queue . push ( filepath ) ;
56
57
} ;
57
58
59
+ function isDefined ( value ) {
60
+ return typeof value !== 'undefined' ;
61
+ }
62
+
63
+ function queuePush ( value ) {
64
+ queue . push ( value ) ;
65
+ }
66
+
58
67
function readdir ( filepath , cb ) {
59
68
fs . readdir ( filepath , readdirOpts , onReaddir ) ;
60
69
@@ -63,29 +72,45 @@ function walkdir() {
63
72
return cb ( err ) ;
64
73
}
65
74
66
- dirents . forEach ( processDirent ) ;
75
+ mapSeries ( dirents , processDirents , function ( err , dirs ) {
76
+ if ( err ) {
77
+ return cb ( err ) ;
78
+ }
67
79
68
- cb ( ) ;
80
+ dirs . filter ( isDefined ) . forEach ( queuePush ) ;
81
+
82
+ cb ( ) ;
83
+ } ) ;
69
84
}
70
85
71
- function processDirent ( dirent ) {
86
+ function processDirents ( dirent , key , cb ) {
72
87
var nextpath = path . join ( filepath , dirent . name ) ;
73
88
ee . emit ( 'path' , nextpath , dirent ) ;
74
89
75
90
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 ( ) ) {
78
97
// If it's a symlink, check if the symlink points to a directory
79
98
fs . stat ( nextpath , function ( err , stats ) {
80
99
if ( err ) {
81
100
return cb ( err ) ;
82
101
}
83
102
84
103
if ( stats . isDirectory ( ) ) {
85
- queue . push ( nextpath ) ;
104
+ cb ( null , nextpath ) ;
105
+ } else {
106
+ cb ( ) ;
86
107
}
87
108
} ) ;
109
+
110
+ return ;
88
111
}
112
+
113
+ cb ( ) ;
89
114
}
90
115
}
91
116
0 commit comments