Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bump release type by dependent if deps.release is inherit #100

Merged
merged 6 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
gavmck marked this conversation as resolved.
Show resolved Hide resolved
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==
Loading