Skip to content

Commit 7e4630c

Browse files
committed
feat: add auto grouping
1 parent 025de30 commit 7e4630c

File tree

14 files changed

+1097
-641
lines changed

14 files changed

+1097
-641
lines changed

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

Lines changed: 150 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,163 @@ import bundleStatsPlugin, { DEFAULT_GROUPING } from './src';
2525
*/
2626

2727
const groups = [
28-
{ title: 'Payments Package', patterns: ['**/packages/payments/**'], icon: '💳' },
28+
{
29+
title: 'Payments Package',
30+
patterns: ['**/packages/payments/**'],
31+
icon: '💳',
32+
},
2933
{ title: 'Casino Package', patterns: ['**/packages/casino/**'], icon: '🎰' },
3034
{ title: 'Bingo Package', patterns: ['**/packages/bingo/**'], icon: '🎯' },
3135
{ title: 'Sports Package', patterns: ['**/packages/sports/**'], icon: '⚽' },
3236
{ title: 'Poker Package', patterns: ['**/packages/poker/**'], icon: '🃏' },
33-
{ title: 'Lottery Package', patterns: ['**/packages/lottery/**'], icon: '🎲' },
34-
{ title: 'Horse Racing Package', patterns: ['**/packages/horseracing/**'], icon: '🐎' },
37+
{
38+
title: 'Lottery Package',
39+
patterns: ['**/packages/lottery/**'],
40+
icon: '🎲',
41+
},
42+
{
43+
title: 'Horse Racing Package',
44+
patterns: ['**/packages/horseracing/**'],
45+
icon: '🐎',
46+
},
3547
{ title: 'Oxygen Package', patterns: ['**/packages/oxygen/**'], icon: '🫧' },
36-
{ title: 'Engagement Package', patterns: ['**/packages/engagement/**'], icon: '🎯' },
37-
{ title: 'My Account Package', patterns: ['**/packages/myaccount/**'], icon: '👤' },
38-
{ title: 'Design System Package', patterns: ['**/packages/design-system/**'], icon: '🎨' },
39-
{ title: 'Global Search Package', patterns: ['**/packages/global-search/**'], icon: '🔍' },
48+
{
49+
title: 'Engagement Package',
50+
patterns: ['**/packages/engagement/**'],
51+
icon: '🎯',
52+
},
53+
{
54+
title: 'My Account Package',
55+
patterns: ['**/packages/myaccount/**'],
56+
icon: '👤',
57+
},
58+
{
59+
title: 'Design System Package',
60+
patterns: ['**/packages/design-system/**'],
61+
icon: '🎨',
62+
},
63+
{
64+
title: 'Global Search Package',
65+
patterns: ['**/packages/global-search/**'],
66+
icon: '🔍',
67+
},
4068
{ title: 'Gantry Package', patterns: ['**/packages/gantry/**'], icon: '🏗️' },
41-
{ title: 'Vanilla Package', patterns: ['**/packages/vanilla/**'], icon: '🍦' },
69+
{
70+
title: 'Vanilla Package',
71+
patterns: ['**/packages/vanilla/**'],
72+
icon: '🍦',
73+
},
4274
{ title: 'Promo Package', patterns: ['**/packages/promo/**'], icon: '🎁' },
43-
{ title: 'Moka Bingo Package', patterns: ['**/packages/mokabingo/**'], icon: '🎯' },
44-
{ title: 'Host App Package', patterns: ['**/packages/host-app/**'], icon: '🏠' },
45-
{ title: 'Test Web App Package', patterns: ['**/packages/testweb-app/**'], icon: '🧪' },
46-
{ title: 'Theme Park Package', patterns: ['**/packages/themepark/**'], icon: '🎢' },
47-
{ title: 'Rewards Hub Package', patterns: ['**/packages/rewards-hub/**'], icon: '🏆' },
48-
{ title: 'Reporting Package', patterns: ['**/packages/reporting/**'], icon: '📊' },
49-
{ title: 'Migration Kit Package', patterns: ['**/packages/migration-kit/**'], icon: '🔄' },
50-
{ title: 'Loaders Lib Package', patterns: ['**/packages/loaders-lib/**'], icon: '📦' },
51-
{ title: 'GitLab Data Access Package', patterns: ['**/packages/gitlab-data-access/**'], icon: '🔗' },
52-
{ title: 'Geo Coordinator Lib Package', patterns: ['**/packages/geo-coordinator-lib/**'], icon: '🌍' },
53-
{ title: 'ESBuild Plugins Package', patterns: ['**/packages/esbuild-plugins/**'], icon: '🔌' },
54-
{ title: 'ESLint Utils Package', patterns: ['**/packages/eslint-utils/**'], icon: '🔧' },
55-
{ title: 'Extractor App Package', patterns: ['**/packages/extractor-app/**'], icon: '📤' },
56-
{ title: 'Gantry App Package', patterns: ['**/packages/gantry-app/**'], icon: '🏗️' },
57-
{ title: 'Moxxi Test Utils Package', patterns: ['**/packages/moxxi-test-utils/**'], icon: '🧪' },
58-
{ title: 'NX Plugin Package', patterns: ['**/packages/nx-plugin/**'], icon: '⚙️' },
59-
{ title: 'RTMS Test App Package', patterns: ['**/packages/rtms-test-app/**'], icon: '🧪' },
60-
{ title: 'SFAPI Smoke Test Package', patterns: ['**/packages/sfapi-smoke-test/**'], icon: '💨' },
61-
{ title: 'Device Atlas Smoke Test Package', patterns: ['**/packages/device-atlas-smoke-test/**'], icon: '📱' },
62-
{ title: 'Zendesk Webchat Feature Package', patterns: ['**/packages/zendesk-webchat-feature/**'], icon: '💬' },
63-
{ title: 'Dev Kit Package', patterns: ['**/packages/dev-kit/**'], icon: '🛠️' },
64-
{ title: 'E2E Test Framework Package', patterns: ['**/packages/e2e-test-framework/**'], icon: '🧪' },
75+
{
76+
title: 'Moka Bingo Package',
77+
patterns: ['**/packages/mokabingo/**'],
78+
icon: '🎯',
79+
},
80+
{
81+
title: 'Host App Package',
82+
patterns: ['**/packages/host-app/**'],
83+
icon: '🏠',
84+
},
85+
{
86+
title: 'Test Web App Package',
87+
patterns: ['**/packages/testweb-app/**'],
88+
icon: '🧪',
89+
},
90+
{
91+
title: 'Theme Park Package',
92+
patterns: ['**/packages/themepark/**'],
93+
icon: '🎢',
94+
},
95+
{
96+
title: 'Rewards Hub Package',
97+
patterns: ['**/packages/rewards-hub/**'],
98+
icon: '🏆',
99+
},
100+
{
101+
title: 'Reporting Package',
102+
patterns: ['**/packages/reporting/**'],
103+
icon: '📊',
104+
},
105+
{
106+
title: 'Migration Kit Package',
107+
patterns: ['**/packages/migration-kit/**'],
108+
icon: '🔄',
109+
},
110+
{
111+
title: 'Loaders Lib Package',
112+
patterns: ['**/packages/loaders-lib/**'],
113+
icon: '📦',
114+
},
115+
{
116+
title: 'GitLab Data Access Package',
117+
patterns: ['**/packages/gitlab-data-access/**'],
118+
icon: '🔗',
119+
},
120+
{
121+
title: 'Geo Coordinator Lib Package',
122+
patterns: ['**/packages/geo-coordinator-lib/**'],
123+
icon: '🌍',
124+
},
125+
{
126+
title: 'ESBuild Plugins Package',
127+
patterns: ['**/packages/esbuild-plugins/**'],
128+
icon: '🔌',
129+
},
130+
{
131+
title: 'ESLint Utils Package',
132+
patterns: ['**/packages/eslint-utils/**'],
133+
icon: '🔧',
134+
},
135+
{
136+
title: 'Extractor App Package',
137+
patterns: ['**/packages/extractor-app/**'],
138+
icon: '📤',
139+
},
140+
{
141+
title: 'Gantry App Package',
142+
patterns: ['**/packages/gantry-app/**'],
143+
icon: '🏗️',
144+
},
145+
{
146+
title: 'Moxxi Test Utils Package',
147+
patterns: ['**/packages/moxxi-test-utils/**'],
148+
icon: '🧪',
149+
},
150+
{
151+
title: 'NX Plugin Package',
152+
patterns: ['**/packages/nx-plugin/**'],
153+
icon: '⚙️',
154+
},
155+
{
156+
title: 'RTMS Test App Package',
157+
patterns: ['**/packages/rtms-test-app/**'],
158+
icon: '🧪',
159+
},
160+
{
161+
title: 'SFAPI Smoke Test Package',
162+
patterns: ['**/packages/sfapi-smoke-test/**'],
163+
icon: '💨',
164+
},
165+
{
166+
title: 'Device Atlas Smoke Test Package',
167+
patterns: ['**/packages/device-atlas-smoke-test/**'],
168+
icon: '📱',
169+
},
170+
{
171+
title: 'Zendesk Webchat Feature Package',
172+
patterns: ['**/packages/zendesk-webchat-feature/**'],
173+
icon: '💬',
174+
},
175+
{
176+
title: 'Dev Kit Package',
177+
patterns: ['**/packages/dev-kit/**'],
178+
icon: '🛠️',
179+
},
180+
{
181+
title: 'E2E Test Framework Package',
182+
patterns: ['**/packages/e2e-test-framework/**'],
183+
icon: '🧪',
184+
},
65185
{ title: 'Node Modules', patterns: ['**/node_modules/**'], icon: '📦' },
66186
];
67187

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ const TREE_AUDITS: BundleStatsOptions[] = [
268268
...BASE_AUDIT_ALL_FILES_ALWAYS_PASS,
269269
artefactTree: {
270270
groups: [
271-
{ title: 'Node Modules', patterns: ['**/node_modules/**'], icon: '📦' },
271+
{
272+
title: 'Node Modules',
273+
patterns: ['**/node_modules/**'],
274+
icon: '📦',
275+
maxDepth: 2,
276+
},
272277
],
273278
},
274279
},
@@ -280,12 +285,17 @@ const TREE_AUDITS: BundleStatsOptions[] = [
280285
artefactTree: { groups: [{ patterns: ['**/utils/**'] }] },
281286
},
282287
{
283-
slug: `${TREE_AUDIT_PREFIX}-groups-max-depth`,
284-
title: `${TREE_AUDIT_ICON} - Artefact Tree - Groups Max Depth`,
288+
slug: `${TREE_AUDIT_PREFIX}-groups-auto`,
289+
title: `${TREE_AUDIT_ICON} - Artefact Tree - Groups auto gtoup node`,
285290
description: 'Demonstrates per-group maxDepth option.',
286291
...BASE_AUDIT_ALL_FILES_ALWAYS_PASS,
287292
artefactTree: {
288-
groups: [{ patterns: ['**/node_modules/**'], maxDepth: 1 }],
293+
groups: [
294+
{
295+
patterns: ['**/node_modules/**', '**/node_modules/@*/**'],
296+
maxDepth: 1,
297+
},
298+
],
289299
},
290300
},
291301
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export const DEFAULT_GROUPING: GroupingRule[] = [
347347
icon: '📁',
348348
},
349349
{
350-
title: '@*/*',
350+
title: 'Dependencies',
351351
patterns: ['**/node_modules/@*/**', '**/node_modules/**'],
352352
},
353353
];

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import type { BundleStatsConfig } from '../types.js';
33
import type { UnifiedStats } from '../unify/unified-stats.types.js';
44
import { createDisplayValue } from '../utils.js';
55
import { createEmptyAudit } from '../utils.js';
6+
import { DEFAULT_PRUNING_OPTIONS } from './details/constants.js';
67
import { getIssues } from './details/issues.js';
78
import { createInsightsTable } from './details/table.js';
8-
import { DEFAULT_PRUNING, createTree } from './details/tree.js';
9+
import { createTree } from './details/tree.js';
910
import { createBundleStatsScoring } from './scoring.js';
1011
import { selectArtefacts } from './selection.js';
1112

