Skip to content

fix(bundler): rewrite namespace re-exports for Bun bundler compatibility#18524

Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:fix/bundler-namespace-reexports
Open

fix(bundler): rewrite namespace re-exports for Bun bundler compatibility#18524
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:fix/bundler-namespace-reexports

Conversation

@sjawhar
Copy link

@sjawhar sjawhar commented Mar 21, 2026

Issue for this PR

Closes #18525

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Rewrites 9 facade/index files that re-export values from service modules inside TypeScript namespaces. Bun's bundler transpiles namespace re-exports like export const FileDiff = S.FileDiff into self-referential assignments (Snapshot.FileDiff = Snapshot.FileDiff) which evaluate to undefined when circular imports delay module initialization.

The fix splits each file into:

  • A plain export const X = { ... } object literal with value exports (eagerly initialized with correct references)
  • A separate export namespace X { ... } block with type-only exports (erased at runtime)

This preserves the identical public API surface while ensuring Bun's bundler emits correct initialization code regardless of module evaluation order.

Files changed: src/snapshot/index.ts, src/question/index.ts, src/provider/auth.ts, src/file/index.ts, src/file/time.ts, src/skill/skill.ts, src/tool/truncate.ts, src/permission/index.ts, src/format/index.ts

How did you verify your code works?

  1. bun typecheck — passes clean (tsgo --noEmit)
  2. bun run build --single — builds successfully
  3. Bundled binary opencode serve — starts and listens without TypeError (previously crashed with Snapshot2.FileDiff.array and ProviderAuth2.Authorization.optional errors)
  4. Bundled binary opencode run "echo test" — creates session, runs LLM prompt loop, executes tools successfully

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Bun's bundler emits self-referential assignments (X.Y = X.Y) for namespace
re-exports that resolve to undefined when the source module hasn't finished
initializing. Replace fragile namespace re-export pattern with concrete
object exports + separate type-only namespaces in 9 index/facade files.
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 21, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 21, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Bundled binary crashes with TypeError on namespace re-exports

1 participant