UNPKG

6.37 kBMarkdownView Raw
1## @changesets/cli 🦋
2
3[![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/@changesets/cli)
4
5The primary implementation of [changesets](https://github.com/Noviny/changesets). Helps you manage the versioning
6and changelog entries for your packages, with a focus on versioning within a mono-repository (though we support
7single-package repositories too).
8
9This package is intended as a successor to `@atlaskit/build-releases` with a more general focus. It works in
10[bolt](https://www.npmjs.com/package/bolt) multi-package repositories, [yarn workspaces] multi-package repositories, and
11in single-package repositories.
12
13## Getting Started
14
15If you are installing this in a monorepo run
16
17```
18yarn add @changesets/cli
19yarn changeset init
20```
21
22otherwise run
23
24```
25yarn add --dev @changesets/cli
26yarn changeset init
27```
28
29From here you are set up to use changesets. Add your first changeset by running
30
31```
32yarn changeset
33```
34
35and following the prompts that you are presented with.
36
37Below you can find a basic workflow for maintainers to help them use changesets, which you can vary to meet your own needs.
38
39## Core Concepts
40
41The core concept that `changesets` follows is that contributors to a repository should be able to declare an intent to release, and that multiple intents should be able to be combined sensibly. Sensibly here refers to if there is one intent to release button as a 'minor' and another to release button as a 'patch', only one release will be made, at the higher of the two versions.
42
43A single `changeset` is an intent to release stored as data, with the information we need to combine multiple changesets and coordinate releases. It will also update internal dependencies within a multi-package repository.
44
45## Base workflow
46
47Contributor runs:
48
49```
50yarn changeset
51```
52
53or
54
55```
56npx changeset
57```
58
59and answers the provided questions.
60
61When the maintainer wants to release packages, they should run
62
63```
64yarn changeset version
65```
66
67or
68
69```
70npx changeset version
71```
72
73and then
74
75```
76yarn changeset publish
77```
78
79or
80
81```
82npx changeset publish
83```
84
85The commands are explained further below.
86
87## Commands
88
89### init
90
91```
92changeset init
93```
94
95This command sets up the `.changeset` folder. It generates a readme and a config file. The config file includes the default options, as well as comments on what these options represent. You should run this command once, when you are setting up `changesets`.
96
97### add
98
99```
100changeset [--empty]
101```
102
103or
104
105```
106changeset add [--empty]
107```
108
109This command will ask you a series of questions, first about what packages you want to release, then what semver bump type for each package, then it will ask for a summary of the entire changeset. At the final step it will show the changeset it will generate, and confirm that you want to add it.
110
111Once confirmed, the changeset will be write a Markdown file that contains the summary and YAML front matter which stores the packages that will be released and the semver bump types for them.
112
113A changeset that major bumps `@changesets/cli` would look like this:
114
115```md
116---
117"@changesets/cli": major
118---
119
120A description of the major changes.
121```
122
123If you want to modify this file after it's generated, that's completely fine or if you want to write changeset files yourself, that's also fine.
124
125- `--empty` - allows you to create an empty changeset if no packages are being bumped, usually only required if you have CI that blocks merges without a changeset.
126
127A changeset created with the `empty` flag would look like this:
128
129```md
130---
131---
132```
133
134If you set the `commit` option in the config, the command will add the updated changeset files and then commit them.
135
136### version
137
138```
139changeset version
140```
141
142Updates the versions for all packages described in changesets since last release along with any dependents inside the repo that are out of range.
143
144Will also create/append to a CHANGELOG file for each package using the summaries from the changesets.
145
146We recommend making sure changes made from this commmand are merged back into master before you run `publish`.
147
148This command will read then delete changesets on disk, ensuring that they are only used once.
149
150### publish
151
152```
153changeset publish [--otp={token}]
154```
155
156Publishes to NPM repo, and creates git tags. Because this command assumes that last commit is the release commit you should not commit any changes between calling `version` and `publish`. These commands are separate to enable you to check if release commit is acurate.
157
158- `--otp={token}` - allows you to provide an npm one-time password if you have auth and writes enabled on npm. The CLI also prompts for the OTP if it's not provided with the `--otp` option.
159
160**NOTE:** You will still need to push your changes back to master after this
161
162```
163git push --follow-tags
164```
165
166### status
167
168```
169status [--verbose] [--output={filePath}] [--since={gitTag}]
170```
171
172The status command provides information about the changesets that currently exist. If there are no changesets present, it exits with an error status code.
173
174- `--verbose` - use if you want to know the new versions, and get a link to the relevant changeset summary.
175
176- `--output` - allows you to write the json object of the status out, for consumption by other tools, such as CI.
177
178- `--since` - to only display information about changesets since a specific branch or git tag. While this can be
179 used to add a CI check for changesets, we recommend not doing this. We instead recommend using the [changeset bot](https://github.com/apps/changeset-bot)
180 to detect pull requests missing changesets, as not all pull requests need one.
181
182### pre
183
184```
185pre [exit|enter {tag}]
186```
187
188The pre command enters and exits pre mode. The command does not do any actual versioning, when doing a prerelease, you should run `changeset pre enter next`(or a different tag, the tag is what is in versions and is the npm dist tag) and then do the normal release process with `changeset version` and `changeset publish`. For more information about the pre command, see [the prereleases documentation](https://github.com/atlassian/changesets/blob/master/docs/prereleases.md).
189
190### Bumping peerDependencies
191
192In almost all circumstances, internal packages will be bumped as a patch. The one exception is when the dependency is a `peerDependency`, in which case the change will become a major.