Skip to content

Commit

Permalink
fix: closes #11173, move cache clear code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
barisusakli committed Mar 20, 2023
1 parent 18b2150 commit c2961ad
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand All @@ -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 {
Expand Down

0 comments on commit c2961ad

Please sign in to comment.