Skip to content

Commit 213b363

Browse files
CopilotBoshen
andauthored
Fix semver ordering in rolldown stats charts (#68)
Co-authored-by: Boshen <[email protected]>
1 parent 0d129d8 commit 213b363

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

apps/dashboard/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
"react": "^19.1.1",
1515
"react-dom": "^19.1.1",
1616
"react-router-dom": "^7.8.2",
17-
"recharts": "^2.12.6"
17+
"recharts": "^2.12.6",
18+
"semver": "^7.7.2"
1819
},
1920
"devDependencies": {
2021
"@tailwindcss/vite": "^4.1.13",
2122
"@types/react": "^19.1.10",
2223
"@types/react-dom": "^19.1.7",
2324
"@types/react-router-dom": "^5.3.3",
25+
"@types/semver": "^7.7.1",
2426
"rolldown-vite": "7.1.5",
2527
"tailwindcss": "^4.1.13",
2628
"typescript": "catalog:"

apps/dashboard/src/RolldownStats.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
XAxis,
1212
YAxis,
1313
} from 'recharts';
14+
import * as semver from 'semver';
1415
import rolldownStats from '../../../rolldown-version-stats.json';
1516

1617
// Utility function to format numbers with commas
@@ -33,10 +34,13 @@ const buildTimeData = rolldownStats.map(stat => ({
3334
value: stat.buildTime,
3435
version: stat.version,
3536
publicationDate: (stat as any).publicationDate,
36-
})).sort((a, b) => a.value - b.value); // Sort from smallest to largest
37+
})).sort((a, b) => semver.compare(a.version, b.version)); // Sort by semantic version
3738

3839
// Calculate bundle size differences between consecutive versions
39-
const bundleSizeDiffData = rolldownStats.map((stat, index) => {
40+
// First, sort the rolldown stats by semver order
41+
const sortedRolldownStats = [...rolldownStats].sort((a, b) => semver.compare(a.version, b.version));
42+
43+
const bundleSizeDiffData = sortedRolldownStats.map((stat, index) => {
4044
if (index === 0) {
4145
// For the first version, show 0 difference or could show absolute value
4246
return {
@@ -50,7 +54,7 @@ const bundleSizeDiffData = rolldownStats.map((stat, index) => {
5054
};
5155
}
5256

53-
const prevSize = rolldownStats[index - 1].totalSize;
57+
const prevSize = sortedRolldownStats[index - 1].totalSize;
5458
const currentSize = stat.totalSize;
5559
const diff = currentSize - prevSize;
5660

@@ -63,7 +67,7 @@ const bundleSizeDiffData = rolldownStats.map((stat, index) => {
6367
version: stat.version,
6468
publicationDate: (stat as any).publicationDate,
6569
};
66-
}).sort((a, b) => a.value - b.value); // Sort from smallest to largest
70+
}); // Already sorted by semver order, no need to sort again
6771

6872
interface RolldownStatsProps {
6973
selectedMetric: string;

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)