Skip to content

Commit

Permalink
Add an error message for when a changeset references a nonexistent pa…
Browse files Browse the repository at this point in the history
…ckage (#1508)

* Add an error message for when a changeset references a nonexistent package

This can occur when a package with pending changesets is deleted.

* Add changeset

* Fix formatting

* Add tests

* Fix formatting
  • Loading branch information
stevethedev authored Nov 12, 2024
1 parent 7323704 commit 26c8ba9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sharp-impalas-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/assemble-release-plan": patch
---

Add error-reporting for when a changeset references a non-existent package
22 changes: 22 additions & 0 deletions packages/assemble-release-plan/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,28 @@ Mixed changesets that contain both ignored and not ignored packages are not allo
expect(releases[1].newVersion).toEqual("1.0.0");
});

it("should throw an error when a changeset contains a package that is not in the workspace", () => {
setup.addChangeset({
id: "big-cats-delight",
releases: [{ name: "pkg-a", type: "major" }],
});
setup.addChangeset({
id: "small-dogs-sad",
releases: [{ name: "pkg-z", type: "minor" }],
});

expect(() =>
assembleReleasePlan(
setup.changesets,
setup.packages,
defaultConfig,
undefined
)
).toThrow(
"Found changeset small-dogs-sad for package pkg-z which is not in the workspace"
);
});

describe("fixed packages", () => {
it("should assemble release plan for fixed packages", () => {
setup.addChangeset({
Expand Down
10 changes: 9 additions & 1 deletion packages/assemble-release-plan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,16 @@ function getRelevantChangesets(
const skippedPackages = [];
const notSkippedPackages = [];
for (const release of changeset.releases) {
const packageByName = packagesByName.get(release.name);

if (!packageByName) {
throw new Error(
`Found changeset ${changeset.id} for package ${release.name} which is not in the workspace`
);
}

if (
shouldSkipPackage(packagesByName.get(release.name)!, {
shouldSkipPackage(packageByName, {
ignore: config.ignore,
allowPrivatePackages: config.privatePackages.version,
})
Expand Down

0 comments on commit 26c8ba9

Please sign in to comment.