Skip to content

Commit d44f324

Browse files
authored
fix: bump release type by dependent if deps.release is inherit (#100)
* 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
1 parent bd08b14 commit d44f324

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

lib/updateDeps.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,29 @@ const resolveReleaseType = (pkg, bumpStrategy = "override", releaseStrategy = "p
163163
// NOTE This fn also updates pkg deps, so it must be invoked anyway.
164164
const dependentReleaseType = getDependentRelease(pkg, bumpStrategy, releaseStrategy, ignore, prefix);
165165

166+
// Define release type for dependent package if any of its deps changes.
167+
// `patch`, `minor`, `major` — strictly declare the release type that occurs when any dependency is updated.
168+
// `inherit` — applies the "highest" release of updated deps to the package.
169+
// For example, if any dep has a breaking change, `major` release will be applied to the all dependants up the chain.
170+
// If we want to inherit the release type from the dependent package
171+
const types = ["patch", "minor", "major"];
172+
const depIndex = dependentReleaseType ? types.indexOf(dependentReleaseType) : types.length + 1;
173+
const pkgIndex = pkg._nextType ? types.indexOf(pkg._nextType) : types.length + 1;
174+
175+
if (releaseStrategy === "inherit" && dependentReleaseType && depIndex >= pkgIndex) {
176+
return dependentReleaseType;
177+
}
178+
166179
// Release type found by commitAnalyzer.
167180
if (pkg._nextType) {
168181
return pkg._nextType;
169182
}
170183

184+
// No deps changed.
171185
if (!dependentReleaseType) {
172186
return undefined;
173187
}
174188

175-
// Define release type for dependent package if any of its deps changes.
176-
// `patch`, `minor`, `major` — strictly declare the release type that occurs when any dependency is updated.
177-
// `inherit` — applies the "highest" release of updated deps to the package.
178-
// For example, if any dep has a breaking change, `major` release will be applied to the all dependants up the chain.
179-
180189
pkg._nextType = releaseStrategy === "inherit" ? dependentReleaseType : releaseStrategy;
181190

182191
return pkg._nextType;

test/lib/updateDeps.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ describe("resolveReleaseType()", () => {
8585
"inherit",
8686
"major"
8787
],
88+
[
89+
"implements `inherit` strategy: returns the highest release type of any deps even if the local package has changes",
90+
{
91+
manifest: { dependencies: { a: "1.0.0" } },
92+
_nextType: "minor",
93+
localDeps: [
94+
{
95+
name: "a",
96+
manifest: { dependencies: { b: "1.0.0", c: "1.0.0", d: "1.0.0" } },
97+
_lastRelease: { version: "1.0.0" },
98+
_nextType: false,
99+
localDeps: [
100+
{ name: "b", _nextType: false, localDeps: [], _lastRelease: { version: "1.0.0" } },
101+
{ name: "c", _nextType: "patch", localDeps: [], _lastRelease: { version: "1.0.0" } },
102+
{ name: "d", _nextType: "major", localDeps: [], _lastRelease: { version: "1.0.0" } },
103+
],
104+
},
105+
],
106+
},
107+
undefined,
108+
"inherit",
109+
"major"
110+
],
88111
[
89112
"overrides dependent release type with custom value if defined",
90113
{

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -6136,4 +6136,4 @@ yocto-queue@^0.1.0:
61366136
yocto-queue@^1.0.0:
61376137
version "1.0.0"
61386138
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
6139-
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==
6139+
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

0 commit comments

Comments
 (0)