Skip to content

Commit

Permalink
Fix a bug with linked packages where it would break if there was a li…
Browse files Browse the repository at this point in the history
…nked package that didn't have a changeset (#33)

* Fix a bug with linked packages where it would break if there was a linked package that didn't have a changeset

* Add a changeset
  • Loading branch information
emmatown authored and Noviny committed May 7, 2019
1 parent 4498cd8 commit 079eaba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changeset/9c2cafae/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "@changesets/cli", "type": "patch" }],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/9c2cafae/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug with linked packages where it would break if there was a linked package that didn't have a changeset
15 changes: 15 additions & 0 deletions packages/cli/src/commands/bump/__tests__/consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ describe("running version in a simple project", () => {
);
});

it("should not break when there is a linked package without a changeset", async () => {
const cwd2 = await copyFixtureIntoTempDir(__dirname, "linked-packages");
const spy = jest.spyOn(fs, "writeFile");
await writeChangesets([simpleChangeset], cwd2);

await versionCommand({ cwd: cwd2 });
const calls = spy.mock.calls;

expect(JSON.parse(calls[0][1])).toEqual(
expect.objectContaining({ name: "pkg-a", version: "1.1.0" })
);

expect(spy).toHaveBeenCalledTimes(2);
});

describe("when there are multiple changeset commits", () => {
it("should bump releasedPackages", async () => {
await writeChangesets([simpleChangeset, simpleChangeset2], cwd);
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/utils/createRelease/flattenChangesets.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ export default function flattenReleases(changesets, allLinkedPackages) {
const allBumpTypes = [];
for (let linkedPackage of linkedPackages) {
let release = flatReleases.get(linkedPackage);
allBumpTypes.push(release.type);
if (release) {
allBumpTypes.push(release.type);
}
}
const highestBumpType = maxType(allBumpTypes);
for (let linkedPackage of linkedPackages) {
let release = flatReleases.get(linkedPackage);
release.type = highestBumpType;
if (release) {
release.type = highestBumpType;
}
}
}

Expand Down

0 comments on commit 079eaba

Please sign in to comment.