Skip to content

Commit f4901fb

Browse files
ChumpChiefclaude
andauthored
fix(bundle-analysis): publish analyzer.json as a separate bundleAnalyzerJson artifact (#27246)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9d9ac55 commit f4901fb

12 files changed

Lines changed: 114 additions & 39 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ legacy.d.ts
3838

3939
# Bundle analysis artifacts
4040
bundleAnalysis
41+
bundleAnalyzerJson
4142

4243
# Misc pipeline artifacts
4344
artifacts

build-tools/packages/build-cli/docs/generate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ USAGE
128128
$ flub generate bundleSizeDiff [--json] [-v | --quiet] [--localReportPath <value>] [--outputDir <value>]
129129
130130
FLAGS
131-
--localReportPath=<value> [default: ./artifacts/bundleAnalysis] Path to the locally-collected bundle reports for the
132-
PR (as produced by `flub generate bundleStats`).
131+
--localReportPath=<value> [default: ./artifacts/bundleAnalyzerJson] Path to the locally-collected bundle reports for
132+
the PR (as produced by `flub generate bundleStats`).
133133
--outputDir=<value> [default: ./artifacts/bundleSizeDiff] Directory to write result.json or error.json into.
134134
135135
LOGGING FLAGS

build-tools/packages/build-cli/src/commands/generate/bundleSizeDiff.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const adoConstants = {
2222
orgUrl: "https://dev.azure.com/fluidframework",
2323
projectName: "public",
2424
ciBuildDefinitionId: 48,
25-
bundleAnalysisArtifactName: "bundleAnalysis",
25+
artifactName: "bundleAnalyzerJson",
2626
} as const;
2727

28-
// Default path to the PR's locally-collected bundle reports.
28+
// Default path to the PR's locally-collected analyzer.json files.
2929
// Matches where `flub generate bundleStats` (invoked via `npm run bundle-analysis:collect`) writes.
30-
const defaultLocalReportPath = "./artifacts/bundleAnalysis";
30+
const defaultLocalReportPath = "./artifacts/bundleAnalyzerJson";
3131

3232
// Default output directory. The pipeline publishes this directory as the `bundleSizeDiff`
3333
// artifact.

build-tools/packages/build-cli/src/commands/generate/bundleStats.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ export default class GenerateBundlestats extends BaseCommand<typeof GenerateBund
4040
this.error("failed to get package information");
4141
}
4242

43-
// Check each package location for a bundleAnalysis folder
44-
// and copy it to a central location
43+
// Check each package location for a bundleAnalysis folder (telemetry-feeding
44+
// artifact: report.html, report.json, bundleStats.msp.gz) and a sibling
45+
// bundleAnalyzerJson folder (PR-comparison-feeding artifact: analyzer.json),
46+
// and copy each to its own central staging location. The two artifacts are
47+
// kept separate because the FF-internal telemetry handler walks every .json
48+
// under the bundleAnalysis artifact and would mis-parse analyzer.json.
4549
let hasSmallAssetError = false;
4650
const analysesDestPath = path.join(process.cwd(), "artifacts/bundleAnalysis");
51+
const analyzerJsonDestPath = path.join(process.cwd(), "artifacts/bundleAnalyzerJson");
4752

4853
for (const pkg of pkgList) {
4954
if (pkg.path === undefined) {
@@ -82,6 +87,12 @@ export default class GenerateBundlestats extends BaseCommand<typeof GenerateBund
8287

8388
copySync(packageAnalysisPath, path.join(analysesDestPath, pkg.name));
8489
}
90+
91+
const packageAnalyzerJsonPath = path.join(pkg.path, "bundleAnalyzerJson");
92+
if (existsSync(packageAnalyzerJsonPath)) {
93+
this.log(`found bundleAnalyzerJson for ${pkg.name}`);
94+
copySync(packageAnalyzerJsonPath, path.join(analyzerJsonDestPath, pkg.name));
95+
}
8596
}
8697

