fix(bundler): enable tsconfig option in Bun.build() API#26795
Open
fix(bundler): enable tsconfig option in Bun.build() API#26795
tsconfig option in Bun.build() API#26795Conversation
Collaborator
Author
Contributor
WalkthroughParse an optional Changes
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. No actionable comments were generated in the recent review. 🎉 Comment |
Contributor
There was a problem hiding this comment.
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).
987b26d to
544cf7b
Compare
Contributor
There was a problem hiding this comment.
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>
544cf7b to
e1dcdb6
Compare
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
tsconfigoption inBun.build()API which was not workingDetails
The
tsconfigoption inBun.build()was defined in TypeScript types but never actually implemented. This PR:tsconfigproperty from the JavaScript config object inJSBundler.zigtsconfig_overridetoTransformOptionsduringTranspiler.initThe 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
test/regression/issue/26793.test.tsFixes #26793
🤖 Generated with Claude Code