Skip to content

Commit

Permalink
Ensure version is valid before passing it to semver
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Sep 25, 2024
1 parent 93cf856 commit c46f3c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
28 changes: 28 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit c46f3c9

Please sign in to comment.