From 7d918f6851bec175ab4f98f91f439ee7cfdb19c9 Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Mon, 15 Jun 2020 00:10:45 +0200 Subject: [PATCH] fix(prepare): return correct releaseType (#885) It calculate releaseType only with nextVersion Co-authored-by: shipjs --- .../lib/util/__tests__/getReleaseType.spec.js | 24 +++++++------------ .../shipjs-lib/src/lib/util/getReleaseType.js | 22 ++++++++--------- packages/shipjs/src/flow/prepare.js | 2 +- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js b/packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js index 702a0ccb..9ed25c11 100644 --- a/packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js +++ b/packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js @@ -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, }); diff --git a/packages/shipjs-lib/src/lib/util/getReleaseType.js b/packages/shipjs-lib/src/lib/util/getReleaseType.js index 3ce6a56f..e29e162e 100644 --- a/packages/shipjs-lib/src/lib/util/getReleaseType.js +++ b/packages/shipjs-lib/src/lib/util/getReleaseType.js @@ -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); } diff --git a/packages/shipjs/src/flow/prepare.js b/packages/shipjs/src/flow/prepare.js index 9e66af63..e537a798 100644 --- a/packages/shipjs/src/flow/prepare.js +++ b/packages/shipjs/src/flow/prepare.js @@ -70,7 +70,7 @@ async function prepare({ nextVersion, dryRun, }); - const releaseType = getReleaseType(currentVersion, nextVersion); + const releaseType = getReleaseType(nextVersion); await validatePreparationConditions({ config, releaseType,