Skip to content

fix(bundler): enable tsconfig option in Bun.build() API#26795

Open
robobun wants to merge 1 commit intomainfrom
claude/fix-bun-build-tsconfig-option
Open

fix(bundler): enable tsconfig option in Bun.build() API#26795
robobun wants to merge 1 commit intomainfrom
claude/fix-bun-build-tsconfig-option

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Feb 7, 2026

Summary

  • Fixes the tsconfig option in Bun.build() API which was not working
  • Path aliases defined in custom tsconfig files are now properly resolved
  • Added regression test for the fix

Details

The tsconfig option in Bun.build() was defined in TypeScript types but never actually implemented. This PR:

  1. Parses the tsconfig property from the JavaScript config object in JSBundler.zig
  2. Passes tsconfig_override to TransformOptions during Transpiler.init
  3. Explicitly loads and attaches the tsconfig to the directory cache

The root cause was that the bundler's resolver shares a global directory cache with the main process. When a build script loads, the main process populates the cache without the tsconfig_override, and subsequent bundler operations use cached entries lacking tsconfig information.

Test plan

  • Added regression test test/regression/issue/26793.test.ts
  • Verified the fix works with the reproduction case from the issue
  • Verified the test fails with the system bun (USE_SYSTEM_BUN=1)
  • Verified the test passes with the debug build

Fixes #26793

🤖 Generated with Claude Code

@github-actions github-actions bot added the claude label Feb 7, 2026
@robobun
Copy link
Collaborator Author

robobun commented Feb 7, 2026

Updated 12:38 PM PT - Feb 7th, 2026

❌ Your commit e1dcdb69 has 4 failures in Build #36683 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 26795

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

bun-26795 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Parse an optional tsconfig from the JS bundler config into tsconfig_override, thread it into bundler TransformOptions, load it early during initialization, and propagate its JSON into directory caches and resolver state before linker configuration.

Changes

Cohort / File(s) Summary
JSBundler configuration parsing
src/bun.js/api/JSBundler.zig
Parse an optional tsconfig value from the global JS config and store it as tsconfig_override on the JSBundler Config during fromJS parsing.
Bundler init / transpiler / resolver
src/bundler/bundle_v2.zig
Add tsconfig_override field to TransformOptions; load and resolve the override (if provided) before linker configuration; attach loaded tsconfig JSON to its containing directory and each entry-point directory; sync resolver options with transpiler options and wire resolver env loader to the transpiler environment.
Regression tests
test/regression/issue/26793.test.ts
Add tests validating Bun.build() resolves path aliases when given a custom tsconfig (absolute and relative paths) and that aliases are not resolved when no tsconfig is provided (assert logs and failure).
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enabling the tsconfig option in Bun.build() API that was previously non-functional.
Description check ✅ Passed The description follows the template with 'Summary' (what PR does) and 'Test plan' (verification), providing detailed implementation details and root cause analysis beyond the basic template requirements.
Linked Issues check ✅ Passed All coding objectives from issue #26793 are met: tsconfig parsing in JSBundler.zig [26793], tsconfig_override in TransformOptions [26793], explicit tsconfig loading and cache attachment [26793], and regression test [26793].
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the tsconfig option in Bun.build(): parsing in JSBundler.zig, passing to TransformOptions in bundle_v2.zig, and adding regression test. No unrelated modifications detected.

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


No actionable comments were generated in the recent review. 🎉


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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/bundler/bundle_v2.zig`:
- Around line 2011-2055: tsconfig_override may be relative and is never
normalized, and the current null checks prevent the override from replacing
cached values; resolve transpiler.options.tsconfig_override to an absolute path
(use transpiler.fs.absBuf or similar) before calling parseTSConfig and
std.fs.path.dirname, then unconditionally assign the parsed tsconfig to
tsconfig_dir_info.tsconfig_json and tsconfig_dir_info.enclosing_tsconfig_json
(remove the if == null guards) and likewise always set
dir_info.enclosing_tsconfig_json for each entry point directory (use
transpiler.resolver.readDirInfo, config.entry_points, parseTSConfig,
std.fs.path.dirname, transpiler.fs.absBuf to locate and update the right cached
dir entries).

@robobun robobun force-pushed the claude/fix-bun-build-tsconfig-option branch from 987b26d to 544cf7b Compare February 7, 2026 19:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/bun.js/api/JSBundler.zig`:
- Around line 580-583: The tsconfig path is stored as-is which can be relative;
resolve it to an absolute path before storing by converting the incoming
ZigString.Slice to an absolute path (e.g., using std.fs.getcwd() +
std.fs.path.join or std.fs.path.resolve or an equivalent helper) and then call
this.tsconfig_override.appendSliceExact(...) with the absolute path slice;
update the block that handles config.getOptional(globalThis, "tsconfig",
ZigString.Slice) to perform this normalization and ensure you deinit any
temporary slices used for the resolved path.

In `@test/regression/issue/26793.test.ts`:
- Around line 49-67: The test currently changes the global cwd using
process.chdir(originalCwd/process.chdir(String(dir))) which is unsafe; instead
remove process.chdir and call Bun.build with absolute paths derived from the
test's temp dir (use String(dir) or path.join(String(dir), "src/index.ts") for
entrypoints, path.join(String(dir), "dist") for outdir and
path.join(String(dir), "tsconfig.json") for tsconfig) so that the test no longer
mutates process.cwd (remove originalCwd, process.chdir and the finally block)
and assert against the build result/output as before (references: variables dir,
result, result.outputs and the Bun.build call).

The `tsconfig` option in `Bun.build()` was not working - path aliases
defined in a custom tsconfig were not resolved. This fixes the issue by:

1. Parsing the `tsconfig` property from the JavaScript config object
2. Passing `tsconfig_override` to the TransformOptions during Transpiler init
3. Explicitly loading and attaching the tsconfig to the directory cache

The root cause was that the bundler's resolver shares a global directory
cache with the main process. When a build script loads, the main process
populates the cache without the tsconfig_override, and subsequent bundler
operations would use the cached entries that lack tsconfig information.

The fix ensures the tsconfig is loaded and attached to both the tsconfig
file's directory and any entry point directories that may have been
cached before the tsconfig was loaded.

Fixes #26793

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robobun robobun force-pushed the claude/fix-bun-build-tsconfig-option branch from 544cf7b to e1dcdb6 Compare February 7, 2026 19:50
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.

Bun.build() tsconfig option doesn't resolve path aliases (CLI works)

1 participant