mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-30 04:52:04 -04:00
fix: don't remove the modules directory, just the contents of it
close #2720 PR #2722
This commit is contained in:
5
.changeset/dirty-comics-doubt.md
Normal file
5
.changeset/dirty-comics-doubt.md
Normal 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.
|
||||
@@ -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(', ')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user