Skip to content

Commit

Permalink
Only bump peer dependents when leaving range using an experimental fl…
Browse files Browse the repository at this point in the history
…ag (#383)

* add experimental option onlyUpdatePeerDependentsWhenOutOfRange

* support onlyUpdatePeerDependentsWhenOutOfRange

* run prettier

* Create new-pianos-act.md

* Update new-pianos-act.md

* fix type errors

* update type

* rename to ___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH

* bump major for packages that uses a config object

* run prettier

* Do not bump peerDependencies if they are still in range

* run prettier

* address comment

* run prettier

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
Feiyang1 and emmatown committed Jun 8, 2020
1 parent 00e768e commit addd725
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 58 deletions.
9 changes: 9 additions & 0 deletions .changeset/new-pianos-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@changesets/assemble-release-plan": major
"@changesets/apply-release-plan": major
"@changesets/get-release-plan": major
"@changesets/config": patch
"@changesets/types": patch
---

Added an experimental flag `onlyUpdatePeerDependentsWhenOutOfRange`. When set to `true`, we only bump peer dependents when peerDependencies are leaving range.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "has-peer-dep",
"version": "1.0.0",
"peerDependencies": {
"depended-upon": "~1.0.0"
"depended-upon": "^1.0.0"
}
}
22 changes: 17 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,7 +2,7 @@ import { ChangelogFunctions, NewChangesetWithCommit } from "@changesets/types";

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

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

Expand Down Expand Up @@ -62,10 +68,16 @@ export default async function generateMarkdown(
const versionRange = dependencyVersionRange || peerDependencyVersionRange;
return (
versionRange &&
shouldUpdateInternalDependency(
updateInternalDependencies,
shouldUpdateDependencyBasedOnConfig(
{ type: rel.type, version: rel.newVersion },
versionRange
{
depVersionRange: versionRange,
depType: dependencyVersionRange ? "dependencies" : "peerDependencies"
},
{
minReleaseType: updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange
}
)
);
});
Expand Down
162 changes: 144 additions & 18 deletions packages/apply-release-plan/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class FakeReleasePlan {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
};

this.changesets = [baseChangeset, ...changesets];
Expand Down Expand Up @@ -72,7 +75,10 @@ async function testSetup(
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
};
}
let tempDir = await f.copy(fixtureName);
Expand Down Expand Up @@ -274,7 +280,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -330,7 +339,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPath = changedFiles.find(a =>
Expand Down Expand Up @@ -390,7 +402,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -468,7 +483,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -538,7 +556,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -608,7 +629,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -681,7 +705,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -759,7 +786,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -829,7 +859,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -899,7 +932,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies
updateInternalDependencies,
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgPathA = changedFiles.find(a =>
Expand Down Expand Up @@ -933,6 +969,78 @@ describe("apply release plan", () => {
});
});
});

describe("onlyUpdatePeerDependentsWhenOutOfRange set to true", () => {
it("should not bump peerDependencies if they are still in range", async () => {
let { changedFiles } = await testSetup(
"simple-caret-peer-dep",
{
changesets: [
{
id: "quick-lions-devour",
summary: "Hey, let's have fun with testing!",
releases: [
{ name: "has-peer-dep", type: "patch" },
{ name: "depended-upon", type: "patch" }
]
}
],
releases: [
{
name: "has-peer-dep",
type: "patch",
oldVersion: "1.0.0",
newVersion: "1.0.1",
changesets: ["quick-lions-devour"]
},
{
name: "depended-upon",
type: "patch",
oldVersion: "1.0.0",
newVersion: "1.0.1",
changesets: ["quick-lions-devour"]
}
],
preState: undefined
},
{
changelog: false,
commit: false,
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: true
}
}
);
let pkgPathDependent = changedFiles.find(a =>
a.endsWith(`has-peer-dep${path.sep}package.json`)
);
let pkgPathDepended = changedFiles.find(b =>
b.endsWith(`depended-upon${path.sep}package.json`)
);

if (!pkgPathDependent || !pkgPathDepended) {
throw new Error(`could not find an updated package json`);
}
let pkgJSONDependent = await fs.readJSON(pkgPathDependent);
let pkgJSONDepended = await fs.readJSON(pkgPathDepended);

expect(pkgJSONDependent).toMatchObject({
name: "has-peer-dep",
version: "1.0.1",
peerDependencies: {
"depended-upon": "^1.0.0"
}
});
expect(pkgJSONDepended).toMatchObject({
name: "depended-upon",
version: "1.0.1"
});
});
});
});
describe("changelogs", () => {
it("should update a changelog for one package", async () => {
Expand Down Expand Up @@ -1057,7 +1165,10 @@ describe("apply release plan", () => {
path.resolve(__dirname, "test-utils/simple-get-changelog-entry"),
null
],
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);
let pkgAChangelogPath = changedFiles.find(a =>
Expand Down Expand Up @@ -1155,7 +1266,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);

Expand Down Expand Up @@ -1231,7 +1345,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor"
updateInternalDependencies: "minor",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);

Expand Down Expand Up @@ -1311,7 +1428,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor"
updateInternalDependencies: "minor",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);

Expand Down Expand Up @@ -1404,7 +1524,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor"
updateInternalDependencies: "minor",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);

Expand Down Expand Up @@ -1772,7 +1895,10 @@ describe("apply release plan", () => {
linked: [],
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch"
updateInternalDependencies: "patch",
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false
}
}
);

Expand Down
18 changes: 12 additions & 6 deletions packages/apply-release-plan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ export default async function applyReleasePlan(

// iterate over releases updating packages
let finalisedRelease = releaseWithChangelogs.map(release => {
return versionPackage(
release,
versionsToUpdate,
config.updateInternalDependencies
);
return versionPackage(release, versionsToUpdate, {
updateInternalDependencies: config.updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange:
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
.onlyUpdatePeerDependentsWhenOutOfRange
});
});

let prettierConfig = await prettier.resolveConfig(cwd);
Expand Down Expand Up @@ -210,7 +211,12 @@ async function getNewChangelogEntry(
moddedChangesets,
getChangelogFuncs,
changelogOpts,
config.updateInternalDependencies
{
updateInternalDependencies: config.updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange:
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
.onlyUpdatePeerDependentsWhenOutOfRange
}
);

return {
Expand Down
Loading

0 comments on commit addd725

Please sign in to comment.