Skip to content

Commit

Permalink
fix: if no previous prod release, return 1.0.0 if no prerelease
Browse files Browse the repository at this point in the history
Here's an example of what this fixes: agrc/plpco-rdcc-notifications#147
  • Loading branch information
stdavis committed Oct 9, 2024
1 parent 1c9142b commit 3a22bc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('getNewVersion', () => {
['0.1.0-0', 'minor', true, null, '0.1.0-1'],
['2.0.0-5', 'minor', false, '1.3.4', '1.4.0'],
[null, 'patch', false, null, '1.0.0'],
['1.0.0-3', 'patch', false, null, '1.0.0'],
];

test.each(cases)('%s, %s, %j, %s => %s', (lastTag, bumpType, prerelease, lastProdTag, expectation) => {
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export function getNewVersion(
return prerelease ? '1.0.0-0' : '1.0.0';
}

if (!prerelease && !lastProdTag) {
return '1.0.0';
}

/* If the last tag was a major prerelease, we shouldn't
bump anything but the prerelease number. For example, if the
last tag was 2.0.0-0 and this is a minor bump, we should
Expand All @@ -29,7 +33,7 @@ export function getNewVersion(

const releaseType = getReleaseType(lastTag, conventionalReleaseType, prerelease, lastProdTag);

return semver.inc(prerelease ? lastTag : lastProdTag ?? '0.0.0', releaseType, prerelease);
return semver.inc(prerelease ? lastTag : lastProdTag ?? '1.0.0', releaseType, prerelease);
}

function getReleaseType(
Expand Down

0 comments on commit 3a22bc2

Please sign in to comment.