Skip to content

Commit d9891a1

Browse files
author
Michael Hladky
committed
refactor: add sonda
1 parent 4ee3992 commit d9891a1

File tree

13 files changed

+1258
-36
lines changed

13 files changed

+1258
-36
lines changed

packages/plugin-bundle-stats/CONTRIBUTING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ cd packages/plugin-bundle-stats/mocks/fixtures/node-minimal
1414
npm run build
1515

1616
# Or generate artifacts for specific bundlers
17-
npm run build:esbuild # → dist/esbuild/stats.json
18-
npm run build:webpack # → dist/webpack/stats.json
19-
npm run build:rsbuild # → dist/rsbuild/stats.json
20-
npm run build:vite # → dist/vite/stats.json
17+
npm run build:esbuild # → dist/esbuild/stats.json
18+
npm run build:esbuild-sonda # → dist/esbuild-sonda/sonda-report.json
19+
npm run build:webpack # → dist/webpack/stats.json
20+
npm run build:rsbuild # → dist/rsbuild/stats.json
21+
npm run build:vite # → dist/vite/stats.json
2122
```
2223

2324
### Running the Plugin
@@ -27,6 +28,7 @@ Once the artifacts are generated, you can run the Code PushUp plugin to analyze
2728
```bash
2829
# Run plugin analysis for each bundler
2930
nx run plugin-bundle-stats:code-pushup-minimal-esbuild
31+
nx run plugin-bundle-stats:code-pushup-minimal-esbuild-sonda
3032
nx run plugin-bundle-stats:code-pushup-minimal-webpack
3133
nx run plugin-bundle-stats:code-pushup-minimal-rsbuild
3234
nx run plugin-bundle-stats:code-pushup-minimal-vite
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { CoreConfig } from '../models/src/index.js';
2+
import bundleStatsPlugin from './src';
3+
4+
const config: CoreConfig = {
5+
plugins: [
6+
await bundleStatsPlugin({
7+
artifactsPaths:
8+
'packages/plugin-bundle-stats/mocks/fixtures/stats/esbuild-minimal.sonda-report.json',
9+
bundler: 'sonda',
10+
audits: [
11+
{
12+
slug: 'bundle-size',
13+
title: 'Bundle Size Analysis',
14+
description: 'Analyzes bundle size using Sonda report',
15+
selection: {
16+
mode: 'bundle',
17+
includeOutputs: ['**/*.js'],
18+
},
19+
scoring: {
20+
totalSize: 100_000,
21+
},
22+
},
23+
],
24+
}),
25+
],
26+
categories: [
27+
{
28+
slug: 'performance',
29+
title: '⚡ Performance',
30+
description: 'Bundle performance analysis using Sonda',
31+
refs: [
32+
{
33+
type: 'audit',
34+
plugin: 'bundle-stats',
35+
slug: 'bundle-size',
36+
weight: 1,
37+
},
38+
],
39+
},
40+
],
41+
};
42+
43+
export default (async () => {
44+
return config;
45+
})();
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"metadata": {
3+
"version": "0.10.1",
4+
"integration": "esbuild",
5+
"sources": false,
6+
"gzip": false,
7+
"brotli": false
8+
},
9+
"resources": [
10+
{
11+
"kind": "asset",
12+
"name": "dist/esbuild-sonda/bin.js",
13+
"type": "script",
14+
"uncompressed": 104,
15+
"gzip": 0,
16+
"brotli": 0
17+
},
18+
{
19+
"kind": "asset",
20+
"name": "dist/esbuild-sonda/chunks/chunk.js",
21+
"type": "script",
22+
"uncompressed": 2234,
23+
"gzip": 0,
24+
"brotli": 0
25+
},
26+
{
27+
"kind": "asset",
28+
"name": "dist/esbuild-sonda/index.js",
29+
"type": "script",
30+
"uncompressed": 63,
31+
"gzip": 0,
32+
"brotli": 0
33+
},
34+
{
35+
"kind": "filesystem",
36+
"name": "src/bin.ts",
37+
"type": "script",
38+
"format": "esm",
39+
"uncompressed": 78
40+
},
41+
{
42+
"kind": "filesystem",
43+
"name": "src/index.ts",
44+
"type": "script",
45+
"format": "esm",
46+
"uncompressed": 147
47+
},
48+
{
49+
"kind": "filesystem",
50+
"name": "src/lib/feature-1.ts",
51+
"type": "script",
52+
"format": "esm",
53+
"uncompressed": 70
54+
},
55+
{
56+
"kind": "filesystem",
57+
"name": "src/lib/utils/format.ts",
58+
"type": "script",
59+
"format": "esm",
60+
"uncompressed": 1035
61+
},
62+
{
63+
"kind": "filesystem",
64+
"name": "src/lib/utils/math.ts",
65+
"type": "script",
66+
"format": "esm",
67+
"uncompressed": 1035
68+
}
69+
],
70+
"connections": [
71+
{
72+
"kind": "import",
73+
"source": "src/lib/feature-1.ts",
74+
"target": "src/lib/utils/format.ts",
75+
"original": "./utils/format"
76+
},
77+
{
78+
"kind": "import",
79+
"source": "src/index.ts",
80+
"target": "src/lib/feature-1.ts",
81+
"original": "./lib/feature-1"
82+
},
83+
{
84+
"kind": "import",
85+
"source": "src/index.ts",
86+
"target": "src/lib/utils/math.ts",
87+
"original": "./lib/utils/math"
88+
},
89+
{
90+
"kind": "import",
91+
"source": "src/bin.ts",
92+
"target": "src/index.ts",
93+
"original": "./index"
94+
},
95+
{
96+
"kind": "entrypoint",
97+
"source": "src/index.ts",
98+
"target": "dist/esbuild-sonda/index.js",
99+
"original": null
100+
},
101+
{
102+
"kind": "entrypoint",
103+
"source": "src/bin.ts",
104+
"target": "dist/esbuild-sonda/bin.js",
105+
"original": null
106+
}
107+
],
108+
"dependencies": [],
109+
"issues": [],
110+
"sourcemaps": []
111+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { build } = require('esbuild');
2+
const sonda = require('sonda/esbuild').default;
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const config = {
7+
entryPoints: ['src/index.ts', 'src/bin.ts'],
8+
bundle: true,
9+
outdir: 'dist/esbuild-sonda',
10+
entryNames: '[name]',
11+
chunkNames: 'chunks/[name]',
12+
metafile: true,
13+
format: 'esm',
14+
platform: 'node',
15+
target: 'node18',
16+
sourcemap: false,
17+
minify: false,
18+
splitting: true,
19+
external: [],
20+
treeShaking: true,
21+
loader: {
22+
'.css': 'css',
23+
'.png': 'file',
24+
'.jpg': 'file',
25+
'.jpeg': 'file',
26+
'.gif': 'file',
27+
'.svg': 'file',
28+
},
29+
logLevel: 'info',
30+
plugins: [
31+
sonda({
32+
filename: 'sonda-report.json',
33+
format: 'json',
34+
open: false,
35+
}),
36+
],
37+
};
38+
39+
async function buildWithStats() {
40+
try {
41+
const result = await build(config);
42+
43+
// Write metafile to stats.json (for compatibility)
44+
if (result.metafile) {
45+
const statsPath = path.join(config.outdir, 'stats.json');
46+
fs.writeFileSync(statsPath, JSON.stringify(result.metafile, null, 2));
47+
console.log(`Stats written to ${statsPath}`);
48+
}
49+
50+
console.log('Build completed successfully with Sonda plugin!');
51+
console.log('Sonda report: .sonda/sonda-report.json');
52+
return result;
53+
} catch (error) {
54+
console.error('Build failed:', error);
55+
process.exit(1);
56+
}
57+
}
58+
59+
// If this file is run directly, execute the build
60+
if (require.main === module) {
61+
buildWithStats();
62+
}
63+
64+
module.exports = { config, buildWithStats };

0 commit comments

Comments
 (0)