diff --git a/packages/playground-v2/src/compiler-versions.ts b/packages/playground-v2/src/compiler-versions.ts index ccf46d407387..b8fb9684800e 100644 --- a/packages/playground-v2/src/compiler-versions.ts +++ b/packages/playground-v2/src/compiler-versions.ts @@ -1,4 +1,4 @@ -import { gte, prerelease, rcompare, valid } from "semver" +import { gte, lte, prerelease, rcompare, valid } from "semver" import { CompilerDownloadError, fetchCompilerResource } from "./compiler-assets" export type PublishedCompilerVersions = { @@ -106,6 +106,18 @@ export function publishedNativeCompilerSelection(published: PublishedCompilerVer return { version, channel: useStable ? ("stable" as const) : ("nightly" as const) } } +export function latestStableCompilerVersion(legacyVersions: readonly string[], published: PublishedCompilerVersions) { + const latest = published.tags.latest + if (latest && valid(latest) !== null && !prerelease(latest)) { + if (!isUnsupportedNativeCompilerVersion(latest) && published.versions.includes(latest)) return latest + const supported = compilerVersionChoices(legacyVersions, published).find( + ({ version }) => valid(version) !== null && !prerelease(version) && lte(version, latest) + ) + if (supported) return supported.version + } + throw new Error("No supported TypeScript release is published as latest") +} + export function compilerVersionChoices( legacyVersions: readonly string[], published?: PublishedCompilerVersions, diff --git a/packages/playground-v2/src/index.html b/packages/playground-v2/src/index.html index 3c93de346730..96de7ec4d9f6 100644 --- a/packages/playground-v2/src/index.html +++ b/packages/playground-v2/src/index.html @@ -314,6 +314,8 @@

Enter a value

+ +