From 4402927859a421bebb89118cd4fc328752dd4928 Mon Sep 17 00:00:00 2001 From: Regev Brody Date: Sun, 7 Jul 2024 13:27:03 +0300 Subject: [PATCH] feat: when packages are filter due to engine not matching, we need to print it out, just like we do in peer checks #1422 --- src/lib/upgradePackageDefinitions.ts | 72 ++++++++++++++++++---------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/src/lib/upgradePackageDefinitions.ts b/src/lib/upgradePackageDefinitions.ts index 1e4ab2dd..f2b1adba 100644 --- a/src/lib/upgradePackageDefinitions.ts +++ b/src/lib/upgradePackageDefinitions.ts @@ -98,18 +98,45 @@ export async function upgradePackageDefinitions( const filteredLatestDependencies = pickBy(latestVersions, (spec, dep) => filteredUpgradedDependencies[dep]) + let result: UpgradePackageDefinitionsResult = [ + filteredUpgradedDependencies, + latestVersionResults, + options.peerDependencies, + ] + + if (!options.peer || Object.keys(filteredLatestDependencies).length === 0) { + return result + } + if (options.peer && Object.keys(filteredLatestDependencies).length > 0) { const upgradedPeerDependencies = await getPeerDependenciesFromRegistry(filteredLatestDependencies, options) - let checkPeerViolationResult: CheckIfInPeerViolationResult = { - violated: false, - filteredUpgradedDependencies, - upgradedPeerDependencies, + let checkPeerViolationResult: CheckIfInPeerViolationResult + + if ( + dequal(options.peerDependencies, { + ...options.peerDependencies, + ...upgradedPeerDependencies, + }) + ) { + checkPeerViolationResult = checkIfInPeerViolation( + currentDependencies, + filteredUpgradedDependencies, + options.peerDependencies!, + ) + if (!checkPeerViolationResult.violated) { + return result + } + } else { + checkPeerViolationResult = { + violated: false, + filteredUpgradedDependencies, + upgradedPeerDependencies, + } } - let rerunResult: UpgradePackageDefinitionsResult - let runIndex = 0 + let runCount = 0 do { - if (runIndex++ > 6) { + if (runCount++ > 6) { throw new Error(`Stuck in a while loop. Please report an issue`) } const peerDependenciesAfterUpgrade = { @@ -117,27 +144,22 @@ export async function upgradePackageDefinitions( ...checkPeerViolationResult.upgradedPeerDependencies, } if (dequal(options.peerDependencies, peerDependenciesAfterUpgrade)) { - if (runIndex > 1) { - // We can't find anything to do, will not upgrade anything - return [{}, latestVersionResults, options.peerDependencies] - } - rerunResult = [filteredUpgradedDependencies, latestVersionResults, options.peerDependencies] - } else { - const [newUpgradedDependencies, newLatestVersions, newPeerDependencies] = await upgradePackageDefinitions( - { ...currentDependencies, ...checkPeerViolationResult.filteredUpgradedDependencies }, - { ...options, peerDependencies: peerDependenciesAfterUpgrade, loglevel: 'silent' }, - ) - rerunResult = [ - { ...checkPeerViolationResult.filteredUpgradedDependencies, ...newUpgradedDependencies }, - { ...latestVersionResults, ...newLatestVersions }, - newPeerDependencies, - ] + // We can't find anything to do, will not upgrade anything + return [{}, latestVersionResults, options.peerDependencies] } - checkPeerViolationResult = checkIfInPeerViolation(currentDependencies, rerunResult[0], rerunResult[2]!) + const [newUpgradedDependencies, newLatestVersions, newPeerDependencies] = await upgradePackageDefinitions( + { ...currentDependencies, ...checkPeerViolationResult.filteredUpgradedDependencies }, + { ...options, peerDependencies: peerDependenciesAfterUpgrade, loglevel: 'silent' }, + ) + result = [ + { ...checkPeerViolationResult.filteredUpgradedDependencies, ...newUpgradedDependencies }, + { ...latestVersionResults, ...newLatestVersions }, + newPeerDependencies, + ] + checkPeerViolationResult = checkIfInPeerViolation(currentDependencies, result[0], result[2]!) } while (checkPeerViolationResult.violated) - return rerunResult } - return [filteredUpgradedDependencies, latestVersionResults, options.peerDependencies] + return result } export default upgradePackageDefinitions