Repository: atlassian/changesets
Pull request #343 (2020-04-29 23:52:24)

fix: release shouldn't fail on a project that references itself

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

Latest commit: 428f4122230d7c1813aaf511909e7f2a7e727f58

**We got this.**

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

  | Name                           | Type  |
| ------------------------------ | ----- |
| @changesets/apply-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/skip-self-reference?filename=.changeset/late-flies-march.md&value=---%0A%22%40changesets%2Fapply-release-plan%22%3A%20patch%0A---%0A%0Afix%3A%20release%20shouldn't%20fail%20on%20a%20project%20that%20references%20itself%0A)


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

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

```diff
@@           Coverage Diff           @@
##           master     #343   +/-   ##
=======================================
  Coverage   79.84%   79.84%           
=======================================
  Files          40       40           
  Lines        1062     1062           
  Branches      240      240           
=======================================
  Hits          848      848           
  Misses        204      204           
  Partials       10       10           
```


| [Impacted Files](https://codecov.io/gh/atlassian/changesets/pull/343?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/apply-release-plan/src/version-package.ts](https://codecov.io/gh/atlassian/changesets/pull/343/diff?src=pr&el=tree#diff-cGFja2FnZXMvYXBwbHktcmVsZWFzZS1wbGFuL3NyYy92ZXJzaW9uLXBhY2thZ2UudHM=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/atlassian/changesets/pull/343?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/343?src=pr&el=footer). Last update [31aa728...b1995fe](https://codecov.io/gh/atlassian/changesets/pull/343?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

zkochan: yes, ignoring `file:` and `link:`  would work as well. I will update this.

Patch:
diff --git a/.changeset/quiet-pumpkins-fly.md b/.changeset/quiet-pumpkins-fly.md
new file mode 100644
index 0000000..68c87de
--- /dev/null
+++ b/.changeset/quiet-pumpkins-fly.md
@@ -0,0 +1,5 @@
+---
+"@changesets/apply-release-plan": patch
+---
+
+Self-references should be skipped when bumping versions. A self-reference is a dev dep that has the same name as the package. Some projects use self-references as a convinient way to require files using relative paths from the root directory.
diff --git a/__fixtures__/self-referenced/package.json b/__fixtures__/self-referenced/package.json
new file mode 100644
index 0000000..d7489d9
--- /dev/null
+++ b/__fixtures__/self-referenced/package.json
@@ -0,0 +1,7 @@
+{
+  "name": "self-referenced",
+  "version": "0.0.0",
+  "devDependencies": {
+    "self-referenced": "file:"
+  }
+}
diff --git a/packages/apply-release-plan/src/version-package.ts b/packages/apply-release-plan/src/version-package.ts
index af62a2c..bbac604 100644
--- a/packages/apply-release-plan/src/version-package.ts
+++ b/packages/apply-release-plan/src/version-package.ts
@@ -26,7 +26,12 @@ export default function versionPackage(
     if (deps) {
       for (let { name, version } of versionsToUpdate) {
         let depCurrentVersion = deps[name];
-        if (!depCurrentVersion) continue;
+        if (
+          !depCurrentVersion ||
+          depCurrentVersion.startsWith("file:") ||
+          depCurrentVersion.startsWith("link:")
+        )
+          continue;
         const usesWorkspaceRange = depCurrentVersion.startsWith("workspace:");
         if (usesWorkspaceRange) {
           depCurrentVersion = depCurrentVersion.substr(10);


Test patch:
diff --git a/packages/apply-release-plan/src/index.test.ts b/packages/apply-release-plan/src/index.test.ts
index 2cb9333..10ab996 100644
--- a/packages/apply-release-plan/src/index.test.ts
+++ b/packages/apply-release-plan/src/index.test.ts
@@ -300,6 +300,51 @@ describe("apply release plan", () => {
         version: "1.1.0"
       });
     });
+    it("should skip dependencies that have the same name as the package", async () => {
+      let { changedFiles } = await testSetup(
+        "self-referenced",
+        {
+          changesets: [
+            {
+              id: "quick-lions-devour",
+              summary: "Hey, let's have fun with testing!",
+              releases: [{ name: "self-referenced", type: "minor" }]
+            }
+          ],
+          releases: [
+            {
+              name: "self-referenced",
+              type: "minor",
+              oldVersion: "1.0.0",
+              newVersion: "1.1.0",
+              changesets: ["quick-lions-devour"]
+            }
+          ],
+          preState: undefined
+        },
+        {
+          changelog: false,
+          commit: false,
+          linked: [],
+          access: "restricted",
+          baseBranch: "master"
+        }
+      );
+      let pkgPath = changedFiles.find(a =>
+        a.endsWith(`self-referenced${path.sep}package.json`)
+      );
+
+      if (!pkgPath) throw new Error(`could not find an updated package json`);
+      let pkgJSON = await fs.readJSON(pkgPath);
+
+      expect(pkgJSON).toMatchObject({
+        name: "self-referenced",
+        version: "1.1.0",
+        devDependencies: {
+          "self-referenced": "file:"
+        }
+      });
+    });
   });
   describe("changelogs", () => {
     it("should update a changelog for one package", async () => {