diff --git a/README.md b/README.md index 81cbda5..4fcb0b4 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/index.js b/index.js index 08a7440..7fda6c7 100644 --- a/index.js +++ b/index.js @@ -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)); diff --git a/test.js b/test.js index 4c7e095..264596e 100644 --- a/test.js +++ b/test.js @@ -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'); @@ -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 });