8798
if (hasSmallAssetError) {

build-tools/packages/bundle-size-tools/api-report/bundle-size-tools.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ export interface GetBundleSummariesFromAnalyzerArgs {
142142
export function getPriorCommit(baseCommit: string): string;
143143

144144
// @public
145-
export function getZipObjectFromArtifact(adoConnection: WebApi, projectName: string, buildNumber: number, bundleAnalysisArtifactName: string): Promise<JSZip>;
145+
export function getZipObjectFromArtifact(adoConnection: WebApi, projectName: string, buildNumber: number, artifactName: string): Promise<JSZip>;
146146

147147
// @public (undocumented)
148148
export interface IADOConstants {
149149
// (undocumented)
150-
buildsToSearch?: number;
150+
artifactName: string;
151151
// (undocumented)
152-
bundleAnalysisArtifactName: string;
152+
buildsToSearch?: number;
153153
// (undocumented)
154154
ciBuildDefinitionId: number;
155155
// (undocumented)

build-tools/packages/bundle-size-tools/src/ADO/AdoArtifactFileProvider.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function getZipObjectFromArtifact(
3636
adoConnection: WebApi,
3737
projectName: string,
3838
buildNumber: number,
39-
bundleAnalysisArtifactName: string,
39+
artifactName: string,
4040
): Promise<JSZip> {
4141
const buildApi = await adoConnection.getBuildApi();
4242

@@ -51,17 +51,14 @@ export async function getZipObjectFromArtifact(
5151
const artifactStream = await buildApi.getArtifactContentZip(
5252
projectName,
5353
buildNumber,
54-
bundleAnalysisArtifactName,
54+
artifactName,
5555
);
5656
// Undo hack from above
5757
buildApi.createAcceptHeader = originalCreateAcceptHeader;
5858

5959
// We want our relative paths to be clean, so navigating JsZip into the top level folder
60-
const result = (await unzipStream(artifactStream)).folder(bundleAnalysisArtifactName);
61-
assert(
62-
result,
63-
`getZipObjectFromArtifact could not find the folder ${bundleAnalysisArtifactName}`,
64-
);
60+
const result = (await unzipStream(artifactStream)).folder(artifactName);
61+
assert(result, `getZipObjectFromArtifact could not find the folder ${artifactName}`);
6562

6663
return result;
6764
}

build-tools/packages/bundle-size-tools/src/ADO/AdoSizeComparator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,13 @@ export class ADOSizeComparator {
165165
// Baseline build succeeded
166166
console.log(`Found baseline build with id: ${baselineBuild.id}`);
167167
console.log(`projectName: ${this.adoConstants.projectName}`);
168-
console.log(
169-
`bundleAnalysisArtifactName: ${this.adoConstants.bundleAnalysisArtifactName}`,
170-
);
168+
console.log(`artifactName: ${this.adoConstants.artifactName}`);
171169

172170
baselineZip = await getZipObjectFromArtifact(
173171
this.adoConnection,
174172
this.adoConstants.projectName,
175173
baselineBuild.id,
176-
this.adoConstants.bundleAnalysisArtifactName,
174+
this.adoConstants.artifactName,
177175
).catch((error) => {
178176
console.log(`Error unzipping object from artifact: ${error.message}`);
179177
console.log(`Error stack: ${error.stack}`);

build-tools/packages/bundle-size-tools/src/ADO/Constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export interface IADOConstants {
1818
// Note: Assumes CI and PR builds both run in the same org/project
1919
prBuildDefinitionId?: number;
2020

21-
// The name of the build artifact that contains the bundle size artifacts
22-
bundleAnalysisArtifactName: string;
21+
// The name of the build artifact that contains the bundle size data
22+
artifactName: string;
2323

2424
// The guid of the repo
2525
// Used to post/update comments in ADO

examples/utils/bundle-size-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
2121
"check:biome": "biome check .",
2222
"check:format": "npm run check:biome",
23-
"clean": "rimraf --glob build dist lib bundleAnalysis \"**/*.tsbuildinfo\" \"**/*.build.log\" nyc",
23+
"clean": "rimraf --glob build dist lib bundleAnalysis bundleAnalyzerJson \"**/*.tsbuildinfo\" \"**/*.build.log\" nyc",
2424
"eslint": "eslint --quiet --format stylish src",
2525
"eslint:fix": "eslint --quiet --format stylish src --fix --fix-type problem,suggestion,layout",
2626
"explore:tree": "fluid-build . --task webpack && source-map-explorer ./build/sharedTree.js --html bundleAnalysis/reportTree.html",

examples/utils/bundle-size-tests/webpack.config.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,13 @@ module.exports = {
130130
}),
131131
// Generates analyzer.json with per-asset statSize/parsedSize/gzipSize that
132132
// `flub generate bundleSizeDiff` consumes to compute the bundle-size diff.
133+
// Emitted to a sibling folder so the file ends up in its own artifact
134+
// (bundleAnalyzerJson) rather than alongside bundleAnalysis content; the
135+
// FF-internal telemetry handler walks every .json under the bundleAnalysis
136+
// artifact and would otherwise try to parse this file as webpack stats.
133137
new BundleAnalyzerPlugin({
134138
analyzerMode: "json",
135-
reportFilename: path.resolve(process.cwd(), "bundleAnalysis/analyzer.json"),
139+
reportFilename: path.resolve(process.cwd(), "bundleAnalyzerJson/analyzer.json"),
136140
}),
137141
// Generates bundleStats.msp.gz (compressed webpack stats; consumed by the
138142
// FF-internal telemetry handler).

0 commit comments

Comments
 (0)