Skip to content

fix(bundler): skip barrel optimization for entry points with sideEffects#27710

Open
robobun wants to merge 1 commit intomainfrom
claude/fix-27709-sideeffects-entry-point
Open

fix(bundler): skip barrel optimization for entry points with sideEffects#27710
robobun wants to merge 1 commit intomainfrom
claude/fix-27709-sideeffects-entry-point

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Mar 3, 2026

Summary

  • Fix barrel imports optimization incorrectly tree-shaking entry point re-exports when the project's package.json has a sideEffects field
  • Entry points have no requested_exports (nothing imports them within the bundle), so the barrel optimization would mark all their imports as unused, producing empty output with dangling references like export{m as B,e as A};
  • Add an early return in applyBarrelOptimizationImpl to skip barrel optimization for entry points

Closes #27709

Test plan

  • Added regression tests in test/regression/issue/27709.test.ts covering both sideEffects: ["./dist/index.js"] and sideEffects: false
  • Tests fail with system bun (v1.3.10) confirming the bug
  • Tests pass with debug build confirming the fix
  • All 46 existing barrel tests pass (test/bundler/bundler_barrel.test.ts)

🤖 Generated with Claude Code

The barrel imports optimization incorrectly applied to entry point files
when the project's package.json had a `sideEffects` field. Since entry
points have no `requested_exports` (nothing imports them within the
bundle), the optimization marked all their imports as unused, producing
empty output with dangling export references.

Skip barrel optimization for entry points so all their exports are
preserved as the public API of the bundle.

Closes #27709

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added the claude label Mar 3, 2026
@robobun
Copy link
Collaborator Author

robobun commented Mar 3, 2026

Updated 1:17 AM PT - Mar 3rd, 2026

❌ Your commit 1213676b has 2 failures in Build #38573 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 27710

That installs a local version of the PR into your bun-27710 executable, so you can run:

bun-27710 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6c7e972 and 1213676.

📒 Files selected for processing (2)
  • src/bundler/barrel_imports.zig
  • test/regression/issue/27709.test.ts

Walkthrough

Adds a guard in barrel import optimization to skip entry point files, preventing unwanted barrel optimization that affects public API exports. Introduces regression tests validating sideEffects field handling with re-exports during bundling.

Changes

Cohort / File(s) Summary
Barrel Import Optimization Guard
src/bundler/barrel_imports.zig
Adds early return in applyBarrelOptimizationImpl to skip barrel optimization for entry point files, ensuring entry points preserve all exports.
Regression Tests for sideEffects Handling
test/regression/issue/27709.test.ts
Adds test suite verifying correct re-export preservation when sideEffects is configured in package.json, covering both array and false configurations.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: skipping barrel optimization for entry points when sideEffects is present.
Description check ✅ Passed The description covers the problem, root cause, solution, and test verification, though it uses a generated footer that could be considered non-essential.
Linked Issues check ✅ Passed The code changes directly address issue #27709 by preventing barrel optimization on entry points, which resolves the tree-shaking problem with sideEffects.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the barrel optimization issue for entry points with sideEffects; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

LGTM — small, focused fix with good regression tests.

Extended reasoning...

Overview

This PR adds a 7-line early return in applyBarrelOptimizationImpl (src/bundler/barrel_imports.zig) that skips barrel optimization for entry points. Entry points have no requested_exports since nothing imports them within the bundle, so barrel optimization would incorrectly mark all their imports as unused when sideEffects is configured. The test file (test/regression/issue/27709.test.ts) adds two regression tests covering both sideEffects: ["./dist/index.js"] and sideEffects: false.

Security risks

None — this is a bundler optimization fix with no security implications.

Level of scrutiny

Moderate. The production code change is minimal and follows established patterns (linear scan over entry_points.items is used throughout bundle_v2.zig). The logic is straightforward: entry points should never be barrel-optimized because they define the public API of the bundle.

Other factors

  • The entry point check is correctly positioned after the initial guards (optimize_imports, side_effects check, empty records check) but before the barrel verification loop.
  • The test is placed in the correct location per CLAUDE.md conventions (test/regression/issue/27709.test.ts).
  • Tests use tempDir with using for proper cleanup, and test via Bun.build API which is appropriate for bundler regression tests.
  • No CODEOWNERS concerns — this is standard bundler code.
  • The PR description notes all 46 existing barrel tests continue to pass.

// of the bundle. Since nothing imports from them within the bundle,
// requested_exports will be empty, causing barrel optimization to
// incorrectly mark all their imports as unused.
for (this.graph.entry_points.items) |ep| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use std.mem.containsScalar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sideEffects field breaks bundler tree-shaking in Bun 1.3.10

2 participants