diff --git a/lib/updateDeps.js b/lib/updateDeps.js index a777de2..003f25a 100644 --- a/lib/updateDeps.js +++ b/lib/updateDeps.js @@ -163,20 +163,29 @@ const resolveReleaseType = (pkg, bumpStrategy = "override", releaseStrategy = "p // NOTE This fn also updates pkg deps, so it must be invoked anyway. const dependentReleaseType = getDependentRelease(pkg, bumpStrategy, releaseStrategy, ignore, prefix); + // Define release type for dependent package if any of its deps changes. + // `patch`, `minor`, `major` — strictly declare the release type that occurs when any dependency is updated. + // `inherit` — applies the "highest" release of updated deps to the package. + // For example, if any dep has a breaking change, `major` release will be applied to the all dependants up the chain. + // If we want to inherit the release type from the dependent package + const types = ["patch", "minor", "major"]; + const depIndex = dependentReleaseType ? types.indexOf(dependentReleaseType) : types.length + 1; + const pkgIndex = pkg._nextType ? types.indexOf(pkg._nextType) : types.length + 1; + + if (releaseStrategy === "inherit" && dependentReleaseType && depIndex >= pkgIndex) { + return dependentReleaseType; + } + // Release type found by commitAnalyzer. if (pkg._nextType) { return pkg._nextType; } + // No deps changed. if (!dependentReleaseType) { return undefined; } - // Define release type for dependent package if any of its deps changes. - // `patch`, `minor`, `major` — strictly declare the release type that occurs when any dependency is updated. - // `inherit` — applies the "highest" release of updated deps to the package. - // For example, if any dep has a breaking change, `major` release will be applied to the all dependants up the chain. - pkg._nextType = releaseStrategy === "inherit" ? dependentReleaseType : releaseStrategy; return pkg._nextType; diff --git a/test/lib/updateDeps.test.js b/test/lib/updateDeps.test.js index 3ab2e98..ef75417 100644 --- a/test/lib/updateDeps.test.js +++ b/test/lib/updateDeps.test.js @@ -85,6 +85,29 @@ describe("resolveReleaseType()", () => { "inherit", "major" ], + [ + "implements `inherit` strategy: returns the highest release type of any deps even if the local package has changes", + { + manifest: { dependencies: { a: "1.0.0" } }, + _nextType: "minor", + localDeps: [ + { + name: "a", + manifest: { dependencies: { b: "1.0.0", c: "1.0.0", d: "1.0.0" } }, + _lastRelease: { version: "1.0.0" }, + _nextType: false, + localDeps: [ + { name: "b", _nextType: false, localDeps: [], _lastRelease: { version: "1.0.0" } }, + { name: "c", _nextType: "patch", localDeps: [], _lastRelease: { version: "1.0.0" } }, + { name: "d", _nextType: "major", localDeps: [], _lastRelease: { version: "1.0.0" } }, + ], + }, + ], + }, + undefined, + "inherit", + "major" + ], [ "overrides dependent release type with custom value if defined", { diff --git a/yarn.lock b/yarn.lock index 039fdeb..4e62887 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6136,4 +6136,4 @@ yocto-queue@^0.1.0: yocto-queue@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" - integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== + integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== \ No newline at end of file