Repository: atlassian/changesets
Pull request #344 (2020-04-30 09:29:06)

fix: bump dependent when both a dev dep and a prod dep are released
When both a dev dep and a prod dep of a dependent package are published, the version of the dependent package should be bumped. This fixes a regression introduced by #313.

changeset-bot[bot]: ###  🦋  Changeset is good to go

Latest commit: 4393ffc4c5514e80a67a7b5481de771c7e4d9c55

**We got this.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name                              | Type  |
| --------------------------------- | ----- |
| @changesets/assemble-release-plan | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/zkochan/changesets/new/fix/dev-dep-2?filename=.changeset/tender-birds-work.md&value=---%0A%22%40changesets%2Fassemble-release-plan%22%3A%20patch%0A---%0A%0Afix%3A%20bump%20dependent%20when%20both%20a%20dev%20dep%20and%20a%20prod%20dep%20are%20released%0A)


codecov[bot]: # [Codecov](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=h1) Report
> Merging [#344](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=desc) into [master](https://codecov.io/gh/atlassian/changesets/commit/31aa728b74182ad182f9d67312dcb17f3fbd90dd&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/atlassian/changesets/pull/344/graphs/tree.svg?width=650&height=150&src=pr&token=j0W25zrXm2)](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #344      +/-   ##
==========================================
+ Coverage   79.84%   79.88%   +0.03%     
==========================================
  Files          40       40              
  Lines        1062     1064       +2     
  Branches      240      241       +1     
==========================================
+ Hits          848      850       +2     
  Misses        204      204              
  Partials       10       10              
```


| [Impacted Files](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [.../assemble-release-plan/src/determine-dependents.ts](https://codecov.io/gh/atlassian/changesets/pull/344/diff?src=pr&el=tree#diff-cGFja2FnZXMvYXNzZW1ibGUtcmVsZWFzZS1wbGFuL3NyYy9kZXRlcm1pbmUtZGVwZW5kZW50cy50cw==) | `97.67% <100.00%> (+0.11%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=footer). Last update [31aa728...4393ffc](https://codecov.io/gh/atlassian/changesets/pull/344?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.changeset/lovely-papayas-promise.md b/.changeset/lovely-papayas-promise.md
new file mode 100644
index 0000000..9d69d40
--- /dev/null
+++ b/.changeset/lovely-papayas-promise.md
@@ -0,0 +1,5 @@
+---
+"@changesets/assemble-release-plan": patch
+---
+
+When both a dev dep and a prod dep of a dependent package are published, the version of the dependent package should be bumped. This fixes a regression introduced by #313.
diff --git a/__fixtures__/dev-and-prod-dep/.changeset/README.md b/__fixtures__/dev-and-prod-dep/.changeset/README.md
new file mode 100644
index 0000000..fd188f5
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/.changeset/README.md
@@ -0,0 +1,3 @@
+# We just want a file in here so git collects it
+
+For this we have deliberately not included a config file, as we want to test the defaults
\ No newline at end of file
diff --git a/__fixtures__/dev-and-prod-dep/.changeset/config.json b/__fixtures__/dev-and-prod-dep/.changeset/config.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/.changeset/config.json
@@ -0,0 +1,1 @@
+{}
diff --git a/__fixtures__/dev-and-prod-dep/package.json b/__fixtures__/dev-and-prod-dep/package.json
new file mode 100644
index 0000000..2e742d8
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/package.json
@@ -0,0 +1,11 @@
+{
+  "private": true,
+  "name": "simple-project",
+  "description": "three projects, each depending on one other",
+  "version": "1.0.0",
+  "bolt": {
+    "workspaces": [
+      "packages/*"
+    ]
+  }
+}
diff --git a/__fixtures__/dev-and-prod-dep/packages/pkg-a/package.json b/__fixtures__/dev-and-prod-dep/packages/pkg-a/package.json
new file mode 100644
index 0000000..b075657
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/packages/pkg-a/package.json
@@ -0,0 +1,10 @@
+{
+  "name": "pkg-a",
+  "version": "1.0.0",
+  "dependencies": {
+    "pkg-b": "1.0.0"
+  },
+  "devDependencies": {
+    "pkg-c": "1.0.0"
+  }
+}
diff --git a/__fixtures__/dev-and-prod-dep/packages/pkg-b/package.json b/__fixtures__/dev-and-prod-dep/packages/pkg-b/package.json
new file mode 100644
index 0000000..be4760e
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/packages/pkg-b/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "pkg-b",
+  "version": "1.0.0"
+}
diff --git a/__fixtures__/dev-and-prod-dep/packages/pkg-c/package.json b/__fixtures__/dev-and-prod-dep/packages/pkg-c/package.json
new file mode 100644
index 0000000..888ba5c
--- /dev/null
+++ b/__fixtures__/dev-and-prod-dep/packages/pkg-c/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "pkg-c",
+  "version": "1.0.0"
+}
diff --git a/packages/assemble-release-plan/src/determine-dependents.ts b/packages/assemble-release-plan/src/determine-dependents.ts
index cd1ebaf..d0903c9 100644
--- a/packages/assemble-release-plan/src/determine-dependents.ts
+++ b/packages/assemble-release-plan/src/determine-dependents.ts
@@ -67,7 +67,8 @@ export default function getDependents(
         } else {
           if (
             // TODO validate this - I don't think it's right anymore
-            !releases.has(dependent) &&
+            (!releases.has(dependent) ||
+              releases.get(dependent)!.type === "none") &&
             !semver.satisfies(
               incrementVersion(nextRelease, preInfo),
               versionRange
@@ -85,6 +86,9 @@ export default function getDependents(
             }
           }
         }
+        if (releases.has(dependent) && releases.get(dependent)!.type === type) {
+          type = undefined;
+        }
         return { name: dependent, type, pkgJSON: dependentPackage.packageJson };
       })
       .filter(({ type }) => type)


