diff options
author | 2023-10-25 00:17:14 +0800 | |
---|---|---|
committer | 2023-10-24 11:17:14 -0500 | |
commit | f2dd895d71e0fccfbc1b98890ceefb69f32524d5 (patch) | |
tree | bdda009376ff5a411a1fc5a7c54721955bb3c883 /packages/create-astro/src | |
parent | 5a3d46da1e80f62a29eaf464eeb87c626cc5593f (diff) | |
download | astro-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>
Diffstat (limited to 'packages/create-astro/src')
-rw-r--r-- | packages/create-astro/src/actions/template.ts | 11 |
1 files changed, 10 insertions, 1 deletions
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 { |