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): Correct handling of internal dev/prerelease versions #12734

Merged
merged 7 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 7 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,7 @@ export function isInternalVersionRange(range: string, allowAnyPrereleaseId = fal
return false;
}

return isInternalVersionScheme(minVer, false, allowAnyPrereleaseId);
return isInternalVersionScheme(minVer, allowAnyPrereleaseId, allowAnyPrereleaseId);
tylerbutler marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -265,10 +265,12 @@ 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);
console.log(intVer.version);
tylerbutler marked this conversation as resolved.
Show resolved Hide resolved
const newIntVer = bumpType === "current" ? intVer : intVer.inc(bumpType);
return toInternalScheme(pubVer, newIntVer, false, prereleaseId);
console.log(newIntVer.version);
return toInternalScheme(pubVer, newIntVer, true, prereleaseId);
tylerbutler marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -290,7 +292,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