Skip to content

Commit

Permalink
Add strictSemVer option
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 11, 2022
1 parent 377c941 commit c3748fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ Use `true` to ignore the recommended bump, and use the version provided by relea
(Note that the changelog preview shows the recommended bump, as the desired version isn't known yet. The `infile` will
have the correct version.)

### `strictSemVer`

Default value: `false`

Use `true` to strictly follow semver, also in consecutive pre-releases. This means that from a pre-release, a
recommended bump will result in a next pre-release for the next version. For example, from `1.0.0-alpha.0` a recommended
bump of `minor` will result in a `preminor` bump to `1.1.0-alpha.0` (whereas the default behavior without this flag
results in a `prerelease` bump to `1.0.0-alpha.1`).

### `context`

Default value: `undefined`
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class ConventionalChangelog extends Plugin {
if (increment && semver.valid(increment)) {
resolve(increment);
} else if (isPreRelease) {
const type = releaseType && !semver.prerelease(latestVersion) ? `pre${releaseType}` : 'prerelease';
const type =
releaseType && (options.strictSemVer || !semver.prerelease(latestVersion))
? `pre${releaseType}`
: 'prerelease';
resolve(semver.inc(latestVersion, type, preReleaseId));
} else if (releaseType) {
resolve(semver.inc(latestVersion, releaseType, preReleaseId));
Expand Down
12 changes: 11 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('should use provided pre-release id', async t => {
assert.strictEqual(version, '1.1.0-alpha.0');
});

test('should use provided pre-release id (prelease continuation)', async t => {
test('should use provided pre-release id (pre-release continuation)', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.1.0-alpha.0');
Expand Down Expand Up @@ -103,6 +103,16 @@ test('should use recommended bump (after pre-rerelease)', async t => {
stub.restore();
});

test('should follow true semver (pre-release continuation)', async t => {
const options = { preRelease: 'alpha', [namespace]: { preset, strictSemVer: true }, git };
const plugin = factory(Plugin, { namespace, options });
const stub = sinon.stub(plugin, 'getLatestVersion').returns('1.1.0-alpha.0');
await runTasks(plugin);
const { version } = plugin.config.getContext();
assert.strictEqual(version, '1.2.0-alpha.0');
stub.restore();
});

test('should use provided increment', async t => {
const options = { increment: 'major', [namespace]: { preset }, git };
const plugin = factory(Plugin, { namespace, options });
Expand Down

0 comments on commit c3748fa

Please sign in to comment.