Skip to content

Commit

Permalink
feat: when packages are filter due to engine not matching, we need to…
Browse files Browse the repository at this point in the history
… print it out, just like we do in peer checks #1422
  • Loading branch information
rbnayax committed Jul 7, 2024
1 parent fabc23b commit 4402927
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions src/lib/upgradePackageDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,46 +98,68 @@ 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 = {
...options.peerDependencies,
...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

0 comments on commit 4402927

Please sign in to comment.