Skip to content

Commit f836b6e

Browse files
Fix: --exclude version not respected (#365)
1 parent 4a43b35 commit f836b6e

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@chronus/chronus"
5+
---
6+
7+
Fix `--exclude` not respected for `version`, `status` commands

packages/chronus/src/release-plan/assemble-release-plan.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,42 @@ describe("Assemble Release Plan", () => {
249249
expect(plan.changes[0]).toMatchObject({ usage: "partial", packages: ["pkg-a"] });
250250
});
251251
});
252+
253+
describe("partial release plan using exclude option", () => {
254+
it("ignore packages with changes", () => {
255+
const workspace: Workspace = mkWorkspace([mkPkg("pkg-a", {}), mkPkg("pkg-b", {})]);
256+
const plan = assembleReleasePlan(
257+
[mkChange("pkg-a", "minor"), mkChange("pkg-b", "minor")],
258+
createChronusWorkspace(workspace, baseConfig),
259+
{ exclude: ["pkg-b"] },
260+
);
261+
expect(plan.actions).toHaveLength(1);
262+
expect(plan.actions[0]).toMatchObject({ packageName: "pkg-a", oldVersion: "1.0.0", newVersion: "1.1.0" });
263+
});
264+
265+
it("ignore packages that would need to be bumped as dependent", () => {
266+
const workspace: Workspace = mkWorkspace([
267+
mkPkg("pkg-a", {}),
268+
mkPkg("pkg-b", { dependencies: { "pkg-a": "1.0.0" } }),
269+
]);
270+
const plan = assembleReleasePlan([mkChange("pkg-a", "minor")], createChronusWorkspace(workspace, baseConfig), {
271+
exclude: ["pkg-b"],
272+
});
273+
expect(plan.actions).toHaveLength(1);
274+
expect(plan.actions[0]).toMatchObject({ packageName: "pkg-a", oldVersion: "1.0.0", newVersion: "1.1.0" });
275+
});
276+
277+
it("report changes as partially used if only bumping some packages tagged in it", () => {
278+
const workspace: Workspace = mkWorkspace([mkPkg("pkg-a", {}), mkPkg("pkg-b", {})]);
279+
const plan = assembleReleasePlan(
280+
[mkChange(["pkg-a", "pkg-b"], "minor")],
281+
createChronusWorkspace(workspace, baseConfig),
282+
{
283+
exclude: ["pkg-b"],
284+
},
285+
);
286+
expect(plan.changes).toHaveLength(1);
287+
expect(plan.changes[0]).toMatchObject({ usage: "partial", packages: ["pkg-a"] });
288+
});
289+
});
252290
});

packages/chronus/src/release-plan/assemble-release-plan.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ChangeDescription } from "../change/types.js";
22
import { getDependentsGraph } from "../dependency-graph/index.js";
3+
import { isPackageIncluded } from "../utils/misc-utils.js";
34
import type { ChronusWorkspace } from "../workspace/types.js";
45
import { applyDependents } from "./determine-dependents.js";
56
import { incrementVersion } from "./increment-version.js";
@@ -18,7 +19,10 @@ export function assembleReleasePlan(
1819
options?: AssembleReleasePlanOptions,
1920
): ReleasePlan {
2021
const packagesByName = new Map(workspace.allPackages.map((pkg) => [pkg.name, pkg]));
21-
const { changeApplications, actions: requested } = reduceChanges(changes, workspace, options?.only);
22+
const { changeApplications, actions: requested } = reduceChanges(changes, workspace, {
23+
only: options?.only,
24+
exclude: options?.exclude,
25+
});
2226

2327
const dependentsGraph = getDependentsGraph(workspace.packages);
2428
const internalActions = new Map<string, InternalReleaseAction>();
@@ -46,6 +50,7 @@ export function assembleReleasePlan(
4650
internalActions.set(request.packageName, request);
4751
}
4852
}
53+
4954
// The map passed in to determineDependents will be mutated
5055
applyDependents({
5156
actions: internalActions,
@@ -76,7 +81,7 @@ export function assembleReleasePlan(
7681
function reduceChanges(
7782
changes: ChangeDescription[],
7883
workspace: ChronusWorkspace,
79-
only?: string[],
84+
filters: { only?: string[]; exclude?: string[] } = {},
8085
): { changeApplications: ReleasePlanChangeApplication[]; actions: Map<string, InternalReleaseAction> } {
8186
const actions: Map<string, InternalReleaseAction> = new Map();
8287
const changeApplications: ReleasePlanChangeApplication[] = [];
@@ -85,8 +90,8 @@ function reduceChanges(
8590
// Filter out ignored packages because they should not trigger a release
8691
// If their dependencies need updates, they will be added to releases by `determineDependents()` with release type `none`
8792
const packages = change.packages
88-
.filter((name) => !only || only.includes(name))
8993
.map((name) => workspace.getPackage(name))
94+
.filter((pkg) => isPackageIncluded(pkg, filters))
9095
.filter((pkg) => pkg.state === "versioned" || pkg.state === "standalone");
9196

9297
changeApplications.push({

packages/chronus/src/utils/misc-utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export function isPackageIncluded(
6767
return false;
6868
}
6969

70-
if (only && (only.includes(pkgName) || only.includes(policyName))) {
71-
return true;
70+
if (only) {
71+
return only.includes(pkgName) || only.includes(policyName);
7272
}
7373

7474
return true;

0 commit comments

Comments
 (0)