Skip to content

Commit

Permalink
Prereleases (#183)
Browse files Browse the repository at this point in the history
* Fix changelog generator options not being provided to changelog generators

* First iteration of docs on prereleases

* i don't know why this exists on this branch

* Implement prerelease command(I know things aren't in the ideal places probably, I want to have an implement that works and is what we want first and things in the right places second)

* Publish things implemented. Easy parts are done!

* It maybe works

* A thing that I want to commit because I want to change branches

* things

* I should really write tests for this

* A bunch of stuff

* Various things

* Fix some stuff

* Await the things

* A lot of stuff

* so... yes. tests are in fact a Good Thing

* Move a thing

* It works 🦋🎉 + rdom other changes because i'm bad and don't split up PRs enough

* Fix TS things

* Actually use the thing I wrote

* these things might work

* Fix all the linting errors

* Some things

* More things

* another

* Store used changesets and filter them out when doing successive prereleases

* Consistently use PreState | undefined instead of making PreState optional

* More tests and some little changes

* Linting

* It's not flakey 🎉

* Warnings for things

* Remove verdaccio because I didn't end up writing those publish tests and don't want to block this PR on them

* This is why tests are good

* Add changesets and a README to pre

* Docs and some logging

* And this is why you should run tests rather than assuming that the change you made fixed them

* Tests

* Linting

* Add another test

* Always publish packages if they don't exist on npm rather than only if they are a greater version than the latest version on npm

* Don't use snapshots in some places because I think they're gonna be annoying

* Remove the .only

* Fix bugs and independent pre versions except for linked packages

* Update docs

* Fix TS, linting and an opinion

* Fix pre warning to only show up when actually in pre and make important end lines red
  • Loading branch information
emmatown committed Oct 31, 2019
1 parent dfd7e24 commit 8f0a1ef
Show file tree
Hide file tree
Showing 69 changed files with 1,420 additions and 271 deletions.
7 changes: 7 additions & 0 deletions .changeset/cold-impalas-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@changesets/assemble-release-plan": minor
"@changesets/apply-release-plan": minor
"@changesets/get-release-plan": minor
---

Add support for prereleases. For more information, see [the docs on prereleases](https://github.com/atlassian/changesets/blob/master/docs/prereleases.md).
5 changes: 5 additions & 0 deletions .changeset/forty-hairs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/types": minor
---

Add `PreState` type and `preState` property to `ReleasePlan`
6 changes: 6 additions & 0 deletions .changeset/ninety-flowers-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/cli": patch
"@changesets/errors": patch
---

Add `InternalError` for errors which are unexpected and if they occur, an issue should be opened. The CLI catches the error and logs a link for users to open an issue with the error and versions of Node and Changesets filled in
5 changes: 5 additions & 0 deletions .changeset/olive-kings-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": minor
---

Add support for prereleases. Prereleases work with two new commands, `pre enter` and `pre exit` along with changes to `version` and `exit`. For more information, see [the docs on prereleases](https://github.com/atlassian/changesets/blob/master/docs/prereleases.md).
6 changes: 6 additions & 0 deletions .changeset/proud-kangaroos-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/errors": patch
"@changesets/pre": patch
---

Add `PreExitButNotInPreModeError` and `PreEnterButInPreModeError`
5 changes: 5 additions & 0 deletions .changeset/sour-plants-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Always publish packages if they don't exist on npm rather than only if they are a greater version than the latest version on npm
5 changes: 5 additions & 0 deletions .changeset/wise-dingos-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/pre": minor
---

Initial release
File renamed without changes.
File renamed without changes.
File renamed without changes.
137 changes: 137 additions & 0 deletions docs/prereleases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Prereleases

You might want to release a version of your packages before you do an actual release, Changesets lets you do this but there are some caveats because of the complexity that monorepos add that are important to understand.

When you want to do a prerelease, you need to enter prerelease mode. You can do that with the `pre enter <tag>`. The tag that you need to pass is used in versions(e.g. `1.0.0-beta.0`) and for the npm dist tag.

A prerelease workflow might look something like this:

```bash
yarn changeset pre enter next
yarn changeset version
git add .
git commit -m "Enter prerelease mode and version packages"
yarn changeset publish
git push --follow-tags
```

Let's go through what's happening here. For this example, let's say you have a repo that looks like this:

```
packages/
pkg-a@1.0.0 has dep on pkg-b@^2.0.0
pkg-b@2.0.0 has no deps
pkg-c@3.0.0 has no deps
.changeset/
pkg-b@minor
```

```
yarn changeset prerelease next
```

This command changes Changesets into prerelease mode which creates a `pre.json` file in the `.changeset` directory which stores information about the state the prerelease is in. For the specific data stored in the `pre.json` file, see the type definition of `PreState` in [`@changesets/types`](https://github.com/atlassian/changesets/tree/master/packages/types).

```
yarn changeset version
```

This command will version packages as you would normally expect but append `-next.0`. An important note is that this will bump dependent packages that wouldn't be bumped in normal releases because prerelease versions are not satisfied by most semver ranges.(e.g. `^5.0.0` is not satisfied by `5.1.0-next.0`)

The repo would now look like this:

```
packages/
pkg-a@1.0.1-next.0 has dep on pkg-b@^2.0.1
pkg-b@2.1.0-next.0 has no deps
pkg-c@3.0.0 has no deps
.changeset/
```

```
yarn changeset publish
```

This command will publish to npm as the publish command normally does though it will set the dist tag to the tag you specified when running the prerelease command.

When you want to do another prerelease, your workflow would look something like this:

```bash
yarn changeset version
git add .
git commit -m "Version packages"
yarn changeset publish
git push --follow-tags
```

Let's say we add some changesets and a new package so our repo looks like this

```
packages/
pkg-a@1.0.1-next.0 has dep on pkg-b@^2.0.1
pkg-b@2.1.0-next.0 has no deps
pkg-c@3.0.0 has no deps
pkg-d@0.0.0 has no deps
.changeset/
pkg-a@minor
pkg-c@patch
pkg-d@major
```

```
yarn changeset version
```

The version command will behave just like it does for the first versioning of a prerelease except the number at the end will be updated. The repo would now look like this:

```
packages/
pkg-a@1.1.0-next.1 has dep on pkg-b@^2.0.1
pkg-b@2.1.0-next.0 has no deps
pkg-c@3.0.1-next.0 has no deps
pkg-d@1.0.0-next.0 has no deps
```

```
yarn changeset publish
```

This command will publish to npm just like it does for the first prerelease except because we're adding a new package(we need to define this, is it new to the repo or new to npm? I'm thinking new to npm), the new package will be published with the `latest` dist tag rather than the `next` tag because it's the first time it's being published which means it will be on `latest` anyway. For future publishes until pkg-d is out of prerelease, it will also be published to `latest`.

When you're ready to do the final release, your workflow would look something like this:

```bash
yarn changeset pre exit
yarn changeset version
git add .
git commit -m "Exit prerelease mode and version packages"
yarn changeset publish
git push --follow-tags
```

```
yarn changeset pre exit
```

This command will set an intent to exit prerelease mode in the `pre.json` file though it won't do any actual versioning.

```
yarn changeset version
```

The version command will apply any changesets currently in the repo and then remove the prerelease tag from the versions. The repo would now look like this:

```
packages/
pkg-a@1.1.0 has dep on pkg-b@^2.0.1
pkg-b@2.1.0 has no deps
pkg-c@3.0.1 has no deps
pkg-d@1.0.0 has no deps
```

```
yarn changeset publish
```

The publish command will publish everything to the `latest` dist tag as normal.
3 changes: 0 additions & 3 deletions fixtures/pinned-caret-tilde-dependents/.changeset/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions fixtures/pinned-caret-tilde-dependents/package.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/simple-project/.changeset/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions fixtures/simple-project/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions fixtures/simple-project/packages/pkg-a/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions fixtures/simple-project/packages/pkg-b/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions fixtures/simple-tilde-peer-dep/.changeset/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions fixtures/simple-tilde-peer-dep/package.json

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"packages": [
"packages/*"
]
},
"jest": {
"clearMocks": true
}
}
9 changes: 6 additions & 3 deletions packages/apply-release-plan/src/createVersionCommit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ let simpleReleasePlan: ReleasePlan = {
newVersion: "1.1.0",
changesets: [simpleChangeset.id]
}
]
],
preState: undefined
};

let secondReleasePlan: ReleasePlan = {
Expand All @@ -47,7 +48,8 @@ let secondReleasePlan: ReleasePlan = {
newVersion: "1.1.0",
changesets: [simpleChangeset2.id]
}
]
],
preState: undefined
};

describe("createReleaseCommit", () => {
Expand Down Expand Up @@ -93,7 +95,8 @@ describe("createReleaseCommit", () => {
newVersion: "1.1.0",
changesets: [simpleChangeset2.id]
}
]
],
preState: undefined
};
const commitStr = createReleaseCommit(releasePlan, false);
expect(commitStr).toEqual(outdent`
Expand Down
Loading

0 comments on commit 8f0a1ef

Please sign in to comment.