@@ -59,7 +60,7 @@ export function createAuditOutputDetails(
5960
createTree(statsSlice, {
6061
title: config.slug,
6162
pruning: {
62-
...DEFAULT_PRUNING,
63+
...DEFAULT_PRUNING_OPTIONS,
6364
...config.artefactTree.pruning,
6465
},
6566
groups: config.artefactTree.groups ?? [],
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { ArtefactType } from './utils/grouping';
2+
3+
// ===== ARTEFACT TYPE DEFINITIONS =====
4+
5+
export const ARTEFACT_TYPE_ICON_MAP: Record<ArtefactType, string> = {
6+
root: '🗂️',
7+
'script-file': '📄',
8+
'style-file': '🎨',
9+
'entry-file': '📍',
10+
'static-import': '🔗',
11+
group: '📁',
12+
};
13+
14+
// ===== TREE CONFIGURATION =====
15+
16+
export const DEFAULT_PRUNING_OPTIONS = {
17+
maxDepth: 3,
18+
maxChildren: 5,
19+
minSize: 0,
20+
} as const;
21+
22+
// ===== ISSUE ICONS =====
23+
24+
export const ISSUE_ICONS = {
25+
TOO_LARGE: '🔺',
26+
TOO_SMALL: '🔻',
27+
BLACKLIST: '🚫',
28+
} as const;
29+
30+
// ===== DEFAULT VALUES =====
31+
32+
export const DEFAULT_GROUP_NAME = 'Group';
33+
export const REST_GROUP_NAME = 'Rest';

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { minimatch } from 'minimatch';
22
import type { Issue } from '@code-pushup/models';
33
import { formatBytes } from '@code-pushup/utils';
4-
import type { BundleStatsConfig } from '../types.js';
4+
import type { BundleStatsConfig } from '../../types.js';
55
import type {
66
UnifiedStats,
77
UnifiedStatsOutput,
8-
} from '../unify/unified-stats.types.js';
8+
} from '../../unify/unified-stats.types.js';
9+
import { ISSUE_ICONS } from './constants.js';
910

1011
export type PenaltyConfig = {
1112
artefactSize?: [number, number];
@@ -15,24 +16,18 @@ export type PenaltyConfig = {
1516
};
1617

1718
/**
18-
* Checks if a file path matches any of the provided blacklist glob patterns.
19-
* Uses minimatch for pattern matching with support for wildcards and special characters.
20-
*
21-
* @param path - File path to check against blacklist patterns
22-
* @param patterns - Array of glob patterns to match against (supports *, **, ?, etc.)
23-
* @returns The first matching pattern if found, or false if no patterns match
24-
*
19+
* Checks if a path matches any of the given blacklist patterns. Enables pattern-based filtering for bundle security and optimization.
2520
*/
2621
function matchesBlacklistPattern(
2722
path: string,
2823
patterns: string[],
29-
): string | false {
24+
): string | null {
3025
for (const pattern of patterns) {
31-
if (minimatch(path, pattern)) {
26+
if (minimatch(path, pattern, { matchBase: true })) {
3227
return pattern;
3328
}
3429
}
35-
return false;
30+
return null;
3631
}
3732

3833
/**
@@ -55,7 +50,7 @@ export function createTooLargeIssue(
5550
maxSize: number,
5651
): Issue {
5752
return {
58-
message: `🔺 \`${outputPath}\` is **${formatBytes(bytes)}** _(> ${formatBytes(maxSize)})_`,
53+
message: `${ISSUE_ICONS.TOO_LARGE} \`${outputPath}\` is **${formatBytes(bytes)}** _(> ${formatBytes(maxSize)})_`,
5954
severity: 'error',
6055
source: { file: outputPath },
6156
};
@@ -81,23 +76,23 @@ export function createTooSmallIssue(
8176
minSize: number,
8277
): Issue {
8378
return {
84-
message: `🔻 \`${outputPath}\` is **${formatBytes(bytes)}** _(< ${formatBytes(minSize)})_`,
79+
message: `${ISSUE_ICONS.TOO_SMALL} \`${outputPath}\` is **${formatBytes(bytes)}** _(< ${formatBytes(minSize)})_`,
8580
severity: 'warning',
8681
source: { file: outputPath },
8782
};
8883
}
8984

9085
/**
91-
* Creates error issue for blacklisted import matching forbidden pattern. Identifies dependencies that should be removed or replaced.
86+
* Creates error issue for blacklisted import pattern match. Enforces dependency restrictions for security and architectural compliance.
9287
*
93-
* @param importPath - Path to the import that matches blacklist pattern
94-
* @param outputPath - Path to the output file containing the blacklisted import
95-
* @param pattern - The specific blacklist pattern that was matched
96-
* @returns Issue object with error severity and replacement recommendation
88+
* @param importPath - Path that matched the blacklist pattern
89+
* @param outputPath - Output file containing the blacklisted import
90+
* @param pattern - Specific pattern that was matched
91+
* @returns Issue object with error severity and compliance requirement
9792
*
9893
* @example
9994
* ```js
100-
* createBlacklistedIssue('src/math.ts', 'dist/bundle.js', '**\/math.*')
95+
* createBlacklistedIssue('src/math.ts', 'bundle.js', '**\/math.*')
10196
* // Returns: { message: "🚫 `src/math.ts` matches blacklist pattern `**\/math.*`", severity: 'error', ... }
10297
* ```
10398
*/
@@ -107,7 +102,7 @@ export function createBlacklistedIssue(
107102
pattern: string,
108103
): Issue {
109104
return {
110-
message: `🚫 \`${importPath}\` matches blacklist pattern \`${pattern}\``,
105+
message: `${ISSUE_ICONS.BLACKLIST} \`${importPath}\` matches blacklist pattern \`${pattern}\``,
111106
severity: 'error',
112107
source: { file: outputPath },
113108
};

0 commit comments

Comments
 (0)