fix: modules directory compatibility check

Always check the layout version first.
This commit is contained in:
Zoltan Kochan
2020-05-27 00:37:17 +03:00
parent 1737c10422
commit 58c02009f3
2 changed files with 11 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/get-context": patch
---
When checking compatibility of the existing modules directory, start with the layout version. Otherwise, it may happen that some of the fields were renamed and other checks will fail.

View File

@@ -13,11 +13,16 @@ export default function checkCompatibility (
virtualStoreDir: string,
}
) {
if (!modules.layoutVersion || modules.layoutVersion !== LAYOUT_VERSION) {
throw new ModulesBreakingChangeError({
modulesPath: opts.modulesDir,
})
}
// Important: comparing paths with path.relative()
// is the only way to compare paths correctly on Windows
// as of Node.js 4-9
// See related issue: https://github.com/pnpm/pnpm/issues/996
if (path.relative(modules.storeDir, opts.storeDir) !== '') {
if (!modules.storeDir || path.relative(modules.storeDir, opts.storeDir) !== '') {
throw new UnexpectedStoreError({
actualStorePath: opts.storeDir,
expectedStorePath: modules.storeDir,
@@ -31,9 +36,4 @@ export default function checkCompatibility (
modulesDir: opts.modulesDir,
})
}
if (!modules.layoutVersion || modules.layoutVersion !== LAYOUT_VERSION) {
throw new ModulesBreakingChangeError({
modulesPath: opts.modulesDir,
})
}
}