Skip to content

Commit fb8f058

Browse files
authored
fix: prevent empty Vite 8 stats from breaking the build (#184)
No stable Vite 8 release exists yet, so the stats generator wrote an empty array to data/vite-version-stats.json, which TypeScript infers as never[] and breaks every chart component (vp check failure in the Update Vite Stats workflow). - Add a typed apps/dashboard/src/data/viteStats.ts wrapper so empty data type-checks as ViteStat[] instead of never[] - Point all stats importers at the typed module - Skip writing the stats file when no versions are collected so existing tracked data isn't clobbered until Vite 8 ships
1 parent bf33f4a commit fb8f058

6 files changed

Lines changed: 34 additions & 7 deletions

File tree

apps/dashboard/src/components/vite/BuildTimeChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
YAxis,
1212
} from "recharts";
1313
import * as semver from "semver";
14-
import viteStats from "../../../../../data/vite-version-stats.json";
14+
import { viteStats } from "../../data/viteStats";
1515

1616
const buildTimeData = viteStats
1717
.map((stat) => ({

apps/dashboard/src/components/vite/BundleSizeChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
YAxis,
1313
} from "recharts";
1414
import * as semver from "semver";
15-
import viteStats from "../../../../../data/vite-version-stats.json";
15+
import { viteStats } from "../../data/viteStats";
1616

1717
const sortedViteStats = [...viteStats].toSorted((a, b) => semver.compare(a.version, b.version));
1818

apps/dashboard/src/components/vite/StatsCards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from "react";
22
import { formatNumberWithCommas } from "@vibe/utils";
3-
import viteStats from "../../../../../data/vite-version-stats.json";
3+
import { viteStats } from "../../data/viteStats";
44

55
export function StatsCards() {
66
const stats = useMemo(() => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import rawViteStats from "../../../../data/vite-version-stats.json";
2+
3+
export interface ViteStatFile {
4+
path: string;
5+
size: number;
6+
type: string;
7+
}
8+
9+
export interface ViteStat {
10+
version: string;
11+
timestamp: string;
12+
publicationDate: string;
13+
files: ViteStatFile[];
14+
totalSize: number;
15+
buildTime: number;
16+
}
17+
18+
// Typed view of the generated stats. The underlying JSON can be an empty array
19+
// (e.g. before any stable Vite 8 release exists), which would otherwise be
20+
// inferred as `never[]` and break every property access downstream.
21+
export const viteStats = rawViteStats as ViteStat[];

apps/dashboard/src/pages/ViteStatsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PageHeader } from "@vibe/shared";
22
import { Badge } from "@vibe/ui";
33
import { BarChart3, Clock, Package, TrendingUp } from "lucide-react";
44
import { useState } from "react";
5-
import viteStatsData from "../../../../data/vite-version-stats.json";
5+
import { viteStats as viteStatsData } from "../data/viteStats";
66
import { PageContainer } from "../components/layout/PageContainer";
77
import ViteStats from "../ViteStats";
88

tools/override-vite.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,15 @@ async function collectAllVersionStats() {
345345
console.log("\n🔄 Restoring original package.json...");
346346
writeFileSync(DASHBOARD_PACKAGE_PATH, originalPackageJson);
347347

348-
// Save results
349-
console.log(`\n💾 Saving results to ${STATS_OUTPUT_PATH}...`);
350-
writeFileSync(STATS_OUTPUT_PATH, JSON.stringify(allStats, null, 2));
348+
// Save results. Skip writing an empty dataset (e.g. when no stable Vite 8
349+
// release exists yet) so we don't clobber the existing tracked stats and
350+
// break the type-checked dashboard build.
351+
if (allStats.length === 0) {
352+
console.log(`\n⏭️ No stats collected — leaving ${STATS_OUTPUT_PATH} unchanged.`);
353+
} else {
354+
console.log(`\n💾 Saving results to ${STATS_OUTPUT_PATH}...`);
355+
writeFileSync(STATS_OUTPUT_PATH, JSON.stringify(allStats, null, 2));
356+
}
351357

352358
console.log("\n==================== ANALYSIS COMPLETE ====================");
353359
console.log(`📊 Analysis Summary:`);

0 commit comments

Comments
 (0)