Skip to content

Commit

Permalink
fix(create-astro): ignore fs errors after download fails (#8841)
Browse files Browse the repository at this point in the history
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 24, 2023
1 parent 5a3d46d commit f2dd895
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-berries-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

No longer attempts to delete the directory after a template download fails if the path is `.`, `./` or starts with `../`.
11 changes: 10 additions & 1 deletion packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ export default async function copyTemplate(tmpl: string, ctx: Context) {
dir: '.',
});
} catch (err: any) {
fs.rmdirSync(ctx.cwd);
// Only remove the directory if it's most likely created by us.
if (ctx.cwd !== '.' && ctx.cwd !== './' && !ctx.cwd.startsWith('../')) {
try {
fs.rmdirSync(ctx.cwd);
} catch (_) {
// Ignore any errors from removing the directory,
// make sure we throw and display the original error.
}
}

if (err.message.includes('404')) {
throw new Error(`Template ${color.reset(tmpl)} ${color.dim('does not exist!')}`);
} else {
Expand Down

0 comments on commit f2dd895

Please sign in to comment.