summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Genteure <genteure@gmail.com> 2023-10-25 00:17:14 +0800
committerGravatar GitHub <noreply@github.com> 2023-10-24 11:17:14 -0500
commitf2dd895d71e0fccfbc1b98890ceefb69f32524d5 (patch)
treebdda009376ff5a411a1fc5a7c54721955bb3c883
parent5a3d46da1e80f62a29eaf464eeb87c626cc5593f (diff)
downloadastro-f2dd895d71e0fccfbc1b98890ceefb69f32524d5.tar.gz
astro-f2dd895d71e0fccfbc1b98890ceefb69f32524d5.tar.zst
astro-f2dd895d71e0fccfbc1b98890ceefb69f32524d5.zip
fix(create-astro): ignore fs errors after download fails (#8841)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
-rw-r--r--.changeset/soft-berries-prove.md5
-rw-r--r--packages/create-astro/src/actions/template.ts11
2 files changed, 15 insertions, 1 deletions
diff --git a/.changeset/soft-berries-prove.md b/.changeset/soft-berries-prove.md
new file mode 100644
index 000000000..cce169649
--- /dev/null
+++ b/.changeset/soft-berries-prove.md
@@ -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 `../`.
diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts
index 8d22e95b1..bdb326076 100644
--- a/packages/create-astro/src/actions/template.ts
+++ b/packages/create-astro/src/actions/template.ts
@@ -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 {