Skip to content

Commit

Permalink
Fix dependency release lines being output when they were skipped via …
Browse files Browse the repository at this point in the history
…the updateInternalDependencies config option (#361)
  • Loading branch information
Blasz committed May 12, 2020
1 parent 13406e9 commit 52a88ce
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .changeset/moody-flies-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/apply-release-plan": patch
"@changesets/cli": patch
---

Fix dependency release lines being output when they were skipped via the updateInternalDependencies config option
16 changes: 11 additions & 5 deletions packages/apply-release-plan/src/get-changelog-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangelogFunctions, NewChangesetWithCommit } from "@changesets/types";

import { ModCompWithPackage } from "@changesets/types";
import startCase from "lodash.startcase";
import { shouldUpdateInternalDependencies } from "./utils";

type ChangelogLines = {
major: Array<Promise<string>>;
Expand All @@ -26,7 +27,8 @@ export default async function generateMarkdown(
releases: ModCompWithPackage[],
changesets: NewChangesetWithCommit[],
changelogFuncs: ChangelogFunctions,
changelogOpts: any
changelogOpts: any,
updateInternalDependencies: "patch" | "minor"
) {
if (release.type === "none") return null;

Expand All @@ -50,11 +52,15 @@ export default async function generateMarkdown(
});

let dependentReleases = releases.filter(rel => {
const isDependency =
release.packageJson.dependencies &&
release.packageJson.dependencies[rel.name];
const isPeerDependency =
release.packageJson.peerDependencies &&
release.packageJson.peerDependencies[rel.name];
return (
(release.packageJson.dependencies &&
release.packageJson.dependencies[rel.name]) ||
(release.packageJson.peerDependencies &&
release.packageJson.peerDependencies[rel.name])
(isDependency || isPeerDependency) &&
shouldUpdateInternalDependencies(updateInternalDependencies, rel.type)
);
});

Expand Down
271 changes: 265 additions & 6 deletions packages/apply-release-plan/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "patch" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -427,7 +430,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "minor" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -494,7 +500,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "major" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -564,7 +573,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "patch" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -631,7 +643,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "minor" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -698,7 +713,10 @@ describe("apply release plan", () => {
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [{ name: "pkg-a", type: "patch" }]
releases: [
{ name: "pkg-a", type: "major" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
Expand Down Expand Up @@ -939,6 +957,247 @@ describe("apply release plan", () => {
].join("\n")
);
});

it("should add an updated dependencies line when dependencies have been updated", async () => {
let { changedFiles } = await testSetup(
"internal-dependencies",
{
changesets: [
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [
{ name: "pkg-a", type: "patch" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
{
name: "pkg-a",
type: "patch",
oldVersion: "1.0.3",
newVersion: "1.0.4",
changesets: ["quick-lions-devour"]
},
{
name: "pkg-b",
type: "patch",
oldVersion: "1.2.0",
newVersion: "1.2.1",
changesets: ["quick-lions-devour"]
}
],
preState: undefined
},
{
changelog: [
path.resolve(__dirname, "test-utils/simple-get-changelog-entry"),
null
],
commit: false,
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
}
);

let readmePath = changedFiles.find(a =>
a.endsWith(`pkg-a${path.sep}CHANGELOG.md`)
);
let readmePathB = changedFiles.find(a =>
a.endsWith(`pkg-b${path.sep}CHANGELOG.md`)
);

if (!readmePath || !readmePathB)
throw new Error(`could not find an updated changelog`);
let readme = await fs.readFile(readmePath, "utf-8");
let readmeB = await fs.readFile(readmePathB, "utf-8");

expect(readme.trim()).toEqual(outdent`# pkg-a
## 1.0.4
### Patch Changes
- Hey, let's have fun with testing!
- Updated dependencies [undefined]
- pkg-b@1.2.1`);

expect(readmeB.trim()).toEqual(outdent`# pkg-b
## 1.2.1
### Patch Changes
- Hey, let's have fun with testing!
- Updated dependencies [undefined]
- pkg-a@1.0.4`);
});

it("should NOT add updated dependencies line if dependencies have NOT been updated", async () => {
let { changedFiles } = await testSetup(
"internal-dependencies",
{
changesets: [
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [
{ name: "pkg-a", type: "patch" },
{ name: "pkg-b", type: "patch" }
]
}
],
releases: [
{
name: "pkg-a",
type: "patch",
oldVersion: "1.0.3",
newVersion: "1.0.4",
changesets: ["quick-lions-devour"]
},
{
name: "pkg-b",
type: "patch",
oldVersion: "1.2.0",
newVersion: "1.2.1",
changesets: ["quick-lions-devour"]
}
],
preState: undefined
},
{
changelog: [
path.resolve(__dirname, "test-utils/simple-get-changelog-entry"),
null
],
commit: false,
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor"
}
);

let readmePath = changedFiles.find(a =>
a.endsWith(`pkg-a${path.sep}CHANGELOG.md`)
);
let readmePathB = changedFiles.find(a =>
a.endsWith(`pkg-b${path.sep}CHANGELOG.md`)
);

if (!readmePath || !readmePathB)
throw new Error(`could not find an updated changelog`);
let readme = await fs.readFile(readmePath, "utf-8");
let readmeB = await fs.readFile(readmePathB, "utf-8");

expect(readme.trim()).toEqual(outdent`# pkg-a
## 1.0.4
### Patch Changes
- Hey, let's have fun with testing!`);

expect(readmeB.trim()).toEqual(outdent`# pkg-b
## 1.2.1
### Patch Changes
- Hey, let's have fun with testing!`);
});

it("should only add updated dependencies line for dependencies that have been updated", async () => {
let { changedFiles } = await testSetup(
"internal-dependencies",
{
changesets: [
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [
{ name: "pkg-a", type: "patch" },
{ name: "pkg-b", type: "patch" },
{ name: "pkg-c", type: "minor" }
]
}
],
releases: [
{
name: "pkg-a",
type: "patch",
oldVersion: "1.0.3",
newVersion: "1.0.4",
changesets: ["quick-lions-devour"]
},
{
name: "pkg-b",
type: "patch",
oldVersion: "1.2.0",
newVersion: "1.2.1",
changesets: ["quick-lions-devour"]
},
{
name: "pkg-c",
type: "minor",
oldVersion: "2.0.0",
newVersion: "2.1.0",
changesets: ["quick-lions-devour"]
}
],
preState: undefined
},
{
changelog: [
path.resolve(__dirname, "test-utils/simple-get-changelog-entry"),
null
],
commit: false,
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor"
}
);

let readmePath = changedFiles.find(a =>
a.endsWith(`pkg-a${path.sep}CHANGELOG.md`)
);
let readmePathB = changedFiles.find(a =>
a.endsWith(`pkg-b${path.sep}CHANGELOG.md`)
);
let readmePathC = changedFiles.find(a =>
a.endsWith(`pkg-c${path.sep}CHANGELOG.md`)
);

if (!readmePath || !readmePathB || !readmePathC)
throw new Error(`could not find an updated changelog`);
let readme = await fs.readFile(readmePath, "utf-8");
let readmeB = await fs.readFile(readmePathB, "utf-8");
let readmeC = await fs.readFile(readmePathC, "utf-8");

expect(readme.trim()).toEqual(outdent`# pkg-a
## 1.0.4
### Patch Changes
- Hey, let's have fun with testing!`);

expect(readmeB.trim()).toEqual(outdent`# pkg-b
## 1.2.1
### Patch Changes
- Hey, let's have fun with testing!
- Updated dependencies [undefined]
- pkg-c@2.1.0`);

expect(readmeC.trim()).toEqual(outdent`# pkg-c
## 2.1.0
### Minor Changes
- Hey, let's have fun with testing!`);
});
});
describe("should error and not write if", () => {
// This is skipped as *for now* we are assuming we have been passed
Expand Down
Loading

0 comments on commit 52a88ce

Please sign in to comment.