Skip to content

Commit 2187b08

Browse files
committed
fix: edit select logic
1 parent 9b5b477 commit 2187b08

17 files changed

Lines changed: 1873 additions & 935 deletions

packages/plugin-bundle-stats/code-pushup.large-angular.config.ts

Lines changed: 535 additions & 383 deletions
Large diffs are not rendered by default.

packages/plugin-bundle-stats/code-pushup.minimal-esbuild.config.ts

Lines changed: 592 additions & 132 deletions
Large diffs are not rendered by default.

packages/plugin-bundle-stats/code-pushup.noise-reduced.config.ts

Whitespace-only changes.

packages/plugin-bundle-stats/src/lib/normalize.ts

Lines changed: 140 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ function formatStandardizedIssuesSection(scoring: ScoringConfig): string {
7979
function formatStandardizedTableSection(
8080
insightsTable: InsightsTableConfig | undefined,
8181
): string {
82-
if (!insightsTable || insightsTable.length === 0) {
82+
if (
83+
!insightsTable ||
84+
!insightsTable.groups ||
85+
insightsTable.groups.length === 0
86+
) {
8387
return ''; // Hide empty table section
8488
}
8589

86-
const groupItems = insightsTable
90+
const groupItems = insightsTable.groups
8791
.filter(group => group.title)
8892
.map(group => `*${group.icon || ''}${group.title}*`)
8993
.slice(0, 5); // Limit to prevent overly long descriptions
@@ -103,23 +107,127 @@ function formatStandardizedTreeSection(
103107
return ''; // Hide disabled tree section
104108
}
105109

106-
const { pruning } = dependencyTree;
107-
let pruningText = 'Default settings';
110+
const { pruning, groups, mode } = dependencyTree;
108111

112+
// Format pruning settings
113+
let pruningText = 'Default settings';
109114
if (pruning) {
110115
const pruningParts: string[] = [];
111116
if (pruning.minSize)
112-
pruningParts.push(`\`${formatBytes(pruning.minSize)}\``);
117+
pruningParts.push(`Min size: \`${formatBytes(pruning.minSize)}\``);
113118
if (pruning.maxChildren)
114-
pruningParts.push(`\`${pruning.maxChildren} children\``);
115-
if (pruning.maxDepth) pruningParts.push(`\`${pruning.maxDepth} depth\``);
119+
pruningParts.push(`Max children: \`${pruning.maxChildren}\``);
120+
if (pruning.maxDepth)
121+
pruningParts.push(`Max depth: \`${pruning.maxDepth}\``);
122+
if (pruning.pathLength)
123+
pruningParts.push(`Path length: \`${pruning.pathLength}\``);
116124

117125
if (pruningParts.length > 0) {
118126
pruningText = pruningParts.join(', ');
119127
}
120128
}
121129

122-
return `- **Tree:**\n - Groups: Same as table\n - Pruning: ${pruningText}\n - Rest: Remaining items grouped for clarity`;
130+
// Format groups
131+
let groupsText = 'None';
132+
if (groups && groups.length > 0) {
133+
const groupSummaries = groups.map(group => {
134+
const parts: string[] = [];
135+
if (group.title) parts.push(`"${group.title}"`);
136+
if (group.icon) parts.push(`${group.icon}`);
137+
if (group.include) {
138+
if (Array.isArray(group.include)) {
139+
const includePatterns = group.include
140+
.slice(0, 2)
141+
.map((p: string) => `"${p}"`)
142+
.join(', ');
143+
const moreCount =
144+
group.include.length > 2
145+
? `, +${group.include.length - 2} more`
146+
: '';
147+
parts.push(`include: [${includePatterns}${moreCount}]`);
148+
} else {
149+
parts.push(`include: "${group.include}"`);
150+
}
151+
}
152+
if (group.exclude && group.exclude.length > 0) {
153+
const excludePatterns = group.exclude
154+
.slice(0, 1)
155+
.map((p: string) => `"${p}"`)
156+
.join(', ');
157+
const moreCount =
158+
group.exclude.length > 1 ? `, +${group.exclude.length - 1} more` : '';
159+
parts.push(`exclude: [${excludePatterns}${moreCount}]`);
160+
}
161+
return parts.join(' ');
162+
});
163+
groupsText = groupSummaries.join('; ');
164+
}
165+
166+
// Format mode
167+
const modeText = mode || 'onlyMatching';
168+
169+
return `- **Tree:**\n - Mode: \`${modeText}\`\n - Groups: ${groupsText}\n - Pruning: ${pruningText}`;
170+
}
171+
172+
function formatStandardizedSelectionSection(
173+
selection: SelectionConfig,
174+
): string {
175+
const items: string[] = [];
176+
177+
// Selection mode
178+
items.push(` - Mode: \`${selection.mode}\``);
179+
180+
// Output patterns
181+
if (selection.includeOutputs.length > 0) {
182+
const patterns = selection.includeOutputs
183+
.slice(0, 3)
184+
.map(p => `\`${p}\``)
185+
.join(', ');
186+
const extra =
187+
selection.includeOutputs.length > 3
188+
? ` (+${selection.includeOutputs.length - 3} more)`
189+
: '';
190+
items.push(` - Include Outputs: ${patterns}${extra}`);
191+
}
192+
193+
if (selection.excludeOutputs.length > 0) {
194+
const patterns = selection.excludeOutputs
195+
.slice(0, 2)
196+
.map(p => `\`${p}\``)
197+
.join(', ');
198+
const extra =
199+
selection.excludeOutputs.length > 2
200+
? ` (+${selection.excludeOutputs.length - 2} more)`
201+
: '';
202+
items.push(` - Exclude Outputs: ${patterns}${extra}`);
203+
}
204+
205+
// Input patterns
206+
if (selection.includeInputs.length > 0) {
207+
const patterns = selection.includeInputs
208+
.slice(0, 3)
209+
.map(p => `\`${p}\``)
210+
.join(', ');
211+
const extra =
212+
selection.includeInputs.length > 3
213+
? ` (+${selection.includeInputs.length - 3} more)`
214+
: '';
215+
items.push(` - Include Inputs: ${patterns}${extra}`);
216+
}
217+
218+
if (selection.excludeInputs.length > 0) {
219+
const patterns = selection.excludeInputs
220+
.slice(0, 2)
221+
.map(p => `\`${p}\``)
222+
.join(', ');
223+
const extra =
224+
selection.excludeInputs.length > 2
225+
? ` (+${selection.excludeInputs.length - 2} more)`
226+
: '';
227+
items.push(` - Exclude Inputs: ${patterns}${extra}`);
228+
}
229+
230+
return `- **Selection:**\n${items.join('\n')}`;
123231
}
124232

125233
export function cleanTitleForSlug(title: string): string {
@@ -130,7 +238,8 @@ export function cleanTitleForSlug(title: string): string {
130238
}
131239

132240
export function prepareDescription(config: BundleStatsConfig): string {
133-
const { description, scoring, dependencyTree, insightsTable } = config;
241+
const { description, scoring, selection, dependencyTree, insightsTable } =
242+
config;
134243

135244
// Start with the action paragraph (preserve existing custom descriptions)
136245
let enhancedDescription = description || '';
@@ -146,6 +255,9 @@ export function prepareDescription(config: BundleStatsConfig): string {
146255
const issuesSection = formatStandardizedIssuesSection(scoring);
147256
if (issuesSection) sections.push(issuesSection);
148257

258+
const selectionSection = formatStandardizedSelectionSection(selection);
259+
if (selectionSection) sections.push(selectionSection);
260+
149261
// Handle insightsTable which could be false
150262
const normalizedInsightsTable =
151263
insightsTable === false ? undefined : insightsTable;
@@ -175,6 +287,7 @@ export function selectionGeneralConfigToOptions(
175287
): SelectionOptions {
176288
return {
177289
...config,
290+
mode: 'startup',
178291
includeOutputs: [],
179292
excludeOutputs: [],
180293
includeInputs: [],
@@ -190,36 +303,25 @@ export function normalizeSelectionOptions(
190303
options: SelectionOptions | undefined,
191304
): SelectionConfig {
192305
if (options === undefined) {
306+
// Default: include all outputs for startup mode
193307
return {
194-
includeOutputs: [],
308+
mode: 'startup',
309+
includeOutputs: ['**/*'],
195310
excludeOutputs: [],
196311
includeInputs: [],
197312
excludeInputs: [],
198-
includeImports: [],
199-
excludeImports: [],
200-
includeEntryPoints: [],
201-
excludeEntryPoints: [],
202313
};
203314
}
204315

205316
const globalInclude = options.include || [];
206317
const globalExclude = options.exclude || [];
207318

208319
return {
320+
mode: options.mode || 'startup',
209321
includeOutputs: [...(options.includeOutputs || []), ...globalInclude],
210322
excludeOutputs: [...(options.excludeOutputs || []), ...globalExclude],
211323
includeInputs: [...(options.includeInputs || []), ...globalInclude],
212324
excludeInputs: [...(options.excludeInputs || []), ...globalExclude],
213-
includeImports: [...(options.includeImports || []), ...globalInclude],
214-
excludeImports: [...(options.excludeImports || []), ...globalExclude],
215-
includeEntryPoints: [
216-
...(options.includeEntryPoints || []),
217-
...globalInclude,
218-
],
219-
excludeEntryPoints: [
220-
...(options.excludeEntryPoints || []),
221-
...globalExclude,
222-
],
223325
};
224326
}
225327

@@ -243,6 +345,7 @@ export function normalizeBundleStatsOptions(
243345
}
244346

245347
const normalizedScoring: ScoringConfig = {
348+
mode: 'all',
246349
totalSize: normalizeRange(totalSize ?? Infinity),
247350
penalty: normalizedPenalty,
248351
};
@@ -275,6 +378,7 @@ export function normalizeScoringOptions(
275378
const { penalty } = options;
276379

277380
return {
381+
mode: 'all',
278382
totalSize: [0, Infinity], // Default range
279383
penalty: penalty
280384
? {
@@ -299,6 +403,7 @@ export function normalizeDependencyTreeOptions(
299403
}
300404

301405
return {
406+
mode: 'onlyMatching',
302407
groups: options.groups || [],
303408
pruning: options.pruning || DEFAULT_PRUNING_CONFIG,
304409
};
@@ -314,7 +419,17 @@ export function normalizeInsightsTableOptions(
314419
return undefined;
315420
}
316421

317-
return options;
422+
return {
423+
mode: options.mode || 'onlyMatching',
424+
groups: options.groups || [],
425+
pruning: options.pruning
426+
? {
427+
enabled: options.pruning.enabled ?? false,
428+
maxChildren: options.pruning.maxChildren,
429+
minSize: options.pruning.minSize,
430+
}
431+
: undefined,
432+
};
318433
}
319434

320435
export function normalizeRange(range: MinMax | number): MinMax {

packages/plugin-bundle-stats/src/lib/runner/audits/audit-outputs.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function createAuditOutput(
3030
console.timeEnd('⚡ GET_ISSUES');
3131

3232
const calculateScore = createBundleStatsScoring({
33+
mode: config.scoring.mode,
3334
totalSize: config.scoring.totalSize,
3435
penalty: config.scoring.penalty,
3536
});
@@ -51,9 +52,20 @@ export function generateAuditOutputs(
5152
configs: BundleStatsConfig[],
5253
): AuditOutput[] {
5354
return configs.map(config => {
54-
console.time(`🔍 SELECT_BUNDLES`);
55-
const filteredTree = selectBundles(bundleStatsTree, config.selection);
56-
console.timeEnd(`🔍 SELECT_BUNDLES`);
55+
console.time('�� SELECT_BUNDLES');
56+
57+
// Extract grouping rules for feature mode filtering
58+
const groupingRules =
59+
config.insightsTable && typeof config.insightsTable === 'object'
60+
? config.insightsTable.groups
61+
: undefined;
62+
63+
const filteredTree = selectBundles(
64+
bundleStatsTree,
65+
config.selection,
66+
groupingRules,
67+
);
68+
console.timeEnd('🔍 SELECT_BUNDLES');
5769

5870
if (!filteredTree || Object.keys(filteredTree).length === 0) {
5971
return createEmptyAudit(config);

packages/plugin-bundle-stats/src/lib/runner/audits/details/audit-details.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export function createAuditOutputDetails(
1717
issues,
1818
};
1919

20-
if (config.insightsTable && config.insightsTable.length > 0) {
20+
if (
21+
config.insightsTable &&
22+
config.insightsTable.groups &&
23+
config.insightsTable.groups.length > 0
24+
) {
2125
console.time('📊 CREATE_INSIGHTS_TABLE');
2226
details.table = createInsightsTable(statsSlice, config.insightsTable);
2327
console.timeEnd('📊 CREATE_INSIGHTS_TABLE');
@@ -35,8 +39,10 @@ export function createAuditOutputDetails(
3539
details.trees = [
3640
createTree(statsSlice, {
3741
title: config.slug,
42+
mode: config.dependencyTree.mode ?? 'onlyMatching',
3843
pruning: config.dependencyTree.pruning ?? {},
3944
groups: config.dependencyTree.groups ?? [],
45+
selection: config.selection, // Pass selection config for onlyMatching filtering
4046
}),
4147
];
4248
console.timeEnd('🌳 CREATE_TREE');

0 commit comments

Comments
 (0)