From c46f3c9372ec565c956cb92a9555949ee024bfb7 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Wed, 25 Sep 2024 12:57:06 +0200 Subject: [PATCH] Ensure version is valid before passing it to semver --- .gitignore | 2 ++ index.js | 2 +- test.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d2b47d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +node_modules \ No newline at end of file diff --git a/index.js b/index.js index d0c29b7..e24fd20 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,7 @@ class ConventionalChangelog extends Plugin { skipUnstable: true }); - const lastStableTag = tags.length > 0 ? tags[0] : null; + const lastStableTag = tags.length > 0 ? tags[0].replace(options.tagPrefix, '') : null; if ( lastStableTag && diff --git a/test.js b/test.js index 89407bc..d13cfdb 100644 --- a/test.js +++ b/test.js @@ -189,6 +189,34 @@ test('should follow conventional commit strategy with prereleaase', async t => { assert.equal(version4, '2.0.0-alpha.1'); }); +test.only('should follow conventional commit strategy with prereleaase and custom prefix', async t => { + setup(); + const prefix = 'scope/'; + sh.exec(`git tag ${prefix}v1.2.1`); + add('feat', 'baz'); + + const [config, container] = getOptions({ preset: { name: 'conventionalcommits' } }, { commit: true, tag: true }); + config.preRelease = 'alpha'; + config.git.tagName = `${prefix}v${'${version}'}`; + const { version: version1 } = await runTasks(config, container); + assert.equal(version1, '1.3.0-alpha.0'); + + add('fix', 'buz'); + + const { version: version2 } = await runTasks(config, container); + assert.equal(version2, '1.3.0-alpha.1'); + + add('feat', 'biz', { breaking: true }); + + const { version: version3 } = await runTasks(config, container); + assert.equal(version3, '2.0.0-alpha.0'); + + add('fix', 'boz'); + + const { version: version4 } = await runTasks(config, container); + assert.equal(version4, '2.0.0-alpha.1'); +}); + test('should use provided pre-release id (pre-release continuation)', async t => { setup(); sh.exec(`git tag 1.0.1-alpha.0`);