Skip to content

Commit

Permalink
fix: fix cascade bumping when some dep belongs to several levels of t…
Browse files Browse the repository at this point in the history
…he dep tree
  • Loading branch information
antongolub committed Mar 5, 2022
1 parent 9d9fce4 commit cf20dea
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/updateDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const resolveReleaseType = (pkg, bumpStrategy = "override", releaseStrategy = "p
};

/**
* Get dependent release type by recursive scanning and updating its deps.
* Get dependent release type by recursive scanning and updating pkg deps.
*
* @param {Package} pkg The package with local deps to check.
* @param {string} bumpStrategy Dependency resolution strategy: override, satisfy, inherit.
Expand All @@ -173,6 +173,7 @@ const resolveReleaseType = (pkg, bumpStrategy = "override", releaseStrategy = "p
const getDependentRelease = (pkg, bumpStrategy, releaseStrategy, ignore) => {
const severityOrder = ["patch", "minor", "major"];
const { localDeps, manifest = {} } = pkg;
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
const { dependencies = {}, devDependencies = {}, peerDependencies = {}, optionalDependencies = {} } = manifest;
const scopes = [dependencies, devDependencies, peerDependencies, optionalDependencies];
const bumpDependency = (scope, name, nextVersion) => {
Expand All @@ -194,23 +195,20 @@ const getDependentRelease = (pkg, bumpStrategy, releaseStrategy, ignore) => {
return localDeps
.filter((p) => !ignore.includes(p))
.reduce((releaseType, p) => {
const name = p.name;

// Has changed if...
// 1. Any local dep package itself has changed
// 2. Any local dep package has local deps that have changed.
const nextType = resolveReleaseType(p, bumpStrategy, releaseStrategy,[...ignore, ...localDeps]);

// Set the nextVersion fallback to the last local dependency package last version
let nextVersion = p._lastRelease && p._lastRelease.version;

// Update the nextVersion only if there is a next type to be bumped
if (nextType) nextVersion = p._preRelease ? getNextPreVersion(p) : getNextVersion(p);
const lastVersion = pkg._lastRelease && pkg._lastRelease.version;
const nextType = resolveReleaseType(p, bumpStrategy, releaseStrategy,[...ignore, p]);
const nextVersion =
nextType
// Update the nextVersion only if there is a next type to be bumped
? p._preRelease ? getNextPreVersion(p) : getNextVersion(p)
// Set the nextVersion fallback to the last local dependency package last version
: p._lastRelease && p._lastRelease.version

// 3. And this change should correspond to manifest updating rule.
const requireRelease = scopes
.reduce((res, scope) => bumpDependency(scope, name, nextVersion) || res, !lastVersion)
.reduce((res, scope) => bumpDependency(scope, p.name, nextVersion) || res, !lastVersion)

return requireRelease && (severityOrder.indexOf(nextType) > severityOrder.indexOf(releaseType))
? nextType
Expand Down

0 comments on commit cf20dea

Please sign in to comment.