Unverified Commit 6d80e6e5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add version for stats (#21823)

Adds versioning for the stats output
parent 55365268
......@@ -6,6 +6,8 @@ import { spans } from './profiling-plugin'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { tracer, traceAsyncFn } from '../../tracer'
const STATS_VERSION = 0
// This plugin creates a stats.json for a build when enabled
export default class BuildStatsPlugin {
private distDir: string
......@@ -29,7 +31,10 @@ export default class BuildStatsPlugin {
const fileStream = fs.createWriteStream(
path.join(this.distDir, 'next-stats.json')
)
const jsonStream = bfj.streamify(statsJson)
const jsonStream = bfj.streamify({
version: STATS_VERSION,
stats: statsJson,
})
jsonStream.pipe(fileStream)
jsonStream.on('error', reject)
fileStream.on('error', reject)
......
......@@ -14,7 +14,10 @@ describe('Build Stats', () => {
await nextBuild(appDir)
expect(await fs.pathExists(statsPath)).toBe(true)
const statsData = await fs.readFile(statsPath, 'utf8')
JSON.parse(statsData)
const statsString = await fs.readFile(statsPath, 'utf8')
const statsData = JSON.parse(statsString)
expect(statsData.version).toBe(0)
expect(typeof statsData.stats).toBe('object')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment