From c43566b2f42a30501802d1b4a990f7617bcad470 Mon Sep 17 00:00:00 2001 From: "berkay.daglar" Date: Wed, 22 Jan 2025 01:35:23 +0300 Subject: [PATCH 1/2] fix(diff): fix prerelease to stable version diff logic Refactored version diff logic to handle transitions from prerelease versions to stable versions correctly for major/minor/patch version bumps. --- functions/diff.js | 10 +++++----- test/functions/diff.js | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/functions/diff.js b/functions/diff.js index fc224e30..f011d99a 100644 --- a/functions/diff.js +++ b/functions/diff.js @@ -29,16 +29,16 @@ const diff = (version1, version2) => { // Otherwise it can be determined by checking the high version - if (highVersion.patch) { - // anything higher than a patch bump would result in the wrong version - return 'patch' - } - if (highVersion.minor) { // anything higher than a minor bump would result in the wrong version return 'minor' } + if (highVersion.patch) { + // anything higher than a patch bump would result in the wrong version + return 'patch' + } + // bumping major/minor/patch all have same result return 'major' } diff --git a/test/functions/diff.js b/test/functions/diff.js index 720e159b..b2c35ef6 100644 --- a/test/functions/diff.js +++ b/test/functions/diff.js @@ -34,6 +34,7 @@ test('diff versions test', (t) => { ['1.0.0-1', '2.0.0-1', 'premajor'], ['1.0.0-1', '1.1.0-1', 'preminor'], ['1.0.0-1', '1.0.1-1', 'prepatch'], + ['1.7.2-1', '1.8.1', 'minor'], ].forEach((v) => { const version1 = v[0] const version2 = v[1] From fd22cddcaa59defa64679628f6feda6a10e7d119 Mon Sep 17 00:00:00 2001 From: "berkay.daglar" Date: Wed, 29 Jan 2025 13:45:04 +0300 Subject: [PATCH 2/2] fix(diff): add new edge cases to tests, and handle them --- functions/diff.js | 17 +++++------------ test/functions/diff.js | 6 ++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/functions/diff.js b/functions/diff.js index f011d99a..33171dc1 100644 --- a/functions/diff.js +++ b/functions/diff.js @@ -27,20 +27,13 @@ const diff = (version1, version2) => { return 'major' } - // Otherwise it can be determined by checking the high version - - if (highVersion.minor) { - // anything higher than a minor bump would result in the wrong version - return 'minor' - } - - if (highVersion.patch) { - // anything higher than a patch bump would result in the wrong version + // If the main part has no difference + if (lowVersion.compareMain(highVersion) === 0) { + if (lowVersion.minor && !lowVersion.patch) { + return 'minor' + } return 'patch' } - - // bumping major/minor/patch all have same result - return 'major' } // add the `pre` prefix if we are going to a prerelease version diff --git a/test/functions/diff.js b/test/functions/diff.js index b2c35ef6..80f5e3c3 100644 --- a/test/functions/diff.js +++ b/test/functions/diff.js @@ -35,6 +35,12 @@ test('diff versions test', (t) => { ['1.0.0-1', '1.1.0-1', 'preminor'], ['1.0.0-1', '1.0.1-1', 'prepatch'], ['1.7.2-1', '1.8.1', 'minor'], + ['1.1.1-pre', '2.1.1-pre', 'premajor'], + ['1.1.1-pre', '2.1.1', 'major'], + ['1.2.3-1', '1.2.3', 'patch'], + ['1.4.0-1', '2.3.5', 'major'], + ['1.6.1-5', '1.7.2', 'minor'], + ['2.0.0-1', '2.1.1', 'major'], ].forEach((v) => { const version1 = v[0] const version2 = v[1]