Skip to content

Commit

Permalink
fix(version-tools): Correct handling of internal dev/prerelease versi…
Browse files Browse the repository at this point in the history
…ons (#12734)

Some necessary changes were missing from #12721 that made it incomplete.
This PR includes those changes, which should address that PR's goals of
accommodating versions that have more than 4 prerelease sections and
versions that use a non-internal prerelease identifier.

Prior to this change, versions like 2.0.0-dev.2.1.0.104436, which is set
in our CI pipeline, would cause a build failure.
  • Loading branch information
tylerbutler authored Oct 31, 2022
1 parent 9a83e43 commit 5ba0ee9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions build-tools/packages/version-tools/src/internalVersionScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ba0ee9

Please sign in to comment.