From b64dd45c0d641f9f2ed997e2cbdf8a6b0193195f Mon Sep 17 00:00:00 2001 From: Reuben Tier <64310361+TheOtterlord@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:18:46 +0100 Subject: [PATCH] Fix behaviour regression in create-astro (#8634) --- .changeset/neat-islands-wink.md | 5 +++++ packages/create-astro/src/actions/template.ts | 11 +++++------ packages/create-astro/test/template.test.js | 7 +++++++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/neat-islands-wink.md diff --git a/.changeset/neat-islands-wink.md b/.changeset/neat-islands-wink.md new file mode 100644 index 0000000000..fff9012adb --- /dev/null +++ b/.changeset/neat-islands-wink.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Fix `--yes` behaviour to prevent it overriding `--template` diff --git a/packages/create-astro/src/actions/template.ts b/packages/create-astro/src/actions/template.ts index 253c9fab1f..eaebe23607 100644 --- a/packages/create-astro/src/actions/template.ts +++ b/packages/create-astro/src/actions/template.ts @@ -9,10 +9,11 @@ import { error, info, spinner, title } from '../messages.js'; export async function template( ctx: Pick ) { - if (ctx.yes) { - ctx.template = 'basics'; - await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`); - } else if (!ctx.template) { + if (!ctx.template && ctx.yes) ctx.template = 'basics'; + + if (ctx.template) { + await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`); + } else { const { template: tmpl } = await ctx.prompt({ name: 'template', type: 'select', @@ -26,8 +27,6 @@ export async function template( ], }); ctx.template = tmpl; - } else { - await info('tmpl', `Using ${color.reset(ctx.template)}${color.dim(' as project template')}`); } if (ctx.dryRun) { diff --git a/packages/create-astro/test/template.test.js b/packages/create-astro/test/template.test.js index 66c7f54468..cf6b45f772 100644 --- a/packages/create-astro/test/template.test.js +++ b/packages/create-astro/test/template.test.js @@ -33,4 +33,11 @@ describe('template', () => { expect(fixture.hasMessage('Using blog as project template')).to.be.true; }); + + it('minimal (--yes)', async () => { + const context = { template: 'minimal', cwd: '', dryRun: true, yes: true, prompt: () => {} }; + await template(context); + + expect(fixture.hasMessage('Using minimal as project template')).to.be.true; + }) });