You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

fs-extra

Package Overview
Dependencies
Maintainers
3
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-extra - npm Package Compare versions

Comparing version
11.3.1
to
11.3.2
+29
lib/util/async.js
'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)

{
"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": {