diff --git a/lib/copy/copy.js b/lib/copy/copy.js index 60161a23..1cc0ef83 100644 --- a/lib/copy/copy.js +++ b/lib/copy/copy.js @@ -113,6 +113,8 @@ async function onDir (srcStat, destStat, src, dest, opts) { await fs.mkdir(dest) } + const promises = [] + // loop through the files in the current directory to copy everything for await (const item of await fs.opendir(src)) { const srcItem = path.join(src, item.name) @@ -122,13 +124,17 @@ async function onDir (srcStat, destStat, src, dest, opts) { const include = await runFilter(srcItem, destItem, opts) if (!include) continue - const { destStat } = await stat.checkPaths(srcItem, destItem, 'copy', opts) - - // If the item is a copyable file, `getStatsAndPerformCopy` will copy it - // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively - await getStatsAndPerformCopy(destStat, srcItem, destItem, opts) + promises.push( + stat.checkPaths(srcItem, destItem, 'copy', opts).then(({ destStat }) => { + // If the item is a copyable file, `getStatsAndPerformCopy` will copy it + // If the item is a directory, `getStatsAndPerformCopy` will call `onDir` recursively + return getStatsAndPerformCopy(destStat, srcItem, destItem, opts) + }) + ) } + await Promise.all(promises) + if (!destStat) { await fs.chmod(dest, srcStat.mode) }