Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(version-tools): Relax handling of internal dev/prerelease versions #12721

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-tools/packages/build-cli/src/lib/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export async function bumpReleaseGroup(

// the lerna version command sets the dependency range of managed packages to a caret (^) dependency range. However,
// for the internal version scheme, the range needs to be a >= < range.
if (scheme === "internal") {
if (scheme === "internal" || scheme === "internalPrerelease") {
const range = getVersionRange(translatedVersion, "^");
if (releaseGroupOrPackage instanceof MonoRepo) {
const packagesToCheckAndUpdate = releaseGroupOrPackage.packages;
Expand Down
12 changes: 5 additions & 7 deletions build-tools/packages/version-tools/src/internalVersionScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MINIMUM_SEMVER_PRERELEASE_SECTIONS = 4;
* The first part of the semver prerelease value is called the "prerelease identifier". For Fluid internal versions, the
* value must always match this constant.
*/
const REQUIRED_PRERELEASE_IDENTIFIER = "internal";
export const REQUIRED_PRERELEASE_IDENTIFIER = "internal";

/**
* Translates a version using the Fluid internal version scheme into two parts: the public version, and the internal
Expand Down Expand Up @@ -162,7 +162,7 @@ export function toInternalScheme(
*
* This function is not typically used. {@link isInternalVersionScheme} is more useful since it does not throw.
*/
function validateVersionScheme(
export function validateVersionScheme(
// eslint-disable-next-line @rushstack/no-new-null
version: semver.SemVer | string | null,
allowPrereleases = false,
Expand Down Expand Up @@ -217,12 +217,10 @@ export function isInternalVersionScheme(
allowAnyPrereleaseId = false,
): boolean {
const parsedVersion = semver.parse(version);
const prereleaseId = allowAnyPrereleaseId ? undefined : REQUIRED_PRERELEASE_IDENTIFIER;

try {
validateVersionScheme(
parsedVersion,
allowPrereleases,
allowAnyPrereleaseId ? undefined : REQUIRED_PRERELEASE_IDENTIFIER,
);
validateVersionScheme(parsedVersion, allowPrereleases, prereleaseId);
} catch (error) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isInternalVersionRange,
isInternalVersionScheme,
toInternalScheme,
validateVersionScheme,
} from "../internalVersionScheme";

describe("internalScheme", () => {
Expand All @@ -27,6 +28,18 @@ describe("internalScheme", () => {
assert.isFalse(result);
});

it("2.0.0-alpha.1.0.0 is valid when allowAnyPrereleaseId is true", () => {
const input = `2.0.0-alpha.1.0.0`;
const result = isInternalVersionScheme(input, false, true);
assert.isTrue(result);
});

it("2.0.0-alpha.1.0.0.0 is valid when allowAnyPrereleaseId is true", () => {
const input = `2.0.0-alpha.1.0.0.0`;
const result = isInternalVersionScheme(input, true, true);
assert.isTrue(result);
});

it("1.1.1-internal.1.0.0 is not internal scheme (public must be 2.0.0+)", () => {
const input = `1.1.1-internal.1.0.0`;
const result = isInternalVersionScheme(input);
Expand All @@ -39,6 +52,12 @@ describe("internalScheme", () => {
assert.isFalse(result);
});

it("validateVersionScheme: 2.0.0-dev.1.1.0.123 is valid when allowAnyPrereleaseId is true", () => {
const input = `2.0.0-dev.1.1.0.123`;
const result = validateVersionScheme(input, true, "dev");
assert.isTrue(result);
});

it("2.0.0-internal.1.1.0.123 is a valid internal prerelease version", () => {
const input = `2.0.0-internal.1.1.0.123`;
const result = isInternalVersionScheme(input, true);
Expand All @@ -63,6 +82,18 @@ describe("internalScheme", () => {
assert.isTrue(result);
});

it("2.0.0-dev.2.1.0.104414 is a valid internal version when prerelease and allowAnyPrereleaseId are true", () => {
const input = `2.0.0-dev.2.1.0.104414`;
const result = isInternalVersionScheme(input, true, true);
assert.isTrue(result);
});

it("2.0.0-dev.2.1.0.104414 is a not valid when prerelease is false and allowAnyPrereleaseId are true", () => {
const input = `2.0.0-dev.2.1.0.104414`;
const result = isInternalVersionScheme(input, false, true);
assert.isFalse(result);
});

it(">=2.0.0-internal.1.0.0 <2.0.0-internal.1.1.0 is internal", () => {
const input = `>=2.0.0-internal.1.0.0 <2.0.0-internal.1.1.0`;
assert.isTrue(isInternalVersionRange(input));
Expand Down