feat(bundle-size-tools): emit and consume analyzer.json for bundle size diff#27224
feat(bundle-size-tools): emit and consume analyzer.json for bundle size diff#27224ChumpChief wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Adds a second BundleAnalyzerPlugin instance with analyzerMode: "json" alongside the existing static-mode (HTML) instance. The new bundleAnalysis/analyzer.json is what `flub generate bundleSizeDiff` consumes for the comparison: per-asset statSize/parsedSize/gzipSize, much smaller (741KB) and more useful than the raw webpack stats. The existing report.json (raw stats) and bundleStats.msp.gz (msgpack- compressed stats) outputs remain unchanged — they're consumed by `flub generate bundleStats` sanity checks and by the FF-internal telemetry handler outside this repo, neither of which we want to risk breaking. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The producer (previous commit) now emits webpack-bundle-analyzer's analyzer.json alongside the existing bundleStats.msp.gz. Wire the consumer to read the new format internally, while keeping the prior msp.gz reader path on the public-API surface for backward compatibility. New (used internally by ADOSizeComparator): - getAnalyzerJsonFromZip / getAnalyzerJsonFromFileSystem read and parse analyzer.json. Typed with BundleAnalyzerPlugin.JsonReport from @types/webpack-bundle-analyzer (added as a devDep) so we get the producer's shape authoritatively rather than maintaining a hand-rolled subset. - getAnalyzerFilePathsFromFolder, getAnalyzerPathsFromZipObject, getAnalyzerPathsFromFileSystem — analyzer.json path discovery, paralleling the existing bundle-paths helpers. - getBundleSummariesFromAnalyzer + GetBundleSummariesFromAnalyzerArgs walk analyzer.json's pre-summarized per-asset data directly, with no WebpackStatsProcessor pipeline needed. Preserved (still exported, still functional, no longer used by ADOSizeComparator): - getStatsFileFromZip / getStatsFileFromFileSystem — the msp.gz readers. - getBundleFilePathsFromFolder still detects *.msp.gz + bundleBuddyConfig.json. - getBundleSummaries with its original (statsProcessors, getStatsFile, getBundleBuddyConfigFile) args. - DefaultStatsProcessors and the stats-processor library remain available. Output is byte-equivalent to today: BundleMetric remains parsedSize-only; no JSON-shape changes for downstream consumers (build-cli's bundleSizeDiff command, the FF-internal telemetry handler). Net effect on the public-API surface: additions only — no removed or modified exports. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (235 lines, 11 files), I've queued these reviewers:
How this works
|
|
On it! Starting review with: Correctness, Security, API Compatibility |
🔭 PR Review Fleet ReportNote This report is generated by an experimental AI review fleet and is provided as a beta feature. Findings are a starting point for discussion, not a gate. Use your own judgement. Verdict: ❌ Request Changes 0 Exterminate, 1 Squash, 2 Investigate Findings
|
|
I'm planning to skip the Fleet feedback as these will all become internal and/or change further in the followups. Primary goal of this PR is just to start producing the analyzer.json which is more generally useful. |
There was a problem hiding this comment.
Pull request overview
This PR updates the bundle size diff pipeline to produce and consume webpack-bundle-analyzer’s analyzerMode: "json" output (analyzer.json) as a smaller, pre-summarized input for bundle size comparisons, while keeping the legacy bundleStats.msp.gz path exported for now.
Changes:
- Emit
bundleAnalysis/analyzer.jsonduring bundle-size test builds (alongside existing HTML/JSON stats outputs). - Add analyzer.json discovery + readers and a new
getBundleSummariesFromAnalyzer()path in@fluidframework/bundle-size-tools. - Switch
ADOSizeComparatorto use analyzer.json summaries instead of thebundleStats.msp.gz/stats-processor pipeline.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/utils/bundle-size-tests/webpack.config.cjs | Adds a second BundleAnalyzerPlugin instance to emit analyzer.json alongside existing artifacts. |
| build-tools/pnpm-lock.yaml | Locks the newly added @types/webpack-bundle-analyzer dependency. |
| build-tools/packages/bundle-size-tools/src/index.ts | Re-exports new analyzer.json APIs from the package entrypoint. |
| build-tools/packages/bundle-size-tools/src/ADO/index.ts | Re-exports new analyzer.json APIs from the ADO sub-entrypoint. |
| build-tools/packages/bundle-size-tools/src/ADO/getBundleSummaries.ts | Introduces getBundleSummariesFromAnalyzer() and related args type. |
| build-tools/packages/bundle-size-tools/src/ADO/getBundleFilePathsFromFolder.ts | Adds getAnalyzerFilePathsFromFolder() for analyzer.json discovery. |
| build-tools/packages/bundle-size-tools/src/ADO/FileSystemBundleFileProvider.ts | Adds filesystem path discovery + JSON parsing for analyzer.json. |
| build-tools/packages/bundle-size-tools/src/ADO/AdoSizeComparator.ts | Switches comparator implementation to analyzer.json-based summaries. |
| build-tools/packages/bundle-size-tools/src/ADO/AdoArtifactFileProvider.ts | Adds zip path discovery + JSON parsing for analyzer.json. |
| build-tools/packages/bundle-size-tools/package.json | Adds @types/webpack-bundle-analyzer (devDependency). |
| build-tools/packages/bundle-size-tools/api-report/bundle-size-tools.api.md | Updates API report to include newly exported analyzer.json APIs/types. |
Files not reviewed (1)
- build-tools/pnpm-lock.yaml: Language not supported
After this PR's consumer migration, `flub generate bundleSizeDiff` reads analyzer.json instead of bundleStats.msp.gz. The producer-only commit was cherry-picked from a state where only the producer was changing, so it intentionally avoided naming `flub generate bundleSizeDiff` as a consumer of analyzer.json (true at the time) and listed it among consumers of bundleStats.msp.gz (also true at the time). Both claims become inverted once the consumer commit is in. - analyzer.json block: now names `flub generate bundleSizeDiff` as the concrete consumer. - bundleStats.msp.gz block: drops `flub generate bundleSizeDiff` from the consumer list, leaving the FF-internal telemetry handler as the sole remaining consumer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Description
webpack-bundle-analyzer's
analyzerMode: "json"output (analyzer.json) is a much smaller, pre-summarized form of the per-asset data we use for bundle-size comparisons (~750KB vs ~3.7MB forbundleStats.msp.gz, the compressed raw stats we currently consume — and ~377MB raw). We use roughly 1% of what's in the full webpack stats. Switching toanalyzer.jsonlets us drop the entireWebpackStatsProcessorpipeline (gunzip → msgpack-decode → walk → entry processor → total processor) and just read pre-summarized per-assetparsedSizedirectly.Two commits, separable for review:
examples/utils/bundle-size-tests/webpack.config.cjs): adds a secondBundleAnalyzerPlugininstance withanalyzerMode: "json", emittingbundleAnalysis/analyzer.jsonalongside the existingreport.html/report.json/bundleStats.msp.gz. Existing outputs are unchanged —flub generate bundleStatssanity checks and the FF-internal telemetry handler keep working as-is.bundle-size-tools): addsanalyzer.jsonreader functions (getAnalyzerJsonFromZip,getAnalyzerJsonFromFileSystem), path discovery (getAnalyzerFilePathsFromFolderand thegetAnalyzerPathsFrom*wrappers), andgetBundleSummariesFromAnalyzer.ADOSizeComparatorswitches to the analyzer.json path internally.result.jsonshape andBundleMetric(parsedSize-only) are unchanged, and per-entrypoint metric names/values match between the two paths. One delta: the msp.gz path's synthesized per-bundle "Total Size" metric is no longer emitted (it's derivable from the per-asset metrics if a downstream consumer needs it).The new readers use
BundleAnalyzerPlugin.JsonReportfrom@types/webpack-bundle-analyzer(added as a devDep) so the type comes from the producer authoritatively rather than a hand-rolled subset.Public-API surface is purely additive — the prior msp.gz reader path (
getStatsFileFromZip,getStatsFileFromFileSystem,getBundleSummarieswith its original args,getBundleFilePathsFromFolder's msp.gz detection,DefaultStatsProcessors, etc.) remains exported and functional. It just goes unused byADOSizeComparatorafter this change.A follow-up PR will clean up the now-dead code (the msp.gz reader path, the
WebpackStatsProcessorinfrastructure, and related types). It was left out of this PR to keep the review focused on the swap itself.Part of AB#56981 (re-enable PR bundle size comparison) — this is one of several incremental PRs that will follow PR #27158.