diff --git a/build-tools/packages/build-cli/src/lib/bump.ts b/build-tools/packages/build-cli/src/lib/bump.ts index bf0881cfc9cc..188c7e5904b6 100644 --- a/build-tools/packages/build-cli/src/lib/bump.ts +++ b/build-tools/packages/build-cli/src/lib/bump.ts @@ -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; diff --git a/build-tools/packages/version-tools/src/internalVersionScheme.ts b/build-tools/packages/version-tools/src/internalVersionScheme.ts index 351b5d3e523f..eba5ce025663 100644 --- a/build-tools/packages/version-tools/src/internalVersionScheme.ts +++ b/build-tools/packages/version-tools/src/internalVersionScheme.ts @@ -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 @@ -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, @@ -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; } diff --git a/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts b/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts index dc6b0796f9d3..70ad42887ae4 100644 --- a/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts +++ b/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts @@ -11,6 +11,7 @@ import { isInternalVersionRange, isInternalVersionScheme, toInternalScheme, + validateVersionScheme, } from "../internalVersionScheme"; describe("internalScheme", () => { @@ -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); @@ -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); @@ -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));