Skip to content

[code-infra] New bundler subcommand for package bundling#1083

Draft
brijeshb42 wants to merge 5 commits intomasterfrom
build-package
Draft

[code-infra] New bundler subcommand for package bundling#1083
brijeshb42 wants to merge 5 commits intomasterfrom
build-package

Conversation

@brijeshb42
Copy link
Copy Markdown
Contributor

@brijeshb42 brijeshb42 commented Jan 30, 2026

This PR introduces a new bundle CLI subcommand for @mui/internal-code-infra to build and bundle packages using Rollup with Babel integration.

Changes

New Features

  • New bundle CLI subcommand (pnpm code-infra bundle)

    • Supports building/bundling packages with configurable output formats (ESM, CJS, or both)
    • Adapter-based architecture for easy migration to other bundlers in the future
    • Automatically determines output file extensions based on "type" field in package.json
    • Reads entry points from package.json exports and bin fields
    • Supports source maps, and verbose logging
    • Option to preserve directory structure in output
    • Option to generate package.json in output directory
  • Rollup adapter implementation (adapter-rollup.mjs)

    • Full Babel integration via @rollup/plugin-babel
    • Node module resolution with @rollup/plugin-node-resolve
    • Environment variable replacement with @rollup/plugin-replace
    • TypeScript declaration generation via rollup-plugin-dts
    • Directive preservation (e.g., 'use client') via rollup-plugin-preserve-directives
    • Automatic externalization of dependencies and peer dependencies
  • Entry point resolution utilities (resolve-entrypoints.mjs)

    • Resolves exports entries from package.json, supporting glob patterns
    • Platform detection (node/browser/neutral) based on export conditions
    • Support for nested conditions (import, require, types, react-server, etc.)
    • Handles bin field entries for CLI tools
  • Exports field generation (generate-exports-field.mjs)

    • Generates proper exports field structure from bundler output
    • Correctly maps ESM/CJS outputs with their corresponding type definitions
    • Handles bin entries separately

Bug Fixes

  • Fix side-effect tree-shaking - Improved tree-shaking by properly handling side effects in the bundling process

  • Babel runtime interop plugin (babel-runtime-interop-plugin.mjs)

    • Replaces Rollup's inline interop helper functions with imports from @babel/runtime/helpers
    • Deduplicates _interopNamespaceCompat, _interopNamespaceDefault, and _interopNamespace helpers across output files
    • Only applies to CJS output format

Other Changes

  • Migrated babel.config.js to babel.config.mjs (ESM format)

  • Updated @mui/internal-babel-config with additional configuration options

  • Added comprehensive test suites for resolve-entrypoints and generate-exports-field utilities (1,430 lines of tests)

  • New dependencies added to code-infra:

    • @rollup/plugin-babel
    • @rollup/plugin-node-resolve
    • @rollup/plugin-replace
    • rollup
    • rollup-plugin-dts
    • rollup-plugin-preserve-directives
  • [code-infra] Migrate to rollup based package build base-ui#3901

@brijeshb42 brijeshb42 added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Jan 30, 2026
@oliviertassinari oliviertassinari temporarily deployed to build-package - code-infra-dashboard PR #1083 January 30, 2026 09:14 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 January 30, 2026 09:14 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 January 30, 2026 10:15 — with Render Destroyed
@mui-bot
Copy link
Copy Markdown

mui-bot commented Jan 30, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@brijeshb42 brijeshb42 changed the title [code-infra] New package for bundler adapter [code-infra] New bundler subcommand for package bundling Jan 30, 2026
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 January 30, 2026 13:37 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 January 30, 2026 13:59 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 January 30, 2026 14:05 — with Render Destroyed
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 8, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 20, 2026
@oliviertassinari oliviertassinari temporarily deployed to build-package - code-infra-dashboard PR #1083 February 20, 2026 15:03 — with Render Destroyed
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 February 23, 2026 05:55 — with Render Destroyed
@brijeshb42 brijeshb42 marked this pull request as ready for review February 23, 2026 05:59
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 23, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 23, 2026
@brijeshb42 brijeshb42 requested a review from a team February 24, 2026 05:38
@brijeshb42 brijeshb42 marked this pull request as draft February 24, 2026 05:38
@brijeshb42 brijeshb42 removed the request for review from a team February 24, 2026 05:38
* Handles babel integration
* Output file extension based on "type" in package.json
* Adapter based so it it simpler to port to another bundler in future
@oliviertassinari oliviertassinari temporarily deployed to build-package - mui-tools-public PR #1083 February 24, 2026 10:36 — with Render Destroyed
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: out-of-date The pull request has merge conflicts and can't be merged. scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants