| 'use strict' | ||
| // https://github.com/jprichardson/node-fs-extra/issues/1056 | ||
| // Performing parallel operations on each item of an async iterator is | ||
| // surprisingly hard; you need to have handlers in place to avoid getting an | ||
| // UnhandledPromiseRejectionWarning. | ||
| // NOTE: This function does not presently handle return values, only errors | ||
| async function asyncIteratorConcurrentProcess (iterator, fn) { | ||
| const promises = [] | ||
| for await (const item of iterator) { | ||
| promises.push( | ||
| fn(item).then( | ||
| () => null, | ||
| (err) => err ?? new Error('unknown error') | ||
| ) | ||
| ) | ||
| } | ||
| await Promise.all( | ||
| promises.map((promise) => | ||
| promise.then((possibleErr) => { | ||
| if (possibleErr !== null) throw possibleErr | ||
| }) | ||
| ) | ||
| ) | ||
| } | ||
| module.exports = { | ||
| asyncIteratorConcurrentProcess | ||
| } |
+12
-19
@@ -9,2 +9,3 @@ 'use strict' | ||
| const stat = require('../util/stat') | ||
| const { asyncIteratorConcurrentProcess } = require('../util/async') | ||
@@ -117,25 +118,17 @@ async function copy (src, dest, opts = {}) { | ||
| const promises = [] | ||
| // loop through the files in the current directory to copy everything | ||
| for await (const item of await fs.opendir(src)) { | ||
| // iterate through the files in the current directory to copy everything | ||
| await asyncIteratorConcurrentProcess(await fs.opendir(src), async (item) => { | ||
| const srcItem = path.join(src, item.name) | ||
| const destItem = path.join(dest, item.name) | ||
| promises.push( | ||
| runFilter(srcItem, destItem, opts).then(include => { | ||
| if (include) { | ||
| // only copy the item if it matches the filter function | ||
| return 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) | ||
| }) | ||
| } | ||
| }) | ||
| ) | ||
| } | ||
| const include = await runFilter(srcItem, destItem, opts) | ||
| // only copy the item if it matches the filter function | ||
| if (include) { | ||
| 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) | ||
| } | ||
| }) | ||
| await Promise.all(promises) | ||
| if (!destStat) { | ||
@@ -142,0 +135,0 @@ await fs.chmod(dest, srcStat.mode) |
+1
-1
| { | ||
| "name": "fs-extra", | ||
| "version": "11.3.1", | ||
| "version": "11.3.2", | ||
| "description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.", | ||
@@ -5,0 +5,0 @@ "engines": { |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
56308
1.38%32
3.23%1276
1.75%