Skip to content

Commit

Permalink
Fixed an infinite loop with fixed & ignored package depending on anot…
Browse files Browse the repository at this point in the history
…her release (#769)
  • Loading branch information
Andarist committed Mar 6, 2022
1 parent ad778e1 commit 3e8e672
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/funny-cooks-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/assemble-release-plan": patch
"@changesets/cli": patch
---

Fixed an infinite loop involving a fixed group of packages and a package within that group that was both ignored and dependent on another package from that group.
2 changes: 1 addition & 1 deletion packages/assemble-release-plan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function assembleReleasePlan(
let fixedConstraintUpdated = matchFixedConstraint(
releases,
packagesByName,
config.fixed
config
);
let linksUpdated = applyLinks(releases, packagesByName, config.linked);

Expand Down
9 changes: 6 additions & 3 deletions packages/assemble-release-plan/src/match-fixed-constraint.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Fixed } from "@changesets/types";
import { Config } from "@changesets/types";
import { Package } from "@manypkg/get-packages";
import { InternalRelease } from "./types";
import { getCurrentHighestVersion, getHighestReleaseType } from "./utils";

export default function matchFixedConstraint(
releases: Map<string, InternalRelease>,
packagesByName: Map<string, Package>,
fixed: Fixed
config: Config
): boolean {
let updated = false;

for (let fixedPackages of fixed) {
for (let fixedPackages of config.fixed) {
let releasingFixedPackages = [...releases.values()].filter(
release => fixedPackages.includes(release.name) && release.type !== "none"
);
Expand All @@ -25,6 +25,9 @@ export default function matchFixedConstraint(

// Finally, we update the packages so all of them are on the highest version
for (let pkgName of fixedPackages) {
if (config.ignore.includes(pkgName)) {
continue;
}
let release = releases.get(pkgName);

if (!release) {
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/src/commands/version/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,34 @@ describe("fixed", () => {
);
});

it("should not bump an ignored fixed package that depends on a package from the group that is being released", async () => {
const cwd = await f.copy("fixed-packages");
await writeChangesets([simpleChangeset3], cwd);

await version(cwd, defaultOptions, {
...modifiedDefaultConfig,
fixed: [["pkg-a", "pkg-b"]],
ignore: ["pkg-a"]
});

expect((await getPackages(cwd)).packages.map(x => x.packageJson))
.toMatchInlineSnapshot(`
Array [
Object {
"dependencies": Object {
"pkg-b": "1.0.1",
},
"name": "pkg-a",
"version": "1.0.0",
},
Object {
"name": "pkg-b",
"version": "1.0.1",
},
]
`);
});

it("should update CHANGELOGs of all packages from the fixed group", async () => {
const cwd = await f.copy("fixed-packages");
const spy = jest.spyOn(fs, "writeFile");
Expand Down

0 comments on commit 3e8e672

Please sign in to comment.