fix: don't remove the modules directory, just the contents of it

close #2720
PR #2722
This commit is contained in:
Zoltan Kochan
2020-07-29 01:46:34 +03:00
committed by GitHub
parent da56ff3345
commit 25b425ca25
2 changed files with 16 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/get-context": patch
---
When purging an incompatible modules directory, don't remove the actual directory, just the contents of it.

View File

@@ -276,12 +276,22 @@ async function purgeModulesDirsOfImporter (
prefix: importer.rootDir,
})
try {
await rimraf(importer.modulesDir)
// We don't remove the actual modules directory, just the contents of it.
// 1. we will need the directory anyway.
// 2. in some setups, pnpm won't even have permission to remove the modules directory.
await removeContentsOfDir(importer.modulesDir)
} catch (err) {
if (err.code !== 'ENOENT') throw err
}
}
async function removeContentsOfDir (dir: string) {
const items = await fs.readdir(dir)
for (const item of items) {
await rimraf(path.join(dir, item))
}
}
function stringifyIncludedDeps (included: IncludedDependencies) {
return DEPENDENCIES_FIELDS.filter((depsField) => included[depsField]).join(', ')
}