diff --git a/.changeset/twelve-ladybugs-float.md b/.changeset/twelve-ladybugs-float.md new file mode 100644 index 0000000000..9fe88cf938 --- /dev/null +++ b/.changeset/twelve-ladybugs-float.md @@ -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. diff --git a/packages/get-context/src/checkCompatibility/index.ts b/packages/get-context/src/checkCompatibility/index.ts index 0d04d45274..8b2686d55e 100644 --- a/packages/get-context/src/checkCompatibility/index.ts +++ b/packages/get-context/src/checkCompatibility/index.ts @@ -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, - }) - } }