Skip to content

fix(bundlechecker): Only externalize React/react-dom when declared - #492

Merged
aversini merged 2 commits into
mainfrom
fix(bundlechecker)-Only-externalize-React/react-dom-when-declared
Feb 1, 2026
Merged

aversini merged 2 commits into
mainfrom
fix(bundlechecker)-Only-externalize-React/react-dom-when-declared

Conversation

@aversini

@aversini aversini commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator

Make React/react-dom externalization conditional on the package's declared dependencies/peerDependencies. Updates bundler.getExternals to accept packageDependencies and only mark react/react-dom as externals when present (and never externalize the package being checked). Pass package dependency info into getExternals from checkBundleSize and adjust the cache key logic to reflect user-specified externals rather than computed defaults. Update tests to cover dependency/peerDependency cases and react/react-dom self-checks, and refresh README/CLI help text to document the new "smart externalization" behavior.

Make React/react-dom externalization conditional on the package's declared dependencies/peerDependencies. Updates bundler.getExternals to accept packageDependencies and only mark react/react-dom as externals when present (and never externalize the package being checked). Pass package dependency info into getExternals from checkBundleSize and adjust the cache key logic to reflect user-specified externals rather than computed defaults. Update tests to cover dependency/peerDependency cases and react/react-dom self-checks, and refresh README/CLI help text to document the new "smart externalization" behavior.
Reformatted several inline // comments into multiline /** ... */ block/JSDoc-style comments for clarity and line-wrapping. Changes touch getExternals and checkBundleSize in packages/bundlecheck/src/bundler.ts and the cache key explanation in packages/bundlecheck/src/index.ts. No functional behavior was changed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates bundle externalization logic so that React and React-DOM are only treated as externals when they are actual dependencies/peerDependencies of the target package, and aligns cache keying and docs/CLI help with this behavior.

Changes:

  • Refined getExternals to depend on a package’s declared dependencies/peerDependencies, and ensured React/React-DOM are not externalized when analyzing their own packages.
  • Updated checkBundleSize, library API (getBundleStats/trend path), and CLI cache key computation to use user-specified externals (plus noExternal) rather than previously hard-coded defaults.
  • Adjusted tests and README/CLI help text to cover the new “smart externalization” behavior and clarify how --external and --no-external interact with React/React-DOM.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/bundlecheck/src/parse.ts Updated CLI flag description for --external to describe the new automatic React/React-DOM externalization behavior and removed the now-unused DEFAULT_EXTERNALS import.
packages/bundlecheck/src/index.ts Stopped importing getExternals and changed cache key construction in getBundleStats to depend only on user-specified externals and noExternal, with updated comments and option docs to match.
packages/bundlecheck/src/bundler.ts Reworked getExternals to conditionally include React/React-DOM based on the package’s dependencies/peerDependencies (and never for the package itself), wiring it into checkBundleSize via the computed dependency list.
packages/bundlecheck/src/__tests__/bundler.test.ts Updated and extended tests to assert the new behavior for packages with/without React/React-DOM in dependencies/peerDependencies, including self-checks for react and cases with additional externals.
packages/bundlecheck/README.md Documented “smart externalization” semantics, clarified noExternal behavior for both CLI and library API, and annotated examples to show when React/React-DOM appear in externals based on peer dependency declarations.

Comment thread packages/bundlecheck/README.md
@aversini
aversini merged commit 1f9ae9f into main Feb 1, 2026
6 checks passed
@aversini
aversini deleted the fix(bundlechecker)-Only-externalize-React/react-dom-when-declared branch February 1, 2026 14:59
@aversini aversini mentioned this pull request Feb 1, 2026
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.

2 participants