@@ -21,23 +21,22 @@ const concurrency = {concurrency: MAX_FILE_REQUESTS}
21
21
const NODE_MODULES_PATTERN = path . sep + "node_modules" + path . sep
22
22
23
23
export async function walk ( dirPath : string , consumer ?: ( file : string , stat : Stats ) => void , filter ?: Filter , addRootToResult ?: boolean ) : Promise < Array < string > > {
24
- const list = await BluebirdPromise . map ( await readdir ( dirPath ) , name => {
25
- const filePath = dirPath + path . sep + name
26
- return lstat ( filePath )
27
- . then ( ( stat ) : any => {
28
- if ( filter != null && ! filter ( filePath , stat ) ) {
29
- return null
30
- }
24
+ const childNames = await readdir ( dirPath )
25
+ const list = await BluebirdPromise . map ( childNames , name => lstat ( dirPath + path . sep + name ) , concurrency )
26
+ . then ( stats => BluebirdPromise . map ( stats , ( stat , index ) : any => {
27
+ const filePath = dirPath + path . sep + childNames [ index ]
28
+ if ( filter != null && ! filter ( filePath , stat ) ) {
29
+ return null
30
+ }
31
31
32
- if ( consumer != null ) {
33
- consumer ( filePath , stat )
34
- }
35
- if ( stat . isDirectory ( ) ) {
36
- return walk ( filePath , consumer , filter , true )
37
- }
38
- return filePath
39
- } )
40
- } , concurrency )
32
+ if ( consumer != null ) {
33
+ consumer ( filePath , stat )
34
+ }
35
+ if ( stat . isDirectory ( ) ) {
36
+ return walk ( filePath , consumer , filter , true )
37
+ }
38
+ return filePath
39
+ } , concurrency ) )
41
40
42
41
list . sort ( ( a , b ) => {
43
42
// files before directories
0 commit comments