From c2961ad4cd4746b7cc393767059e8cac7dd8ffca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 20 Mar 2023 11:05:48 -0400 Subject: [PATCH] fix: closes #11173, move cache clear code if 2 deps were updated only one of them was cleared from require.cache. ie commander & lru-cache both has major version bump then only commander would be cleared from cache since it throws first --- src/cli/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index 5eb9f4924c..18c5b88683 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -32,12 +32,6 @@ try { if (!semver.satisfies(version, defaultPackage.dependencies[packageName])) { const e = new TypeError(`Incorrect dependency version: ${packageName}`); e.code = 'DEP_WRONG_VERSION'; - // delete the module from require cache so it doesn't break rest of the upgrade - // https://github.com/NodeBB/NodeBB/issues/11173 - const resolvedModule = require.resolve(packageName); - if (require.cache[resolvedModule]) { - delete require.cache[resolvedModule]; - } throw e; } }; @@ -57,6 +51,16 @@ try { packageInstall.preserveExtraneousPlugins(); packageInstall.installAll(); + // delete the module from require cache so it doesn't break rest of the upgrade + // https://github.com/NodeBB/NodeBB/issues/11173 + const packages = ['nconf', 'async', 'commander', 'chalk', 'lodash', 'lru-cache']; + packages.forEach((packageName) => { + const resolvedModule = require.resolve(packageName); + if (require.cache[resolvedModule]) { + delete require.cache[resolvedModule]; + } + }); + const chalk = require('chalk'); console.log(`${chalk.green('OK')}\n`); } else {