mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
Warn if astro add fetch failed with non 404 status (#9121)
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
parent
e3dce215a5
commit
f4efd1c808
2 changed files with 15 additions and 1 deletions
5
.changeset/brave-taxis-arrive.md
Normal file
5
.changeset/brave-taxis-arrive.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Adds a warning if `astro add` fetches a package but returns a non-404 status
|
|
@ -731,8 +731,11 @@ async function fetchPackageJson(
|
|||
const res = await fetch(`${registry}/${packageName}/${tag}`);
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return await res.json();
|
||||
} else {
|
||||
} else if (res.status === 404) {
|
||||
// 404 means the package doesn't exist, so we don't need an error message here
|
||||
return new Error();
|
||||
} else {
|
||||
return new Error(`Failed to fetch ${registry}/${packageName}/${tag} - GET ${res.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -754,6 +757,9 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
|
|||
} else {
|
||||
const firstPartyPkgCheck = await fetchPackageJson('@astrojs', name, tag);
|
||||
if (firstPartyPkgCheck instanceof Error) {
|
||||
if (firstPartyPkgCheck.message) {
|
||||
spinner.warn(yellow(firstPartyPkgCheck.message));
|
||||
}
|
||||
spinner.warn(
|
||||
yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)
|
||||
);
|
||||
|
@ -780,6 +786,9 @@ export async function validateIntegrations(integrations: string[]): Promise<Inte
|
|||
if (pkgType === 'third-party') {
|
||||
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
|
||||
if (thirdPartyPkgCheck instanceof Error) {
|
||||
if (thirdPartyPkgCheck.message) {
|
||||
spinner.warn(yellow(thirdPartyPkgCheck.message));
|
||||
}
|
||||
throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
|
||||
} else {
|
||||
pkgJson = thirdPartyPkgCheck as any;
|
||||
|
|
Loading…
Add table
Reference in a new issue