Skip to content

Commit

Permalink
fix: bump release type by dependent if deps.release is inherit (#100)
Browse files Browse the repository at this point in the history
* fix: bump release type by dependent if inherit

* chore: remove auto added package

* refactor: no magic numbers

* test: add test for inherit when local changes less severe than deps

* chore: remove package lock

* chore: revert yarn lock
  • Loading branch information
gavmck authored Jul 28, 2024
1 parent bd08b14 commit d44f324
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/updateDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions test/lib/updateDeps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

0 comments on commit d44f324

Please sign in to comment.