fix: replace broken bun:bundle shim with source pre-processing#657
Merged
Conversation
The `onResolve`/`onLoad` plugin shim for `bun:bundle` was silently
ineffective in Bun v1.3.9+ — the `bun:` namespace is resolved by
Bun's native C++ resolver before the JS plugin phase runs. This meant
ALL `feature()` flags evaluated to `false` regardless of the
`featureFlags` map in build.ts (including `MONITOR_TOOL: true`).
Replace the shim with a source pre-processing step that:
1. Strips `import { feature } from 'bun:bundle'` from .ts/.tsx files
2. Replaces `feature('FLAG')` calls with boolean literals
3. Restores original files in a `finally` block after Bun.build()
Also extend the missing-module scanner to detect `require()` and
dynamic `import()` calls — not just static `import ... from` — since
modules behind feature() gates become resolvable when flags are enabled.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes open-build feature flags by replacing the broken bun:bundle plugin shim (no longer interceptable in Bun v1.3.9+) with a build-time source pre-processing step that rewrites feature('FLAG') calls to boolean literals and restores sources afterward.
Changes:
- Add a pre-build pass over
src/to removebun:bundlefeature imports and inlinefeature()calls from thefeatureFlagsmap. - Remove the ineffective
onResolve/onLoadshim forbun:bundle. - Extend the missing-import scanner to also detect
require()and dynamicimport()usage (in addition to staticimport ... from ...).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add SIGINT/SIGTERM handlers to restore pre-processed source files on abrupt termination (Ctrl+C, kill) - Replace process.exit(1) with process.exitCode = 1 so the finally block runs on build failure
This was referenced Apr 13, 2026
kevincodex1
approved these changes
Apr 13, 2026
3 tasks
Contributor
|
bro @Vasanthdev2004 please have look when you have time |
gnanam1990
approved these changes
Apr 13, 2026
C1ph3r404
pushed a commit
to C1ph3r404/openclaude
that referenced
this pull request
Apr 29, 2026
…wb#657) * fix: replace broken bun:bundle shim with source pre-processing The `onResolve`/`onLoad` plugin shim for `bun:bundle` was silently ineffective in Bun v1.3.9+ — the `bun:` namespace is resolved by Bun's native C++ resolver before the JS plugin phase runs. This meant ALL `feature()` flags evaluated to `false` regardless of the `featureFlags` map in build.ts (including `MONITOR_TOOL: true`). Replace the shim with a source pre-processing step that: 1. Strips `import { feature } from 'bun:bundle'` from .ts/.tsx files 2. Replaces `feature('FLAG')` calls with boolean literals 3. Restores original files in a `finally` block after Bun.build() Also extend the missing-module scanner to detect `require()` and dynamic `import()` calls — not just static `import ... from` — since modules behind feature() gates become resolvable when flags are enabled. * fix: ensure source files are always restored after build - Add SIGINT/SIGTERM handlers to restore pre-processed source files on abrupt termination (Ctrl+C, kill) - Replace process.exit(1) with process.exitCode = 1 so the finally block runs on build failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
onResolve/onLoadplugin shim forimport { feature } from 'bun:bundle'was silently ineffective in Bun v1.3.9+. Thebun:namespace is resolved by Bun's native C++ resolver before the JS plugin phase runs, so theonResolvecallback was never called. This meant ALLfeature()flags evaluated tofalseregardless of thefeatureFlagsmap — includingMONITOR_TOOL: truewhich was already enabled.Root cause
Bun handles
bun:bundleas a compile-time macro via its internal resolver, not as a regular module. Plugins cannot interceptbun:namespace resolution.Fix — source pre-processing
Replace the broken shim with a build-time source transformation:
Bun.build(): walksrc/, stripimport { feature } from 'bun:bundle', replacefeature('FLAG')calls with boolean literals from thefeatureFlagsmapBun.build(): restore original source files in afinallyblock (safe even if the build throws)require()and dynamicimport()calls (not just staticimport ... from) since modules behind feature() gates become resolvable when flags are enabledImpact
MONITOR_TOOL: true,BUDDY: true) now actually take effect.feature()working correctly.feature()calls remain in the compiled bundle (all constant-folded).Before/After
feature('MONITOR_TOOL')withMONITOR_TOOL: truefalseat runtimetrue(constant-folded)feature()calls in bundlefinallyTest plan
bun run build— compiles successfully (206 files pre-processed, all restored)bun run smoke— smoke tests passfeature()calls in compiled bundlebun:bundleimports present)COORDINATOR_MODE: true), verify the feature code is included in the bundle