Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(create): Ignore errors removing directory after download failed #8841

Merged
merged 5 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (_) {
ematipico marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading