Skip to content

Support for webpack scenarios and fixes for bundleAnalysisRepo (--webpack-dir / fetch-on-reuse) - #27627

Merged
Tommy Brosman (TommyBrosman) merged 6 commits into
microsoft:mainfrom
TommyBrosman:tbrosman/bundle-repo-fixes
Jul 6, 2026
Merged

Support for webpack scenarios and fixes for bundleAnalysisRepo (--webpack-dir / fetch-on-reuse)#27627
Tommy Brosman (TommyBrosman) merged 6 commits into
microsoft:mainfrom
TommyBrosman:tbrosman/bundle-repo-fixes

Conversation

@TommyBrosman

@TommyBrosman Tommy Brosman (TommyBrosman) commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This change consists of two improvements to the bundleAnalysisRepo tooling in build-cli, one of which enables webpack "scenarios."

Description

Webpack scenarios are a feature that enables the analysis of webpack configurations and specific sets of imports that are designed to match real use cases. This differs from our typical approach of using a single webpack config for repo-wide analysis. New scenarios are defined under /examples/utils/bundle-size-tests/scenarios.

  1. --webpack-dir flag: Decouples the directory that webpack runs in (and where analyzer.json / compareBundlesOutput are collected) from --package-dir (where build:compile runs). This lets a scenario subdirectory that only contains a webpack config be built and collected correctly. Previously npm run webpack in a config-less subdir walked up to the parent package.json and built the wrong config. The flag is added to generate bundleAnalysisRepo, generate bundleAnalysisReposWithComparison, and check bundleAnalysisReposComparison (defaulting to --package-dir, so existing usage is unchanged).

  2. Fetch-on-reuse for the inner base-repo clone: When an inner base-repo clone already exists, ensureInnerRepoAtRevision now runs git fetch origin --no-tags --prune before checkout, bringing a reused clone to parity with a fresh one. This fixes the stale-clone fatal: unable to read tree <sha> failure for merge-base / revision SHAs created after the original clone, without forcing a full re-clone.

Also adds an encapsulated-no-tree bundle scenario under examples/utils/bundle-size-tests used to exercise and validate both features end-to-end.

Reviewer Guidance

  • What kind of documentation would you like to see around defining scenarios or individual scenarios?

Todo

  • Ensure the webpack configs in scenarios can be linted.
    • I ended up going the CJS route. webpack-bundle-analyzer has no types and making the config a CJS seemed better than enabling skipLibCheck for the whole package.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (411 lines, 13 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

@TommyBrosman Tommy Brosman (TommyBrosman) changed the title Add encapsulated-no-tree bundle scenario and bundleAnalysisRepo --webpack-dir / fetch-on-reuse fixes Support for webpack scenarios and fixes for bundleAnalysisRepo (--webpack-dir / fetch-on-reuse) Jun 30, 2026
@TommyBrosman
Tommy Brosman (TommyBrosman) marked this pull request as ready for review June 30, 2026 23:47
Copilot AI review requested due to automatic review settings June 30, 2026 23:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

… CommonJS

Convert the scenario's webpack.config.cts to webpack.config.cjs so webpack auto-detects it via 'npx webpack' (matching the sibling root config). Because a CommonJS config needs no TS loader and isn't type-checked, terser-webpack-plugin's Node16 .d.ts issue no longer surfaces.

As a result, drop skipLibCheck and the webpack.config.cts entry from tsconfig.json (the config is no longer part of the TS program) and remove the now-unneeded eslint override. build:compile's tsc passes clean without skipLibCheck, and 'flub generate bundleAnalysisRepo' collects the bundle stats successfully.

Also add a justification to the import-x/no-internal-modules eslint-disable in the scenario's index.ts.
Collapse the tsconfig 'include' array onto a single line so 'biome check' passes; the multi-line form failed the client build's format check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall idea makes sense to me. A couple of things:

  • I don't know enough of the legacy API surface to guarantee that the scenario config covered it all. Could suggest some form of programmatic validation of that as an eventual follow-up (and maybe note that in the documentation of that file).
  • A few comments below. Not an expert in webpack so I only called out the bit that stood out to me in the new scenario config; at a glance the config made sense but I could have missed something else there.

Comment thread build-tools/packages/build-cli/src/library/bundleSize/collectBundle.ts Outdated
collectBundle: replace 'npx webpack' (which can silently download webpack from the registry) with 'pnpm exec webpack --config <scenario config>' run from the package root, and add ensureWebpackInstalled() to fail early with an actionable error when the package does not declare webpack as a devDependency.

bundle-size-tests scenario: switch output.library.type from 'jsonp' to 'var' to match the sibling root webpack config.

Also clarify the --webpack-dir flag description (compareBundlesOutput subdirectory).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@TommyBrosman
Tommy Brosman (TommyBrosman) enabled auto-merge (squash) July 6, 2026 19:11
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Bundle size comparison

Base commit: e7d9f8079e0560e979d0d70a8e198a4efc655a4e
Head commit: d1964d4e1196b20db76139c79951304d27559b77

Pending — Build - client packages is running. Results will appear here when the build completes.

@TommyBrosman
Tommy Brosman (TommyBrosman) merged commit 0cda965 into microsoft:main Jul 6, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants