0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

Fix astro add for prerelease packages (#11548)

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
This commit is contained in:
Reuben Tier 2024-07-25 10:04:46 +00:00 committed by GitHub
parent 7f26de906e
commit 602c5bf05d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes `astro add` for packages with only prerelease versions

View file

@ -691,9 +691,9 @@ async function convertIntegrationsToInstallSpecifiers(
async function resolveRangeToInstallSpecifier(name: string, range: string): Promise<string> {
const versions = await fetchPackageVersions(name);
if (versions instanceof Error) return name;
// Filter out any prerelease versions
// Filter out any prerelease versions, but fallback if there are no stable versions
const stableVersions = versions.filter((v) => !v.includes('-'));
const maxStable = maxSatisfying(stableVersions, range);
const maxStable = maxSatisfying(stableVersions.length !== 0 ? stableVersions : versions, range);
return `${name}@^${maxStable}`;
}