Skip to content

Commit

Permalink
fix(prepare): return correct releaseType (#885)
Browse files Browse the repository at this point in the history
It calculate releaseType only with nextVersion

Co-authored-by: shipjs <[email protected]>
  • Loading branch information
Eunjae Lee and shipjs authored Jun 14, 2020
1 parent 6579294 commit 7d918f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
24 changes: 8 additions & 16 deletions packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ import getReleaseType from '../getReleaseType';
describe('getReleaseType', () => {
it('works', () => {
const list = [
['1.2.3', '2.0.0', 'major'],
['1.2.3', '1.3.0', 'minor'],
['1.2.3', '1.2.4', 'patch'],
['1.2.3', '1.2.4-alpha.0', 'prerelease'],

['1.2.4-alpha.0', '1.2.4-alpha.1', 'prerelease'],
['1.2.4-alpha.0', '1.2.4', 'patch'],
['1.2.4-alpha.0', '1.2.5', 'patch'],
['1.2.4-alpha.0', '1.3.0', 'minor'],
['1.2.4-alpha.0', '2.0.0', 'major'],

['1.3.0-alpha.0', '1.3.0', 'minor'],
['2.0.0', 'major'],
['1.3.0', 'minor'],
['1.2.4', 'patch'],
['1.2.5', 'patch'],
['1.2.4-alpha.0', 'prerelease'],
];

list.forEach(([currentVersion, nextVersion, expected]) => {
const actual = getReleaseType(currentVersion, nextVersion);
expect({ currentVersion, nextVersion, result: actual }).toEqual({
currentVersion,
list.forEach(([nextVersion, expected]) => {
const actual = getReleaseType(nextVersion);
expect({ nextVersion, result: actual }).toEqual({
nextVersion,
result: expected,
});
Expand Down
22 changes: 10 additions & 12 deletions packages/shipjs-lib/src/lib/util/getReleaseType.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { diff, prerelease, minor, patch } from 'semver';
import { prerelease, minor, patch } from 'semver';

export default function getReleaseType(currentVersion, nextVersion) {
if (prerelease(currentVersion) === null && prerelease(nextVersion) !== null) {
export default function getReleaseType(nextVersion) {
if (prerelease(nextVersion) !== null) {
return 'prerelease';
}
if (prerelease(currentVersion) !== null && prerelease(nextVersion) === null) {
if (patch(nextVersion) === 0) {
if (minor(nextVersion) === 0) {
return 'major';
} else {
return 'minor';
}

if (patch(nextVersion) === 0) {
if (minor(nextVersion) === 0) {
return 'major';
} else {
return 'patch';
return 'minor';
}
} else {
return 'patch';
}
return diff(currentVersion, nextVersion);
}
2 changes: 1 addition & 1 deletion packages/shipjs/src/flow/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function prepare({
nextVersion,
dryRun,
});
const releaseType = getReleaseType(currentVersion, nextVersion);
const releaseType = getReleaseType(nextVersion);
await validatePreparationConditions({
config,
releaseType,
Expand Down

0 comments on commit 7d918f6

Please sign in to comment.