mirror of
https://github.com/withastro/astro.git
synced 2025-01-22 18:41:55 -05:00
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>
This commit is contained in:
parent
5a3d46da1e
commit
f2dd895d71
2 changed files with 15 additions and 1 deletions
5
.changeset/soft-berries-prove.md
Normal file
5
.changeset/soft-berries-prove.md
Normal file
|
@ -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 `../`.
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue