From 58c02009f3490797399ebef6ea1192b125838f1c Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 27 May 2020 00:37:17 +0300 Subject: [PATCH] fix: modules directory compatibility check Always check the layout version first. --- .changeset/twelve-ladybugs-float.md | 5 +++++ packages/get-context/src/checkCompatibility/index.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/twelve-ladybugs-float.md 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, - }) - } }