Skip to content

Commit

Permalink
fix(test-version-utils): Add temporary workaround for calculating N-1…
Browse files Browse the repository at this point in the history
… for 2.0 (#21562)

This change was included in PR #21531, so it's already in main.

This PR adds a **temporary** workaround to fix the calculation of N-1
(when `allowPublicMajor === false`) for version `2.0.0`.

Ideally, we can complete a long-term solution (full rewrite of version
calculation) and we will not need to merge this. See
[ADO:8198](https://dev.azure.com/fluidframework/internal/_workitems/edit/8198)
for work tracking a long-term solution.

---------

Co-authored-by: Scott Norton <[email protected]>
  • Loading branch information
tylerbutler and scottn12 authored Jun 20, 2024
1 parent 9c54e9e commit 3a2899b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
10 changes: 8 additions & 2 deletions packages/test/test-version-utils/src/test/versionUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -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)", () => {
Expand Down
44 changes: 27 additions & 17 deletions packages/test/test-version-utils/src/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}

/**
Expand Down

0 comments on commit 3a2899b

Please sign in to comment.