Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import path from "node:path";
import {
ADOSizeComparator,
type BundleComparison,
type BundleMetric,
bundlesContainNoChanges,
getAzureDevopsApi,
} from "@fluidframework/bundle-size-tools";
Expand All @@ -33,10 +32,6 @@ const defaultLocalReportPath = "./artifacts/bundleAnalyzerJson";
// artifact.
const defaultOutputDir = "./artifacts/bundleSizeDiff";

// Any single non-total metric that grows by more than this threshold is considered a
// regression.
const sizeRegressionThresholdBytes = 5120;

// Output file names. Only one of these is present per run: `result.json` when the
// comparison produced a meaningful result, or `error.json` when it did not. Consumers
// use file existence as the success/failure discriminator without needing to parse JSON.
Expand All @@ -46,17 +41,14 @@ const errorFileName = "error.json";
/**
* Shape of the `result.json` file produced on a successful comparison, discriminated by
* `kind`. On `"no-changes"`, the comparison ran and found no size deltas. On `"changes"`,
* the comparison found size deltas; `comparison` holds the diff and `sizeRegressionDetected`
* flags any non-total metric that grew past the threshold.
* the comparison found size deltas and `comparison` holds the diff. The producer is
* unopinionated about what constitutes a "regression" — consumers apply their own thresholds.
*/
type BundleSizeDiffResult = {
prNumber: number;
baseCommit: string;
targetBranch: string;
} & (
| { kind: "no-changes" }
| { kind: "changes"; sizeRegressionDetected: boolean; comparison: BundleComparison[] }
);
} & ({ kind: "no-changes" } | { kind: "changes"; comparison: BundleComparison[] });

/**
* Shape of the `error.json` file produced when the command could not produce a comparison
Expand All @@ -70,18 +62,6 @@ interface BundleSizeDiffError {
error: string;
}

/**
* Compute whether any bundle shows a metric growing by more than the regression threshold.
*/
function detectSizeRegression(comparison: BundleComparison[]): boolean {
return comparison.some((bundle: BundleComparison) =>
Object.values(bundle.commonBundleMetrics).some(
({ baseline, compare }: { baseline: BundleMetric; compare: BundleMetric }) =>
compare.parsedSize - baseline.parsedSize > sizeRegressionThresholdBytes,
),
);
}

export default class GenerateBundleSizeDiff extends BaseCommand<
typeof GenerateBundleSizeDiff
> {
Expand Down Expand Up @@ -134,10 +114,8 @@ export default class GenerateBundleSizeDiff extends BaseCommand<
adoConnection,
localReportPath,
targetBranch,
undefined,
ADOSizeComparator.naiveFallbackCommitGenerator,
);
const comparisonResult = await sizeComparator.getSizeComparison(false);
const comparisonResult = await sizeComparator.getSizeComparison();

const resolvedOutputDir = path.resolve(process.cwd(), outputDir);
await mkdir(resolvedOutputDir, { recursive: true });
Expand Down Expand Up @@ -183,12 +161,7 @@ export default class GenerateBundleSizeDiff extends BaseCommand<
};
const result: BundleSizeDiffResult = bundlesContainNoChanges(comparison)
? { ...common, kind: "no-changes" }
: {
...common,
kind: "changes",
sizeRegressionDetected: detectSizeRegression(comparison),
comparison,
};
: { ...common, kind: "changes", comparison };

await writeFile(resultPath, JSON.stringify(result, undefined, 2));
this.info(`Wrote ${resultPath}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,15 @@ import type { Build } from 'azure-devops-node-api/interfaces/BuildInterfaces';
import type { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import type JSZip from 'jszip';
import { WebApi } from 'azure-devops-node-api';
import type Webpack from 'webpack';

// @public (undocumented)
export class ADOSizeComparator {
constructor(
adoConstants: IADOConstants,
adoConnection: WebApi,
localReportPath: string,
targetBranch: string,
adoBuildId: number | undefined,
getFallbackCommit?: ((startingCommit: string) => Generator<string>) | undefined);
getSizeComparison(tagWaiting: boolean): Promise<SizeComparison>;
static naiveFallbackCommitGenerator(startingCommit: string): Generator<string>;
}

// @public (undocumented)
export interface BannedModule {
moduleName: string;
reason: string;
}

// @public
export class BannedModulesPlugin {
constructor(options: BannedModulesPluginOptions);
// (undocumented)
apply(compiler: Webpack.Compiler): void;
}

// @public (undocumented)
export interface BannedModulesPluginOptions {
// (undocumented)
bannedModules: BannedModule[];
targetBranch: string);
getSizeComparison(): Promise<SizeComparison>;
}

// @public
Expand Down Expand Up @@ -124,9 +101,6 @@ export interface GetBuildOptions {
// @public
export function getBuilds(adoConnection: WebApi, options: GetBuildOptions): Promise<Build[]>;

// @public
export function getBuildTagForCommit(commitHash: string): string;

// @public
export function getBundleSummariesFromAnalyzer(args: GetBundleSummariesFromAnalyzerArgs): Promise<BundleSummaries>;

Expand All @@ -138,9 +112,6 @@ export interface GetBundleSummariesFromAnalyzerArgs {
getAnalyzerJson: (relativePath: string) => Promise<BundleAnalyzerPlugin.JsonReport>;
}

// @public (undocumented)
export function getPriorCommit(baseCommit: string): string;

// @public
export function getZipObjectFromArtifact(adoConnection: WebApi, projectName: string, buildNumber: number, artifactName: string): Promise<JSZip>;

Expand All @@ -155,11 +126,7 @@ export interface IADOConstants {
// (undocumented)
orgUrl: string;
// (undocumented)
prBuildDefinitionId?: number;
// (undocumented)
projectName: string;
// (undocumented)
projectRepoGuid?: string;
}

// @public
Expand Down
3 changes: 1 addition & 2 deletions build-tools/packages/bundle-size-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"dependencies": {
"azure-devops-node-api": "^11.2.0",
"jszip": "^3.10.1",
"typescript": "~5.4.5",
"webpack": "^5.103.0"
"typescript": "~5.4.5"
},
"devDependencies": {
"@biomejs/biome": "~2.4.5",
Expand Down
Loading
Loading