Skip to content

Commit faa4599

Browse files
committed
fix: cleanup 1
1 parent a3d5027 commit faa4599

36 files changed

+5179
-17272
lines changed

package-lock.json

Lines changed: 4604 additions & 16102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
"node": ">=22.14"
2323
},
2424
"dependencies": {
25-
"@angular-devkit/build-angular": "~20.0.0",
26-
"@angular/common": "~20.0.0",
27-
"@angular/compiler": "~20.0.0",
28-
"@angular/core": "~20.0.0",
29-
"@angular/forms": "~20.0.0",
30-
"@angular/platform-browser": "~20.0.0",
31-
"@angular/platform-server": "~20.0.0",
32-
"@angular/router": "~20.0.0",
33-
"@angular/ssr": "~20.0.0",
3425
"@code-pushup/portal-client": "^0.13.0",
3526
"@isaacs/cliui": "^8.0.2",
3627
"@nx/devkit": "19.8.13",
@@ -41,15 +32,13 @@
4132
"bundle-require": "^5.1.0",
4233
"esbuild": "^0.25.2",
4334
"eslint": "^9.16.0",
44-
"express": "^4.21.2",
4535
"glob": "^11.0.1",
4636
"lighthouse": "^12.0.0",
4737
"lighthouse-logger": "2.0.1",
4838
"multi-progress-bars": "^5.0.3",
4939
"nx": "19.8.13",
5040
"parse-lcov": "^1.0.4",
5141
"rimraf": "^6.0.1",
52-
"rxjs": "~7.8.0",
5342
"semver": "^7.6.3",
5443
"simple-git": "^3.26.0",
5544
"ts-morph": "^24.0.0",
@@ -58,16 +47,9 @@
5847
"yaml": "^2.5.1",
5948
"yargs": "^17.7.2",
6049
"zod": "^3.23.8",
61-
"zod-validation-error": "^3.4.0",
62-
"zone.js": "~0.15.0"
50+
"zod-validation-error": "^3.4.0"
6351
},
6452
"devDependencies": {
65-
"@angular-devkit/core": "~20.0.0",
66-
"@angular-devkit/schematics": "~20.0.0",
67-
"@angular/build": "~20.0.0",
68-
"@angular/cli": "~20.0.0",
69-
"@angular/compiler-cli": "~20.0.0",
70-
"@angular/language-service": "~20.0.0",
7153
"@beaussan/nx-knip": "^0.0.5-15",
7254
"@code-pushup/eslint-config": "^0.14.2",
7355
"@commitlint/cli": "^19.5.0",
@@ -76,18 +58,13 @@
7658
"@commitlint/cz-commitlint": "^19.5.0",
7759
"@commitlint/types": "^19.5.0",
7860
"@nodelib/fs.walk": "^2.0.0",
79-
"@nx/angular": "^21.2.1",
8061
"@nx/eslint-plugin": "19.8.13",
81-
"@nx/js": "21.2.1",
62+
"@nx/js": "19.8.13",
8263
"@nx/plugin": "19.8.13",
8364
"@nx/react": "19.8.13",
8465
"@nx/vite": "19.8.13",
85-
"@nx/web": "21.2.1",
8666
"@nx/workspace": "19.8.13",
87-
"@push-based/cpu-prof": "^1.0.4",
88-
"@push-based/nx-verdaccio": "0.0.0-alpha.30",
89-
"@rsbuild/core": "^1.3.22",
90-
"@schematics/angular": "~20.0.0",
67+
"@push-based/nx-verdaccio": "^0.0.0",
9168
"@swc-node/register": "1.9.2",
9269
"@swc/cli": "0.3.14",
9370
"@swc/core": "1.5.7",
@@ -97,19 +74,14 @@
9774
"@types/benchmark": "^2.1.5",
9875
"@types/debug": "^4.1.12",
9976
"@types/eslint": "^8.44.2",
100-
"@types/express": "^4.17.21",
101-
"@types/inquirer": "^9.0.8",
10277
"@types/node": "^22.13.4",
10378
"@types/react": "18.3.1",
10479
"@types/react-dom": "18.3.0",
105-
"@typescript-eslint/utils": "^8.29.0",
10680
"@vitejs/plugin-react": "4.2.1",
10781
"@vitest/coverage-v8": "1.3.1",
10882
"@vitest/eslint-plugin": "^1.1.38",
10983
"@vitest/ui": "1.3.1",
110-
"angular-eslint": "^20.0.0",
11184
"benchmark": "^2.1.4",
112-
"bun": "^1.2.16",
11385
"chrome-launcher": "^1.1.2",
11486
"chromium": "^3.0.3",
11587
"commitizen": "^4.3.1",
@@ -137,18 +109,15 @@
137109
"prettier": "^3.4.1",
138110
"react": "18.3.1",
139111
"react-dom": "18.3.1",
140-
"rolldown": "^1.0.0-beta.16",
141-
"rollup": "^4.43.0",
142112
"ts-patch": "^3.3.0",
143113
"tsconfig-paths": "^4.2.0",
144114
"tsx": "^4.19.0",
145115
"type-fest": "^4.26.1",
146116
"typescript": "5.5.4",
147117
"typescript-eslint": "^8.18.0",
148118
"verdaccio": "^5.32.2",
149-
"vite": "^5.4.19",
119+
"vite": "^5.4.8",
150120
"vitest": "1.3.1",
151-
"webpack": "^5.99.9",
152121
"zod2md": "^0.1.7"
153122
},
154123
"optionalDependencies": {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const config = {
77
generateArtefacts: {
88
command: 'npm',
99
args: ['run', 'build:stats'],
10-
cwd: './packages/plugin-bundle-stats/mocks/fixtures/angular-minimal',
1110
},
1211
artefact:
1312
// minimal angular example
@@ -17,22 +16,25 @@ const config = {
1716
bundler: 'esbuild',
1817
configs: [
1918
{
19+
slug: 'initial-bundles',
2020
title: 'Initial Bundles',
2121
include: ['main-*.js', 'polyfills-*.js', '*.css'],
2222
thresholds: {
2323
totalSize: [300 * 1024, 1 * 1024 * 1024],
24-
artefactSize: 500 * 1024,
24+
artefactSize: [100 * 1024, 500 * 1024],
2525
},
2626
},
2727

2828
{
29+
slug: 'shared-chunks',
2930
title: 'Shared Chunks',
3031
include: ['**/chunk-*.js'],
3132
thresholds: {
3233
totalSize: [10, 100 * 1024],
3334
},
3435
},
3536
{
37+
slug: 'css-assets',
3638
title: 'CSS Assets',
3739
include: ['**/*.css'],
3840
thresholds: {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { bundleStatsPlugin } from './lib/bundle-stats-plugin';
22

33
export default bundleStatsPlugin;
4-
export { DEFAULT_GROUPING, DEFAULT_PRUNING } from './lib/runner/constants.js';
4+
export { DEFAULT_GROUPING, DEFAULT_PRUNING } from './lib/constants.js';

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { createRequire } from 'node:module';
22
import type { PluginConfig } from '@code-pushup/models';
3-
import { BUNDLE_STATS_PLUGIN_SLUG } from './constants.js';
3+
import {
4+
BUNDLE_STATS_PLUGIN_SLUG,
5+
DEFAULT_GROUPING,
6+
DEFAULT_PRUNING,
7+
} from './constants.js';
48
import { normalizeBundleStatsOptions } from './normalize.js';
59
import { bundleStatsRunner } from './runner/bundle-stats-runner.js';
6-
import { DEFAULT_GROUPING, DEFAULT_PRUNING } from './runner/constants.js';
710
import { type BundleStatsConfig } from './runner/types.js';
811
import type { PluginOptions } from './types.js';
912

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { PruningOptions } from './bundle-stats-plugin.js';
2-
import type { GroupingRule } from './runner/types.js';
1+
import type { GroupingOptions, PruningOptions } from './runner/types.js';
32

43
/**
54
* Default grouping rules for bundle stats analysis.
65
* These rules help categorize and organize bundle assets by common patterns.
76
*/
8-
export const DEFAULT_GROUPING: GroupingRule[] = [
7+
export const DEFAULT_GROUPING: GroupingOptions[] = [
98
{
109
name: '@angular/*',
1110
patterns: ['**/node_modules/@angular/**'],
@@ -33,3 +32,8 @@ export const DEFAULT_PRUNING: PruningOptions = {
3332
startDepth: 0,
3433
maxDepth: 2,
3534
};
35+
36+
/**
37+
* Plugin slug for bundle stats plugin
38+
*/
39+
export const BUNDLE_STATS_PLUGIN_SLUG = 'bundle-stats';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { BundleStatsConfig } from './runner/types.js';
2+
import type { BundleStatsOptions } from './types.js';
3+
4+
/**
5+
* Normalizes bundle stats options to the expected config format
6+
*/
7+
export function normalizeBundleStatsOptions(
8+
options: BundleStatsOptions,
9+
): BundleStatsConfig {
10+
const {
11+
slug,
12+
title,
13+
description,
14+
thresholds,
15+
include,
16+
exclude,
17+
includeInputs,
18+
excludeInputs,
19+
} = options;
20+
21+
return {
22+
slug,
23+
title: title || slug,
24+
description: description || `Bundle stats analysis for ${slug}`,
25+
thresholds,
26+
include,
27+
exclude,
28+
includeInputs,
29+
excludeInputs,
30+
};
31+
}

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

Lines changed: 110 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import type { AuditOutput } from '@code-pushup/models';
2-
import { executeProcess, readJsonFile } from '@code-pushup/utils';
3-
import type { BundleStatsTree } from './processing/bundle-stats.types.js';
4-
import {
5-
type EsBuildCoreStats,
6-
unifyBundlerStats,
7-
} from './processing/unify.esbuild.js';
2+
import { executeProcess, formatBytes, readJsonFile } from '@code-pushup/utils';
83
import type {
94
BundleStatsConfig,
105
GroupingOptions,
116
PruningOptions,
127
SupportedBundlers,
138
} from './types.js';
9+
import type {
10+
BundleStatsNode,
11+
BundleStatsTree,
12+
} from './unify/bundle-stats.types.js';
1413
import {
15-
getTreesByConfig,
16-
filterUnifiedTreeByConfig as getTreesByConfigs,
14+
type EsBuildCoreStats,
15+
unifyBundlerStats,
16+
} from './unify/unify.esbuild.js';
17+
import {
18+
createDisplayValue,
19+
createEmptyAudit,
20+
filterUnifiedTreeByConfigSingle,
21+
formatTreeForDisplay,
1722
} from './utils.js';
23+
import {
24+
type PrunedNode,
25+
applyGroupingToTree,
26+
calcTotals,
27+
formatTree,
28+
prune,
29+
} from './utils/reduce.js';
30+
import { calculateScore } from './utils/scoring.js';
1831

1932
export type PluginArtefactOptions = {
2033
generateArtefacts?: {
@@ -85,13 +98,97 @@ export async function bundleStatsRunner(
8598
});
8699

87100
const bundleStatsTree = unifieBundleStats as unknown as BundleStatsTree;
101+
return generateAudits(bundleStatsTree, configs, { grouping, pruning });
102+
};
103+
}
104+
105+
/**
106+
* Processes a bundle stats tree through the complete analysis pipeline
107+
*/
108+
function processTreeForAudit(
109+
tree: BundleStatsTree,
110+
options: { grouping?: GroupingOptions[]; pruning?: PruningOptions },
111+
): { processedTree: PrunedNode; totalBytes: number; fileCount: number } {
112+
const {
113+
grouping = [],
114+
pruning = { maxChildren: 10, startDepth: 0, maxDepth: 2 },
115+
} = options;
116+
117+
let processedTree = tree.root;
118+
119+
// Apply grouping if specified
120+
if (grouping.length > 0) {
121+
processedTree = applyGroupingToTree(processedTree, { grouping });
122+
}
88123

89-
const trees = getTreesByConfigs(bundleStatsTree, configs);
124+
// Calculate totals
125+
const rootWithTotals = calcTotals(processedTree);
126+
const totalBytes = rootWithTotals.values.bytes || 0;
127+
const fileCount = rootWithTotals.values.childCount || 0;
90128

91-
return getTreesByConfig(trees, configs, { grouping, pruning });
129+
// Apply pruning for display
130+
const prunedRoot = prune(rootWithTotals, pruning);
131+
const formattedRoot = formatTree(prunedRoot);
132+
133+
return {
134+
processedTree: formattedRoot,
135+
totalBytes,
136+
fileCount,
137+
};
138+
}
139+
140+
/**
141+
* Creates a complete audit output from processed tree data
142+
*/
143+
function createAuditOutput(
144+
config: BundleStatsConfig,
145+
processedTree: PrunedNode,
146+
totalBytes: number,
147+
fileCount: number,
148+
): AuditOutput {
149+
// Convert to Tree format for audit details
150+
const tree = formatTreeForDisplay(processedTree, config.title || config.slug);
151+
152+
// Calculate score using the existing function
153+
const score = calculateScore(totalBytes, config);
154+
155+
// Create display value
156+
const displayValue = createDisplayValue(totalBytes, fileCount);
157+
158+
return {
159+
slug: config.slug,
160+
score,
161+
value: totalBytes,
162+
displayValue,
163+
details: {
164+
trees: [tree],
165+
},
92166
};
93167
}
94168

95-
// @TODO
96-
// Scoring is based on LH metrics for biggest chunk size
97-
//
169+
/**
170+
* Generates audit outputs from bundle stats tree and configurations
171+
*/
172+
export function generateAudits(
173+
bundleStatsTree: BundleStatsTree,
174+
configs: BundleStatsConfig[],
175+
options: { grouping?: GroupingOptions[]; pruning?: PruningOptions },
176+
): AuditOutput[] {
177+
return configs.map(config => {
178+
const filteredTree = filterUnifiedTreeByConfigSingle(
179+
bundleStatsTree,
180+
config,
181+
);
182+
183+
if (!filteredTree) {
184+
return createEmptyAudit(config);
185+
}
186+
187+
const { processedTree, totalBytes, fileCount } = processTreeForAudit(
188+
filteredTree,
189+
options,
190+
);
191+
192+
return createAuditOutput(config, processedTree, totalBytes, fileCount);
193+
});
194+
}

0 commit comments

Comments
 (0)