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 astro add react #10988

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/olive-fans-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Updates `astro add` to handle installing peer dependencies with optional npm specifiers
9 changes: 9 additions & 0 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,16 @@ async function resolveRangeToInstallSpecifier(name: string, range: string): Prom
if (versions instanceof Error) return name;
// Filter out any prerelease versions
const stableVersions = versions.filter((v) => !v.includes('-'));
// Peer dependencies may sometimes use the `npm:` specifier, but `semver` package panics with it.
// Filter it out if so.
if (range.includes('npm:')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: startsWith

range = range
.split('||')
.filter((r) => !r.includes('npm:'))
.join('||');
}
const maxStable = maxSatisfying(stableVersions, range);
if (maxStable === null) return name;
return `${name}@^${maxStable}`;
}

Expand Down
Loading