perf: optimize fs-hard-link-dir

This commit is contained in:
Zoltan Kochan
2023-01-30 17:33:39 +02:00
parent 9247f6781b
commit 5c4eb0fc3e
2 changed files with 10 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/fs.hard-link-dir": patch
---
Performance optimization.

View File

@@ -11,17 +11,18 @@ export async function hardLinkDir (src: string, destDirs: string[]) {
if (file === 'node_modules') return
const srcFile = path.join(src, file)
if ((await fs.lstat(srcFile)).isDirectory()) {
await Promise.all(
const destSubdirs = await Promise.all(
destDirs.map(async (destDir) => {
const destFile = path.join(destDir, file)
const destSubdir = path.join(destDir, file)
try {
await fs.mkdir(destFile, { recursive: true })
await fs.mkdir(destSubdir, { recursive: true })
} catch (err: any) { // eslint-disable-line
if (err.code !== 'EEXIST') throw err
}
return hardLinkDir(srcFile, [destFile])
return destSubdir
})
)
await hardLinkDir(srcFile, destSubdirs)
return
}
await Promise.all(