fix: directories are not being removed from node_modules while linking commands (#7101)

close #6756
This commit is contained in:
Zoltan Kochan
2023-09-17 18:25:12 +03:00
committed by GitHub
parent 2690115d42
commit 78a97774d1
2 changed files with 13 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/headless": patch
"pnpm": patch
---
Fixed an ENOENT error that was sometimes happening during install with "hoisted" `node_modules` [#6756](https://github.com/pnpm/pnpm/issues/6756).

View File

@@ -46,9 +46,11 @@ export async function linkHoistedModules (
prefix: opts.lockfileDir,
removed: dirsToRemove.length,
})
await Promise.all([
...dirsToRemove.map((dir) => tryRemoveDir(dir)),
...Object.entries(hierarchy)
// We should avoid removing unnecessary directories while simultaneously adding new ones.
// Doing so can sometimes lead to a race condition when linking commands to `node_modules/.bin`.
await Promise.all(dirsToRemove.map((dir) => tryRemoveDir(dir)))
await Promise.all(
Object.entries(hierarchy)
.map(([parentDir, depsHierarchy]) => {
function warn (message: string) {
logger.info({
@@ -60,8 +62,8 @@ export async function linkHoistedModules (
...opts,
warn,
})
}),
])
})
)
}
async function tryRemoveDir (dir: string) {