Skip to content

Commit 2288b3a

Browse files
authored
feat(version): bump prerelease versions from conventional commits (#3362)
1 parent 0f785e4 commit 2288b3a

File tree

16 files changed

+218
-3
lines changed

16 files changed

+218
-3
lines changed

commands/version/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Running `lerna version --conventional-commits` without the above flags will rele
5555
- [`--conventional-commits`](#--conventional-commits)
5656
- [`--conventional-graduate`](#--conventional-graduate)
5757
- [`--conventional-prerelease`](#--conventional-prerelease)
58+
- [`--conventional-bump-prerelease`](#--conventional-bump-prerelease)
5859
- [`--create-release <type>`](#--create-release-type)
5960
- [`--exact`](#--exact)
6061
- [`--force-publish`](#--force-publish)
@@ -201,6 +202,21 @@ lerna version --conventional-commits --conventional-prerelease
201202

202203
When run with this flag, `lerna version` will release with prerelease versions the specified packages (comma-separated) or all packages using `*`. Releases all unreleased changes as pre(patch/minor/major/release) by prefixing the version recommendation from `conventional-commits` with `pre`, eg. if present changes include a feature commit, the recommended bump will be `minor`, so this flag will result in a `preminor` release. If changes are present for packages that are not specified (if specifying packages), or for packages that are already in prerelease, those packages will be versioned as they normally would using `--conventional-commits`.
203204

205+
### `--conventional-bump-prerelease`
206+
207+
```sh
208+
lerna version --conventional-commits --conventional-prerelease --conventional-bump-prerelease
209+
```
210+
211+
When run with this flag, `lerna version` will release with bumped prerelease versions even if already released packages are prereleases. Releases all unreleased changes as pre(patch/minor/major/release) by prefixing the version recommendation from `conventional-commits` with `pre`, eg. if present changes include a feature commit, the recommended bump will be `minor`, so this flag will result in a `preminor` release. If not used just a prerelease bump will be applied to prereleased packages.
212+
213+
```sh
214+
Changes:
215+
- major: 1.0.0-alpha.0 => 2.0.0-alpha.0
216+
- minor: 1.0.0-alpha.0 => 1.1.0-alpha.0
217+
- patch: 1.0.0-alpha.0 => 1.0.1-alpha.0
218+
```
219+
204220
### `--create-release <type>`
205221

206222
```sh

commands/version/__tests__/version-conventional-commits.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ describe("--conventional-commits", () => {
9191
});
9292
});
9393

94+
it("should call recommended version with conventionalBumpPrerelease set", async () => {
95+
prereleaseVersionBumps.forEach((bump) => recommendVersion.mockResolvedValueOnce(bump));
96+
const cwd = await initFixture("prerelease-independent");
97+
98+
await lernaVersion(cwd)(
99+
"--conventional-commits",
100+
"--conventional-prerelease",
101+
"--conventional-bump-prerelease"
102+
);
103+
104+
prereleaseVersionBumps.forEach((version, name) => {
105+
const prereleaseId = semver.prerelease(version)[0];
106+
expect(recommendVersion).toHaveBeenCalledWith(expect.objectContaining({ name }), "independent", {
107+
changelogPreset: undefined,
108+
rootPath: cwd,
109+
tagPrefix: "v",
110+
prereleaseId,
111+
conventionalBumpPrerelease: true,
112+
});
113+
expect(updateChangelog).toHaveBeenCalledWith(
114+
expect.objectContaining({ name, version }),
115+
"independent",
116+
{ changelogPreset: undefined, rootPath: cwd, tagPrefix: "v" }
117+
);
118+
});
119+
});
120+
94121
it("should graduate prerelease version bumps and generate CHANGELOG", async () => {
95122
versionBumps.forEach((bump) => recommendVersion.mockResolvedValueOnce(bump));
96123
const cwd = await initFixture("prerelease-independent");

commands/version/command.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ exports.builder = (yargs, composed) => {
3232
describe: "Version changed packages as prereleases when using --conventional-commits.",
3333
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
3434
},
35+
"conventional-bump-prerelease": {
36+
describe: "Bumps prerelease versions if conventional commits requires it.",
37+
type: "boolean",
38+
},
3539
"changelog-preset": {
3640
describe: "Custom conventional-changelog preset.",
3741
type: "string",

commands/version/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class VersionCommand extends Command {
367367

368368
recommendVersions(resolvePrereleaseId) {
369369
const independentVersions = this.project.isIndependent();
370-
const { changelogPreset, conventionalGraduate } = this.options;
370+
const { changelogPreset, conventionalGraduate, conventionalBumpPrerelease } = this.options;
371371
const rootPath = this.project.manifest.location;
372372
const type = independentVersions ? "independent" : "fixed";
373373
const prereleasePackageNames = this.getPrereleasePackageNames();
@@ -394,6 +394,7 @@ class VersionCommand extends Command {
394394
rootPath,
395395
tagPrefix: this.tagPrefix,
396396
prereleaseId: getPrereleaseId(node),
397+
conventionalBumpPrerelease,
397398
})
398399
)
399400
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"command": {
3+
"publish": {
4+
"conventionalCommits": true
5+
}
6+
},
7+
"version": "independent"
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "conventional-commits-independent",
3+
"repository": "lerna/conventional-commits-independent",
4+
"version": "0.0.0-root"
5+
}

core/conventional-commits/__tests__/__fixtures__/prerelease-independent/packages/package-1/CHANGELOG.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "package-1",
3+
"repository": "lerna/conventional-commits-independent",
4+
"version": "1.0.0-alpha.0"
5+
}

core/conventional-commits/__tests__/__fixtures__/prerelease-independent/packages/package-2/CHANGELOG.md

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "package-2",
3+
"repository": "lerna/conventional-commits-independent",
4+
"version": "1.0.0-beta.0",
5+
"dependencies": {
6+
"package-1": "^1.0.0"
7+
}
8+
}

0 commit comments

Comments
 (0)