Skip to content

Commit

Permalink
Fix behaviour regression in create-astro (#8634)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOtterlord authored Sep 22, 2023
1 parent bd00ad7 commit b64dd45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-islands-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Fix `--yes` behaviour to prevent it overriding `--template`
11 changes: 5 additions & 6 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { error, info, spinner, title } from '../messages.js';
export async function template(
ctx: Pick<Context, 'template' | 'prompt' | 'yes' | 'dryRun' | 'exit'>
) {
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',
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/create-astro/test/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
});

0 comments on commit b64dd45

Please sign in to comment.