From 6be8bb39f9a8002c39ffa98b1df36f0b84c7fecb Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 27 Mar 2023 17:49:19 -0400 Subject: [PATCH 1/2] Revert "Revert accidental create-astro fix" This reverts commit c13d428a7804b5b9809dbea94a1b17c36714a1e1. --- packages/create-astro/src/actions/template.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 4f7e751e96cd..aa0363694862 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -35,8 +35,13 @@ export async function template(ctx: Pick copyTemplate(ctx.template!, ctx as Context).catch((e) => { // eslint-disable-next-line no-console - error('error', e); - process.exit(1); + if (e instanceof Error) { + error('error', e.message); + process.exit(1); + } else { + error('error', 'Unable to clone template.'); + process.exit(1); + } }), }); } else { @@ -81,11 +86,18 @@ export default async function copyTemplate(tmpl: string, ctx: Context) { } catch (err: any) { fs.rmdirSync(ctx.cwd); if (err.message.includes('404')) { - await error('Error', `Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); + throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`); } else { - console.error(err.message); + throw new Error(err.message); } - ctx.exit(1); + } + + // It's possible the repo exists (ex. `withastro/astro`), + // But the template route is invalid (ex. `withastro/astro/examples/DNE`). + // `giget` doesn't throw for this case, + // so check if the directory is still empty as a heuristic. + if (fs.readdirSync(ctx.cwd).length === 0) { + throw new Error(`Template ${color.reset(tmpl)} ${color.dim('is empty!')}`); } // Post-process in parallel From 5a5c68ca7673e1aa1d6318624edbf8fa1e6621b2 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 27 Mar 2023 17:54:22 -0400 Subject: [PATCH 2/2] chore: changeset --- .changeset/bright-apricots-kiss.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/bright-apricots-kiss.md diff --git a/.changeset/bright-apricots-kiss.md b/.changeset/bright-apricots-kiss.md new file mode 100644 index 000000000000..483a70e5067f --- /dev/null +++ b/.changeset/bright-apricots-kiss.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Fix: Log an error when passing a `--template` that does not exist