Skip to content

Commit

Permalink
Add support for ignored config (#371)
Browse files Browse the repository at this point in the history
* add ignored to the config object

* exclude ignored packages in release

* throw for mixed changesets

* Do not delete changeset files for ignored packages

* fix a bug where an unchanged package gets a patch release

* do not bump ignored packages in prereleases

* use Array.prototype.includes

* add input validation

* filter out ignored packages in flattenReleases()

* address comments

* correct typo

* add --ignore to cli

* rename ignored to ignore

* Update error message format

* add config tests

* add tests for apply-release-plan

* Add tests for assemble-release-plan

* address comment

* add tests for the version command

* add a test for the pre exit mode fix

* show all missing packages when validating --ignore flag

* fix lint errors

* Throws when --ignore flag and ignore in config are both present

* handle --ignore and ignore in config before calling version()

* change getDependents() to take a single option argument

* pass an option to determineDependents()

* add a test for incrementVersion()

* update test case description

* Update packages/assemble-release-plan/src/index.ts

Co-authored-by: Mateusz Burzy艅ski <mateuszburzynski@gmail.com>

* run prettier

* Require listing all dependents in the ignore array

* fix lint

* sort deps

* update test message

* add tests for version for cli

* fix tests + prettier

* refactor to make test easier

* run prettier

* Create rich-melons-press.md

* remove code for debugging

* add integration tests

* fix test case

* remove line breaks

* remove line break again

* run prettier

* Create proud-tips-allow.md

* Create proud-tips-allow.md

* Update rich-melons-press.md

* Update proud-tips-allow.md

* Update .changeset/rich-melons-press.md

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Update packages/cli/src/run.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Update packages/config/src/index.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Update packages/config/src/index.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Update .changeset/proud-tips-allow.md

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* Update packages/cli/src/run.ts

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>

* address comments

* fix lint issue

* add missing bracket

* fix merge issue

Co-authored-by: Mateusz Burzy艅ski <mateuszburzynski@gmail.com>
Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
3 people committed Jun 17, 2020
1 parent 9006375 commit 9dcc364
Show file tree
Hide file tree
Showing 25 changed files with 867 additions and 194 deletions.
6 changes: 6 additions & 0 deletions .changeset/proud-tips-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/config": minor
"@changesets/types": minor
---

Add `ignore` config option to configure ignored packages. The versions of ignored packages will not be bumped during a release, but their dependencies will still be bumped normally.
20 changes: 20 additions & 0 deletions .changeset/rich-melons-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@changesets/apply-release-plan": minor
"@changesets/assemble-release-plan": minor
"@changesets/cli": minor
---

Added support for ignoring packages in the `version` command. The version of ignored packages will not be bumped, but their dependencies will still be bumped normally. This is useful when you have private packages, e.g. packages under development. It allows you to make releases for the public packages without changing the version of your private packages. To use the feature, you can define the `ignore` array in the config file with the name of the packages:

```
{
...
"ignore": ["pkg-a", "pkg-b"]
...
}
```

or you can pass the package names to the `--ignore` flag when using cli:
```
yarn changeset version --ignore pkg-a --ignore --pkg-b
```
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore": ["pkg-a"]
}
11 changes: 11 additions & 0 deletions __fixtures__/simple-project-with-ignore-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"name": "simple-project",
"description": "three projects, each depending on one other",
"version": "1.0.0",
"bolt": {
"workspaces": [
"packages/*"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "pkg-a",
"version": "1.0.0",
"dependencies": {
"pkg-b": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pkg-b",
"version": "1.0.0"
}
45 changes: 45 additions & 0 deletions packages/apply-release-plan/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FakeReleasePlan {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -77,6 +78,7 @@ async function testSetup(
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -283,6 +285,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -343,6 +346,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -407,6 +411,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -489,6 +494,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -563,6 +569,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -637,6 +644,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -714,6 +722,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -796,6 +805,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -870,6 +880,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -944,6 +955,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies,
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1022,6 +1034,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: true,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1179,6 +1192,7 @@ describe("apply release plan", () => {
null
],
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1281,6 +1295,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1361,6 +1376,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1445,6 +1461,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1542,6 +1559,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "minor",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down Expand Up @@ -1739,6 +1757,32 @@ describe("apply release plan", () => {
let pathExists = await fs.pathExists(changesetPath);
expect(pathExists).toEqual(false);
});
it("should NOT delete changesets for ignored packages", async () => {
const releasePlan = new FakeReleasePlan();

let changesetPath: string;

const setupFunc = (tempDir: string) =>
Promise.all(
releasePlan.getReleasePlan().changesets.map(({ id, summary }) => {
const thisPath = path.resolve(tempDir, ".changeset", `${id}.md`);
changesetPath = thisPath;
const content = `---\n---\n${summary}`;
fs.writeFile(thisPath, content);
})
);

await testSetup(
"simple-project",
releasePlan.getReleasePlan(),
{ ...releasePlan.config, ignore: ["pkg-a"] },
setupFunc
);

// @ts-ignore this is possibly bad
let pathExists = await fs.pathExists(changesetPath);
expect(pathExists).toEqual(true);
});
it("should delete an old format changeset if it is applied", async () => {
const releasePlan = new FakeReleasePlan();

Expand Down Expand Up @@ -1914,6 +1958,7 @@ describe("apply release plan", () => {
access: "restricted",
baseBranch: "master",
updateInternalDependencies: "patch",
ignore: [],
___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH: {
onlyUpdatePeerDependentsWhenOutOfRange: false,
useCalculatedVersionForSnapshots: false
Expand Down
15 changes: 13 additions & 2 deletions packages/apply-release-plan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,19 @@ export default async function applyReleasePlan(
let changesetPath = path.resolve(changesetFolder, `${changeset.id}.md`);
let changesetFolderPath = path.resolve(changesetFolder, changeset.id);
if (await fs.pathExists(changesetPath)) {
touchedFiles.push(changesetPath);
await fs.remove(changesetPath);
// DO NOT remove changeset for ignored packages
// Mixed changeset that contains both ignored packages and not ignored packages are disallowed
// At this point, we know there is no such changeset, because otherwise the program would've already failed,
// so we just check if any ignored package exists in this changeset, and only remove it if none exists
// Ignored list is added in v2, so we don't need to do it for v1 changesets
if (
!changeset.releases.find(release =>
config.ignore.includes(release.name)
)
) {
touchedFiles.push(changesetPath);
await fs.remove(changesetPath);
}
// TO REMOVE LOGIC - this works to remove v1 changesets. We should be removed in the future
} else if (await fs.pathExists(changesetFolderPath)) {
touchedFiles.push(changesetFolderPath);
Expand Down
10 changes: 8 additions & 2 deletions packages/assemble-release-plan/src/determine-dependents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export default function getDependents({
packagesByName,
dependencyGraph,
preInfo,
ignoredPackages,
onlyUpdatePeerDependentsWhenOutOfRange
}: {
releases: Map<string, InternalRelease>;
packagesByName: Map<string, Package>;
dependencyGraph: Map<string, string[]>;
preInfo: PreInfo | undefined;
ignoredPackages: Readonly<string[]>;
onlyUpdatePeerDependentsWhenOutOfRange: boolean;
}): boolean {
let updated = false;
Expand Down Expand Up @@ -62,8 +64,12 @@ export default function getDependents({
nextRelease.name
);

// Firstly we check if it is a peerDependency because if it is, our dependent bump type needs to be major.
if (
// If the dependent is an ignored package, we want to bump its dependencies without a release, so setting type to "none"
if (ignoredPackages.includes(dependent)) {
type = "none";
}
// we check if it is a peerDependency because if it is, our dependent bump type needs to be major.
else if (
depTypes.includes("peerDependencies") &&
nextRelease.type !== "patch" &&
(!onlyUpdatePeerDependentsWhenOutOfRange ||
Expand Down
65 changes: 35 additions & 30 deletions packages/assemble-release-plan/src/flatten-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,47 @@ import { InternalRelease } from "./types";

export default function flattenReleases(
changesets: NewChangeset[],
packagesByName: Map<string, Package>
packagesByName: Map<string, Package>,
ignoredPackages: Readonly<string[]>
): Map<string, InternalRelease> {
let releases: Map<string, InternalRelease> = new Map();

changesets.forEach(changeset => {
changeset.releases.forEach(({ name, type }) => {
let release = releases.get(name);
let pkg = packagesByName.get(name);
if (!pkg) {
throw new Error(`Could not find package information for ${name}`);
}
if (!release) {
release = {
name,
type,
oldVersion: pkg.packageJson.version,
changesets: [changeset.id]
};
} else {
// If the type was already major, we never need to update it
if (release.type === "minor" && type === "major") {
release.type = type;
} else if (
release.type === "patch" &&
(type === "major" || type === "minor")
) {
release.type = type;
changeset.releases
// Filter out ignored packages because they should not trigger a release
// If their dependencies need updates, they will be added to releases by `determineDependents()` with release type `none`
.filter(({ name }) => !ignoredPackages.includes(name))
.forEach(({ name, type }) => {
let release = releases.get(name);
let pkg = packagesByName.get(name);
if (!pkg) {
throw new Error(`Could not find package information for ${name}`);
}
if (!release) {
release = {
name,
type,
oldVersion: pkg.packageJson.version,
changesets: [changeset.id]
};
} else {
// If the type was already major, we never need to update it
if (release.type === "minor" && type === "major") {
release.type = type;
} else if (
release.type === "patch" &&
(type === "major" || type === "minor")
) {
release.type = type;
}
// Check whether the bumpType will change
// If the bumpType has changed recalc newVersion
// push new changeset to releases
release.changesets.push(changeset.id);
}
// Check whether the bumpType will change
// If the bumpType has changed recalc newVersion
// push new changeset to releases
release.changesets.push(changeset.id);
}

releases.set(name, release);
});
releases.set(name, release);
});
});

return releases;
Expand Down
Loading

0 comments on commit 9dcc364

Please sign in to comment.