Test patch:
diff --git a/packages/assemble-release-plan/src/index.test.ts b/packages/assemble-release-plan/src/index.test.ts
index f20dc57..a8055b8 100644
--- a/packages/assemble-release-plan/src/index.test.ts
+++ b/packages/assemble-release-plan/src/index.test.ts
@@ -115,6 +115,33 @@ describe("assemble-release-plan", () => {
     expect(releases[1].name).toEqual("pkg-b");
     expect(releases[1].newVersion).toEqual("1.0.0");
   });
+  it("should assemble release plan with dependent when the dependent has both a changed prod and dev dependency", () => {
+    setup.updateDevDependency("pkg-b", "pkg-a", "^1.0.0");
+    setup.updateDependency("pkg-b", "pkg-c", "^1.0.0");
+    setup.addChangeset({
+      id: "big-cats-delight",
+      releases: [
+        { name: "pkg-a", type: "major" },
+        { name: "pkg-c", type: "major" }
+      ]
+    });
+
+    let { releases } = assembleReleasePlan(
+      setup.changesets,
+      setup.packages,
+      defaultConfig,
+      undefined
+    );
+
+    expect(releases.length).toEqual(3);
+    expect(releases[0].name).toEqual("pkg-a");
+    expect(releases[0].newVersion).toEqual("2.0.0");
+    expect(releases[1].name).toEqual("pkg-c");
+    expect(releases[1].newVersion).toEqual("2.0.0");
+    expect(releases[2].name).toEqual("pkg-b");
+    expect(releases[2].oldVersion).toEqual("1.0.0");
+    expect(releases[2].newVersion).toEqual("1.0.1");
+  });
   it("should assemble release plan without dependent through the link protocol", () => {
     setup.updateDevDependency("pkg-b", "pkg-a", "link:../pkg-a");
     setup.addChangeset({