diff --git a/packages/test/test-version-utils/src/test/versionUtils.spec.ts b/packages/test/test-version-utils/src/test/versionUtils.spec.ts index 94af62590e8b..24267c9b61fa 100644 --- a/packages/test/test-version-utils/src/test/versionUtils.spec.ts +++ b/packages/test/test-version-utils/src/test/versionUtils.spec.ts @@ -53,10 +53,16 @@ describe("versionUtils", () => { }); } - describe("bumping public releases", () => { + describe("bumping public releases (adjustPublicMajor = false)", () => { const adjustPublicMajor = false; createTest("1.0.0", -1, adjustPublicMajor, "^0.59.0"); createTest("1.0.0", -2, adjustPublicMajor, "^0.58.0"); + createTest("2.0.0", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0"); + createTest("2.3.5", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0"); + }); + + describe("bumping public releases (adjustPublicMajor = true)", () => { + const adjustPublicMajor = true; createTest("2.0.0", -1, adjustPublicMajor, "^1.0.0"); createTest("2.3.5", -1, adjustPublicMajor, "^1.0.0"); }); @@ -169,7 +175,7 @@ describe("versionUtils", () => { createTest("0.59.1001", -1, adjustPublicMajor, "^0.58.0"); createTest("0.59.1002", -1, adjustPublicMajor, "^0.58.0"); createTest("1.1.0", -1, adjustPublicMajor, "^0.59.0"); - createTest("2.4.5", -1, adjustPublicMajor, "^1.0.0-0"); + createTest("2.4.5", -1, adjustPublicMajor, "^2.0.0-rc.4.0.0"); }); describe("bumping down public releases (prerelease/dev)", () => { diff --git a/packages/test/test-version-utils/src/versionUtils.ts b/packages/test/test-version-utils/src/versionUtils.ts index a3d0d63c366b..e646b76c8c37 100644 --- a/packages/test/test-version-utils/src/versionUtils.ts +++ b/packages/test/test-version-utils/src/versionUtils.ts @@ -421,24 +421,34 @@ function calculateRequestedRange( throw new Error(err as string); } - // calculate requested major version number - const requestedMajorVersion = version.major + requested; - // if the major version number is bigger than 0 then return it as normal - if (requestedMajorVersion > 0) { - return `^${requestedMajorVersion}.0.0-0`; - } - // if the major version number is <= 0 then we return the equivalent pre-releases - const lastPrereleaseVersion = new semver.SemVer("0.59.0"); - - // Minor number in 0.xx release represent a major change hence different rules - // are applied for computing the requested version. - const requestedMinorVersion = lastPrereleaseVersion.minor + requestedMajorVersion; - // too old a version / non existing version requested - if (requestedMinorVersion <= 0) { - // cap at min version - return "^0.0.1-0"; + // If the base version is a public version and `adjustPublicMajor` is false, then we need to ensure that we + // calculate N-1 as he previous major release, regardless if it is public or internal. + // Currently, this case only applies to calculating N-X for 2.0.0. + // TODO: This is a temporary solution and we need to entirely rewrite this function to handle the changes the version schemas. See ADO:8198. + if (adjustPublicMajor === false && version.major > 1) { + // In this case, we can pretend that 2.0 is RC6 and calculate the range as if it were an internal version. + const internalSchemeRange = internalSchema("2.0.0", "6.0.0", "rc", requested); + return internalSchemeRange; + } else { + // calculate requested major version number + const requestedMajorVersion = version.major + requested; + // if the major version number is bigger than 0 then return it as normal + if (requestedMajorVersion > 0) { + return `^${requestedMajorVersion}.0.0-0`; + } + // if the major version number is <= 0 then we return the equivalent pre-releases + const lastPrereleaseVersion = new semver.SemVer("0.59.0"); + + // Minor number in 0.xx release represent a major change hence different rules + // are applied for computing the requested version. + const requestedMinorVersion = lastPrereleaseVersion.minor + requestedMajorVersion; + // too old a version / non existing version requested + if (requestedMinorVersion <= 0) { + // cap at min version + return "^0.0.1-0"; + } + return `^0.${requestedMinorVersion}.0-0`; } - return `^0.${requestedMinorVersion}.0-0`; } /**