Skip to content

Commit

Permalink
Fix astro add for prerelease packages (withastro#11548)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Bjorn Lu <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2024
1 parent 7f26de9 commit 602c5bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-coats-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes `astro add` for packages with only prerelease versions
4 changes: 2 additions & 2 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

Expand Down

0 comments on commit 602c5bf

Please sign in to comment.