@@ -113,23 +113,28 @@ async function onDir (srcStat, destStat, src, dest, opts) {
113
113
await fs . mkdir ( dest )
114
114
}
115
115
116
- const items = await fs . readdir ( src )
116
+ const promises = [ ]
117
117
118
118
// loop through the files in the current directory to copy everything
119
- await Promise . all ( items . map ( async item => {
120
- const srcItem = path . join ( src , item )
121
- const destItem = path . join ( dest , item )
122
-
123
- // skip the item if it is matches by the filter function
124
- const include = await runFilter ( srcItem , destItem , opts )
125
- if ( ! include ) return
126
-
127
- const { destStat } = await stat . checkPaths ( srcItem , destItem , 'copy' , opts )
119
+ for await ( const item of await fs . opendir ( src ) ) {
120
+ const srcItem = path . join ( src , item . name )
121
+ const destItem = path . join ( dest , item . name )
122
+
123
+ promises . push (
124
+ runFilter ( srcItem , destItem , opts ) . then ( include => {
125
+ if ( include ) {
126
+ // only copy the item if it matches the filter function
127
+ return stat . checkPaths ( srcItem , destItem , 'copy' , opts ) . then ( ( { destStat } ) => {
128
+ // If the item is a copyable file, `getStatsAndPerformCopy` will copy it
129
+ // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
130
+ return getStatsAndPerformCopy ( destStat , srcItem , destItem , opts )
131
+ } )
132
+ }
133
+ } )
134
+ )
135
+ }
128
136
129
- // If the item is a copyable file, `getStatsAndPerformCopy` will copy it
130
- // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively
131
- return getStatsAndPerformCopy ( destStat , srcItem , destItem , opts )
132
- } ) )
137
+ await Promise . all ( promises )
133
138
134
139
if ( ! destStat ) {
135
140
await fs . chmod ( dest , srcStat . mode )
0 commit comments