Handle error state for version (#7939)

* fix(create-astro): handle error state for version

* fix: handle missing version
This commit is contained in:
Nate Moore 2023-08-03 16:03:04 -05:00 committed by GitHub
parent a2b989cba1
commit 89cd4b877e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Handle error state for version number

View file

@ -11,7 +11,7 @@ export async function intro(ctx: Pick<Context, 'skipHouston' | 'version' | 'user
'Welcome',
'to',
label('astro', color.bgGreen, color.black),
color.green(`v${ctx.version}`) + ',',
(ctx.version ? color.green(`v${ctx.version}`) : '') + ',',
`${ctx.username}!`,
],
random(welcome),

View file

@ -83,7 +83,8 @@ export const getVersion = () =>
if (v) return resolve(v);
let registry = await getRegistry();
const { version } = await fetch(`${registry}/astro/latest`, { redirect: 'follow' }).then(
(res) => res.json()
(res) => res.json(),
() => ({ version: '' })
);
v = version;
resolve(version);
@ -92,9 +93,9 @@ export const getVersion = () =>
export const log = (message: string) => stdout.write(message + '\n');
export const banner = async (version: string) =>
log(
`\n${label('astro', color.bgGreen, color.black)} ${color.green(
`\n${label('astro', color.bgGreen, color.black)} ${version ? color.green(
color.bold(`v${version}`)
)} ${color.bold('Launch sequence initiated.')}`
): ''} ${color.bold('Launch sequence initiated.')}`
);
export const info = async (prefix: string, text: string) => {