Skip to content

Commit e830992

Browse files
committed
fix(create-cli): return no plugins when none recommended
1 parent 5dcdcd7 commit e830992

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

packages/create-cli/src/lib/setup/codegen.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ function addPlugins(
6868
plugins: PluginCodegenResult[],
6969
): void {
7070
if (plugins.length === 0) {
71-
builder.addLine('plugins: [],', 1);
71+
builder.addLine('plugins: [', 1);
72+
builder.addLine('// TODO: register some plugins', 2);
73+
builder.addLine('],', 1);
7274
} else {
7375
builder.addLine('plugins: [', 1);
7476
builder.addLines(

packages/create-cli/src/lib/setup/codegen.unit.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import type { PluginCodegenResult } from './types.js';
33

44
describe('generateConfigSource', () => {
55
describe('TypeScript format', () => {
6-
it('should generate config with empty plugins array', () => {
6+
it('should generate config with TODO placeholder when no plugins provided', () => {
77
expect(generateConfigSource([], 'ts')).toMatchInlineSnapshot(`
88
"import type { CoreConfig } from '@code-pushup/models';
99
1010
export default {
11-
plugins: [],
11+
plugins: [
12+
// TODO: register some plugins
13+
],
1214
} satisfies CoreConfig;
1315
"
1416
`);
@@ -104,11 +106,13 @@ describe('generateConfigSource', () => {
104106
});
105107

106108
describe('JavaScript format', () => {
107-
it('should generate JS config with empty plugins array', () => {
109+
it('should generate JS config with TODO placeholder when no plugins provided', () => {
108110
expect(generateConfigSource([], 'js')).toMatchInlineSnapshot(`
109111
"/** @type {import('@code-pushup/models').CoreConfig} */
110112
export default {
111-
plugins: [],
113+
plugins: [
114+
// TODO: register some plugins
115+
],
112116
};
113117
"
114118
`);

packages/create-cli/src/lib/setup/prompts.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type {
1010
* Resolves which plugins to include in the generated config.
1111
*
1212
* Resolution order (first match wins):
13-
* 1. `--plugins` CLI argument: comma-separated slugs, validated against available bindings
14-
* 2. `--yes` flag: recommended plugins (or all if none recommended)
13+
* 1. `--plugins`: comma-separated slugs, validated against available bindings
14+
* 2. `--yes`: recommended plugins
1515
* 3. Interactive: checkbox prompt with recommended plugins pre-checked
1616
*/
1717
export async function promptPluginSelection(
@@ -28,9 +28,7 @@ export async function promptPluginSelection(
2828
}
2929
const recommended = await detectRecommended(bindings, targetDir);
3030
if (cliArgs.yes) {
31-
return recommended.size > 0
32-
? bindings.filter(({ slug }) => recommended.has(slug))
33-
: bindings;
31+
return bindings.filter(({ slug }) => recommended.has(slug));
3432
}
3533
const selected = await checkbox({
3634
message: 'Plugins to include:',

packages/create-cli/src/lib/setup/prompts.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ describe('promptPluginSelection', () => {
154154
expect(result[0]).toHaveProperty('slug', 'eslint');
155155
});
156156

157-
it('should return all plugins when none are recommended', async () => {
157+
it('should return no plugins when none are recommended', async () => {
158158
await expect(
159159
promptPluginSelection(bindings, '/test', { yes: true }),
160-
).resolves.toStrictEqual(bindings);
160+
).resolves.toBeArrayOfSize(0);
161161
});
162162
});
163163

packages/create-cli/src/lib/setup/wizard.int.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const TEST_BINDINGS: PluginSetupBinding[] = [
1818
slug: 'alpha',
1919
title: 'Alpha Plugin',
2020
packageName: '@code-pushup/alpha-plugin',
21+
isRecommended: () => Promise.resolve(true),
2122
prompts: [
2223
{
2324
key: 'alpha.path',
@@ -43,6 +44,7 @@ const TEST_BINDINGS: PluginSetupBinding[] = [
4344
slug: 'beta',
4445
title: 'Beta Plugin',
4546
packageName: '@code-pushup/beta-plugin',
47+
isRecommended: () => Promise.resolve(true),
4648
generateConfig: () => ({
4749
imports: [
4850
{

packages/create-cli/src/lib/setup/wizard.unit.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const TEST_BINDING: PluginSetupBinding = {
1515
slug: 'test-plugin',
1616
title: 'Test Plugin',
1717
packageName: '@code-pushup/test-plugin',
18+
isRecommended: () => Promise.resolve(true),
1819
generateConfig: () => ({
1920
imports: [
2021
{
@@ -72,7 +73,7 @@ describe('runSetupWizard', () => {
7273
expect(logger.info).toHaveBeenCalledWith('Dry run — no files written.');
7374
});
7475

75-
it('should generate empty config with no bindings', async () => {
76+
it('should generate config with TODO placeholder when no bindings provided', async () => {
7677
await runSetupWizard([], {
7778
yes: true,
7879
'target-dir': MEMFS_VOLUME,
@@ -83,7 +84,9 @@ describe('runSetupWizard', () => {
8384
"import type { CoreConfig } from '@code-pushup/models';
8485
8586
export default {
86-
plugins: [],
87+
plugins: [
88+
// TODO: register some plugins
89+
],
8790
} satisfies CoreConfig;
8891
"
8992
`);

0 commit comments

Comments
 (0)