diff --git a/build-tools/packages/version-tools/src/internalVersionScheme.ts b/build-tools/packages/version-tools/src/internalVersionScheme.ts index eba5ce025663..6707acb682e9 100644 --- a/build-tools/packages/version-tools/src/internalVersionScheme.ts +++ b/build-tools/packages/version-tools/src/internalVersionScheme.ts @@ -250,7 +250,12 @@ export function isInternalVersionRange(range: string, allowAnyPrereleaseId = fal return false; } - return isInternalVersionScheme(minVer, false, allowAnyPrereleaseId); + // if allowAnyPrereleaseId === true, then allowPrereleases is implied to be true + return isInternalVersionScheme( + minVer, + /* allowPrereleases */ allowAnyPrereleaseId, + allowAnyPrereleaseId, + ); } /** @@ -265,10 +270,10 @@ export function bumpInternalVersion( version: semver.SemVer | string, bumpType: VersionBumpTypeExtended, ): semver.SemVer { - validateVersionScheme(version); - const [pubVer, intVer, prereleaseId] = fromInternalScheme(version, false, true); + validateVersionScheme(version, true, undefined); + const [pubVer, intVer, prereleaseId] = fromInternalScheme(version, true, true); const newIntVer = bumpType === "current" ? intVer : intVer.inc(bumpType); - return toInternalScheme(pubVer, newIntVer, false, prereleaseId); + return toInternalScheme(pubVer, newIntVer, true, prereleaseId); } /** @@ -290,7 +295,7 @@ export function getVersionRange( version: semver.SemVer | string, maxAutomaticBump: "minor" | "patch" | "~" | "^", ): string { - validateVersionScheme(version, false, undefined); + validateVersionScheme(version, true, undefined); const lowVersion = version; let highVersion: semver.SemVer; 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 70ad42887ae4..c8b8a32a2d96 100644 --- a/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts +++ b/build-tools/packages/version-tools/src/test/internalVersionScheme.test.ts @@ -243,6 +243,20 @@ describe("internalScheme", () => { assert.isFalse(semver.satisfies(`2.0.0-internal.3.1.0`, range)); }); + it("caret ^ dependency equivalent for prerelease/dev versions", () => { + const input = `2.0.0-dev.1.2.3.12345`; + const expected = `>=2.0.0-dev.1.2.3.12345 <2.0.0-dev.2.0.0`; + const range = getVersionRange(input, "^"); + assert.strictEqual(range, expected); + }); + + it("tilde ~ dependency equivalent for prerelease/dev versions", () => { + const input = `2.0.0-dev.1.2.3.12345`; + const expected = `>=2.0.0-dev.1.2.3.12345 <2.0.0-dev.1.3.0`; + const range = getVersionRange(input, "~"); + assert.strictEqual(range, expected); + }); + /** * Builds that are produced from dev builds or other non-release builds don't have the "internal" prerelease * identifier intentionally to ensure they don't satisfy the caret/tilde-equivalent semver ranges we provide to