diff options
author | 2023-11-17 22:28:47 +0800 | |
---|---|---|
committer | 2023-11-17 22:28:47 +0800 | |
commit | f4efd1c808476c7e60fe00fcfb86276cf14fee79 (patch) | |
tree | 61aa94ad1239807b4e36cb03e26ba893bdede1dc | |
parent | e3dce215a5ea06bcff1b21027e5613e6518c69d4 (diff) | |
download | astro-f4efd1c808476c7e60fe00fcfb86276cf14fee79.tar.gz astro-f4efd1c808476c7e60fe00fcfb86276cf14fee79.tar.zst astro-f4efd1c808476c7e60fe00fcfb86276cf14fee79.zip |
Warn if astro add fetch failed with non 404 status (#9121)
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
-rw-r--r-- | .changeset/brave-taxis-arrive.md | 5 | ||||
-rw-r--r-- | packages/astro/src/cli/add/index.ts | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/.changeset/brave-taxis-arrive.md b/.changeset/brave-taxis-arrive.md new file mode 100644 index 000000000..3d2a5bd17 --- /dev/null +++ b/.changeset/brave-taxis-arrive.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Adds a warning if `astro add` fetches a package but returns a non-404 status diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index 42b160665..80c0e10ff 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -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; |