Skip to content

Transpile each file with the tsconfig.json nearest to it at runtime - #38719

Closed
robobun wants to merge 7 commits into
mainfrom
farm/5d1fa5f3/per-file-tsconfig-runtime
Closed

robobun wants to merge 7 commits into
mainfrom
farm/5d1fa5f3/per-file-tsconfig-runtime

Conversation

@robobun

@robobun robobun commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #28605

Problem

  • bun run transpiles every file with the compilerOptions of the tsconfig.json sitting in the cwd. The same proj/sub/a.ts gets legacy (target, key, descriptor) decorators when run from proj/ and TC39 (value, context) decorators when run from proj/sub/ or from above proj/ (repro below). emitDecoratorMetadata, useDefineForClassFields and the jsx* settings flip the same way.
  • bun build, tsc and editors apply the tsconfig.json nearest to each file, so in a monorepo bun run both disagrees with bun build of the same file and gives every package the config of whichever package you happen to be in. jsxImportSource from nested tsconfig ignored when running from workspace root #28605 is the jsxImportSource form of this (workspace root without a tsconfig, so every package's .tsx falls back to react/jsx-dev-runtime); Resolve per-file JSX settings from nearest enclosing tsconfig.json at runtime #28606 fixed it the same way against the Zig sources and was closed when those were removed.
  • Cause: configure_linker_with_auto_jsx (src/bundler/transpiler.rs:700) copies the cwd tsconfig into transpiler.options, and both runtime parse sites read those process-wide values for every module: src/runtime/jsc_hooks.rs:2719 (entry point, require(), static imports) and src/jsc/RuntimeTranspilerStore.rs:852 (imports transpiled on the thread pool). The bundler instead uses the per-file ResolveResult flags that Resolver::finalize_result (src/resolver/resolver.rs:1644) fills from DirInfo.enclosing_tsconfig_json.

Fix

  • Transpiler::tsconfig_for_file returns the file's enclosing_tsconfig_json from the resolver's DirInfo cache (the directory was already walked to resolve the file, so this is a cache hit; it runs on the JS thread, and the thread-pool job carries the interned pointer because the worker's bytewise transpiler copy must not touch the resolver).
  • Transpiler::tsconfig_parse_options derives the four tsconfig-controlled ParseOptions fields from that tsconfig exactly as finalize_result and Bun.Transpiler({ tsconfig }) already do: decorator flags straight from it, useDefineForClassFields defaulting to true, jsx merged over the process-wide pragma (options.jsx, the same base bun build seeds resolver.opts.jsx from, so a field a nested tsconfig leaves unset comes out the same in both; that base currently includes the cwd tsconfig in both tools, which is a separate, pre-existing question, see the review thread). A file with no enclosing tsconfig (and virtual modules) keeps getting the cwd-derived values, so nothing changes for them.
  • Dev vs production JSX runtime: after the merge, an explicit NODE_ENV (options.production / force_node_env) still wins over a tsconfig's react-jsx / react-jsxdev, which is the precedence Pragma::development documents and the bundler applies per parse task (bundle_v2.rs:2663). Without it, NODE_ENV=production plus a nested react-jsxdev tsconfig emits jsxDEV, which react's production jsx-dev-runtime exports as undefined (caught by the existing jsx-production.test.ts).
  • The runtime transpiler cache already hashes all four settings (hash_for_runtime_transpiler), so byte-identical files under different tsconfigs transpile differently; verified with the on-disk cache enabled.
  • DirInfo.enclosing_tsconfig_json becomes pub, like its sibling enclosing_package_json, which the module loader already reads.
  • Also makes --tsconfig-override apply to on-disk files, since the resolver attaches the override as every directory's enclosing tsconfig; runtime: apply --tsconfig-override compilerOptions to transpilation #38584 fixes the same flag through the cwd path and is complementary.
  • Tests (each fails on bun 1.4.0, passes with this change, except the two guards noted):
    • test/bundler/transpiler/es-decorators.test.ts "per-file tsconfig": three identical modules under different tsconfigs (own legacy, own empty, inherited root with metadata), loaded both by static import and by import() after startup (the thread-pool path), run from four cwds, must all print the same result.
    • test/bundler/transpiler/ts-use-define-for-class-fields.test.ts: nested useDefineForClassFields: false applied from the parent cwd.
    • test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts: nested jsxFactory (run and build agree), nested react-jsxdev under a react-jsx cwd, the same with NODE_ENV=production still selecting the production runtime (guard: also passes on 1.4.0), the jsxImportSource from nested tsconfig ignored when running from workspace root #28605 layout (package tsconfig with jsxImportSource, run from a workspace root that has no tsconfig; 1.4.0 fails it with the issue's exact error), and a guard that a jsx field the nearest tsconfig leaves unset resolves to the same import source in bun run and bun build, whatever the shared base is. Also a cross-package matrix: two packages with their own paths alias and jsxImportSource, one importing the other, run from four cwds (repo root, each package, and a src/ dir that has no tsconfig of its own but whose parent does) and compared with bun build. On 1.4.x paths is already per file while jsxImportSource follows the cwd, so every cwd prints a different pair; with this change all four match bun build (am/jsxA, bm/jsxB).
  • Also ran with this change: decorators, decorator-metadata, es-decorators-esbuild, jsx-production, test/cli/run/tsconfig-override.test.ts, test/cli/test/bun-test.test.ts -t tsconfig, test/regression/issue/27526, 27575, test/js/bun/resolve/* (resolve, resolve-ts, require, esModule, import-meta, custom conditions, tsconfig-extends-leak), test/js/bun/plugin/*, run-eval, preload-test, run-cjs, run-extensionless, env, type-export: all pass. cargo fmt and cargo clippy on the four touched crates are clean.
  • Note for the repo's own suite: test files now get test/tsconfig.json (which extends tsconfig.base.json: same decorator flags as the root tsconfig, plus jsx: react-jsx) instead of the root tsconfig.json. The only in-tree fixtures whose transform this changes are the jsx-production ones, which pass.

Background

  • DirInfo is the resolver's cached record for one directory. tsconfig_json is the tsconfig found in that directory itself; enclosing_tsconfig_json is the nearest one at or above it, copied down when a child directory is first read (dir_info_uncached). Per-file paths resolution at runtime and the bundler both already use the enclosing one; only the runtime's transpile settings used the cwd's own.
  • The runtime has two parse sites. transpile_source_code_inner (jsc_hooks.rs) runs synchronously on the JS thread for the entry point, require() and imports made before startup finishes. RuntimeTranspilerStore transpiles later imports on the work pool: transpile() creates a job on the JS thread, and run() on a worker parses using a bytewise copy of the VM's Transpiler, whose resolver caches are not safe to use from there, hence the lookup happens at job creation.
  • TSConfigJSON objects are interned for the life of the process (only the intermediate configs of an extends chain are freed), which is why DirInfo holds them as &'static and the job can carry one across threads.
  • force_node_env / set_production record an explicit NODE_ENV=development / production; configure_defines folds that into options.jsx.development at startup. When neither was given, tsconfig's react-jsx (production jsx) vs react-jsxdev (jsxDEV) decides.
Repro
mkdir -p proj/sub && cd proj
echo '{ "compilerOptions": { "experimentalDecorators": true } }' > tsconfig.json
cat > sub/a.ts <<'EOF'
function d(...a: any[]) { (globalThis as any).ar = a.length }
class C { @d m() {} }
console.log((globalThis as any).ar === 3 ? "legacy" : "standard");
EOF

bun run sub/a.ts          # legacy
(cd sub && bun run a.ts)  # standard   (before: cwd has no tsconfig of its own)
(cd .. && bun run proj/sub/a.ts)   # standard   (before)
bun build sub/a.ts | grep __legacyDecorateClassTS   # the bundler applies proj/tsconfig.json from any cwd

With this change all three bun run invocations print legacy. The Internal error: directory mismatch line --tsconfig-override prints on stderr is #34980, and experimentalDecorators set in a tsconfig that extends another is lost in the extends merge independently of this (fixed in #34496).


[review] gate passed · iteration 2 · 7 files touched

fails on main (without fix)
ASAN without fix: 12 FAILED
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/bundler/transpiler/es-decorators.test.ts test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts test/bundler/transpiler/ts-use-define-for-class-fields.test.ts
bun test v1.4.1 (4448a2e21)

test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:
(pass) tsconfig compilerOptions.jsx > "react-jsx" selects the matching automatic runtime [668.00ms]
(pass) tsconfig compilerOptions.jsx > "react-jsxdev" selects the matching automatic runtime [592.06ms]
88 |         cwd: String(dir),
89 |         stdout: "pipe",
90 |         stderr: "inherit",
91 |       });
92 |       const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]);
93 |       expect({ stdout: stdout.trim(), exitCode }).toEqual({ stdout: "app:div", exitCode: 0 });
                                                       ^
error: expect(received).toEqual(expected)

  {
    "exitCode": 0,
-   "stdout": "app:div",
+   "stdout": "root:div",
  }

- Expected  - 1
+ Received  + 1

      at <anonymous> (/workspace/bun/test/bundler/transpiler/jsx-tsconfig-react-jsx.test
... (truncated)

release without fix: 12 FAILED
bun test v1.4.0-canary.1 (4448a2e21)

test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:
(pass) tsconfig compilerOptions.jsx > "react-jsx" selects the matching automatic runtime [16.33ms]
(pass) tsconfig compilerOptions.jsx > "react-jsxdev" selects the matching automatic runtime [13.25ms]
88 |         cwd: String(dir),
89 |         stdout: "pipe",
90 |         stderr: "inherit",
91 |       });
92 |       const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]);
93 |       expect({ stdout: stdout.trim(), exitCode }).toEqual({ stdout: "app:div", exitCode: 0 });
                                                       ^
error: expect(received).toEqual(expected)

  {
    "exitCode": 0,
-   "stdout": "app:div",
+   "stdout": "root:div",
  }

- Expected  - 1
+ Received  + 1

      at <anonymous> (/workspace/bun/test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:93:51)
(fail) tsconfig compilerOptions.jsx > the tsconfig nearest to the file applies, not the cwd's [7.13ms]
127 |       cwd: String(dir),
128 |       stdout: "pipe",
129 |       stderr: "inherit",
130 |     });
131 |     const [stdout, exitCode] = await Promise.all([proc.stdout.text(
... (truncated)
passes on PR (with fix)
ASAN with fix: all passed
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/bundler/transpiler/es-decorators.test.ts test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts test/bundler/transpiler/ts-use-define-for-class-fields.test.ts
bun test v1.4.1 (4448a2e21)

test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts:
(pass) tsconfig compilerOptions.jsx > "react-jsx" selects the matching automatic runtime [647.04ms]
(pass) tsconfig compilerOptions.jsx > "react-jsxdev" selects the matching automatic runtime [636.45ms]
(pass) tsconfig compilerOptions.jsx > the tsconfig nearest to the file applies, not the cwd's [609.75ms]
(pass) tsconfig compilerOptions.jsx > nested "react-jsxdev" under a "react-jsx" cwd with env {} [291.85ms]
(pass) tsconfig compilerOptions.jsx > nested "react-jsxdev" under a "react-jsx" cwd with env {"NODE_ENV":"production"} [283.56ms]
(pass) tsconfig compilerOptions.jsx > jsxImportSource of a package's tsconfig applies when run from a workspace root without one [299.98ms]
(pass) tsconfig compilerOptions.jsx > a jsx field the nearest tsconfig leaves unset resolves like bun build [307.05ms
... (truncated)

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 740ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/6] gen generated_host_exports.rs
generated_host_exports.rs: 120 exports (host=5, lazy=10, generic=105, rust=0); 243 extern-C blocks audited
[1/6] cargo bun_runtime → libbun_runtime.a (--target x86_64-unknown-linux-gnu)

  nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19)

^[[1m^[[92m   Compiling^[[0m bun_core v0.0.0 (/workspace/bun/src/bun_core)
^[[1m^[[92m   Compiling^[[0m bun_errno v0.0.0 (/workspace/bun/src/errno)
^[[1m^[[92m   Compiling^[[0m bun_ptr v0.0.0 (/workspace/bun/src/ptr)
^[[1m^[[92m   Compiling^[[0m bun_boringssl_sys v0.0.0 (/workspace/bun/src/boringssl_sys)
^[[1m^[[92m   Compiling^[[0m bun_safety v0.0.0 (/workspace/bun/src/safety)
^[[1m^[[92m   Compiling^[[0m bun_base64 v0.0.0 (/workspace/bun/src/base64)
^[[1m^[[92m   Compiling^[[0m bun_cares_sys v0.0.0 (/workspace/bun/src/cares_sys)
^[[1m^[[92m   Compiling^[[0m bun_zlib_sys v0.0.0 (/workspace/bun/src/zlib_sys)
^[[1m^[[92m   Compiling^[[0m bun_zstd v0.0.0 (/workspace/bun/src/zstd)
^[[1m^[[92m   Compiling^[[0m bun_pic
... (truncated)
diff hotspot
src/bundler/transpiler.rs                          |  51 +++++++-
 src/jsc/RuntimeTranspilerStore.rs                  |  15 ++-
 src/resolver/dir_info.rs                           |   3 +-
 src/runtime/jsc_hooks.rs                           |  36 ++++--
 test/bundler/transpiler/es-decorators.test.ts      |  76 +++++++++++
 .../transpiler/jsx-tsconfig-react-jsx.test.ts      | 143 +++++++++++++++++++++
 .../ts-use-define-for-class-fields.test.ts         |  18 +++
 7 files changed, 321 insertions(+), 21 deletions(-)

gate history · 3 passed · 0 rejected · iteration 2

evidence per changed file
file                                                      reads  edits  tests
src/bundler/transpiler.rs                                    11     16      0
src/jsc/RuntimeTranspilerStore.rs                             7      9      0
src/resolver/dir_info.rs                                      3      3      0
src/runtime/jsc_hooks.rs                                     10      9      0
test/bundler/transpiler/es-decorators.test.ts                 1      2      0
test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts        4      5      0
…ndler/transpiler/ts-use-define-for-class-fields.test.ts      1      1      0

@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

On-demand reviews are free for the next 14 days. After that, they cost $0.25 per reviewed file.

Or wait 2 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Essentials

Run ID: ade8e78a-27ec-4a68-b0df-0009957fe416

📥 Commits

Reviewing files that changed from the base of the PR and between aeb1905 and 4a21fd8.

📒 Files selected for processing (7)
  • src/bundler/transpiler.rs
  • src/jsc/RuntimeTranspilerStore.rs
  • src/resolver/dir_info.rs
  • src/runtime/jsc_hooks.rs
  • test/bundler/transpiler/es-decorators.test.ts
  • test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts
  • test/bundler/transpiler/ts-use-define-for-class-fields.test.ts

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

@robobun

robobun commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: reproduced on bun 1.4.0 with the repro in the description (proj/sub/a.ts prints legacy from proj/, standard from proj/sub/ or from above proj/), via an identical module under three different tsconfigs in one process, via the #28605 layout, and via a two-package paths + jsxImportSource matrix run from four cwds (on 1.4.x each cwd prints a different answer; paths was already per file, the jsx/decorator/class-field block was not). With this branch every cwd prints what bun build produces, for both the synchronous loader and the thread-pool transpiler; all new test cases fail on 1.4.x and pass with the change.

Rebased onto main; the one conflict was a SAFETY comment in jsc_hooks.rs. Build 104663 on 8fc947b was fully green (181/181); the current head 4a21fd8 only adds the matrix test. Ready for review.

@github-actions

Copy link
Copy Markdown
Contributor

Found 1 issue this PR may fix:

  1. jsxImportSource from nested tsconfig ignored when running from workspace root #28605 - bun run from a workspace root ignores a nested package's jsxImportSource/jsx and falls back to react; the new per-file tsconfig_for_file + merge_jsx lookup makes each .tsx use the tsconfig nearest to it.

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #28605

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed this PR and didn't find any bugs. Because it changes which tsconfig.json governs every runtime-transpiled TS/JSX file — a user-visible semantics shift that also re-points the repo's own test suite at test/tsconfig.json — a maintainer should confirm the direction and the NODE_ENV-over-tsconfig precedence choice.

Checked: tsconfig_for_file is only invoked on the JS thread (both transpile_source_code_inner and transpile_file before the job is scheduled); the worker's tsconfig_parse_options reads only the interned &'static TSConfigJSON and the bytewise-copied options, never the resolver. read_dir_info swallows errors to None so a cache miss can't fail the transpile. merge_jsx layering matches the bundler's finalize_result path, and the force_node_env/production override afterward matches bundle_v2.rs.

Extended reasoning...

Overview

Adds Transpiler::tsconfig_for_file (resolver DirInfo cache lookup for the nearest enclosing tsconfig) and Transpiler::tsconfig_parse_options (derives jsx, experimental_decorators, emit_decorator_metadata, use_define_for_class_fields from that tsconfig, falling back to the cwd-derived options when there is none). Wires both runtime parse sites — transpile_source_code_inner (sync JS-thread path) and RuntimeTranspilerStore (thread-pool path, tsconfig captured at job creation) — through it. Makes DirInfo.enclosing_tsconfig_json pub. Adds tests exercising static import, dynamic import, four cwds, jsxFactory, react-jsxdev under NODE_ENV=production, and useDefineForClassFields.

Security risks

None. No parsing of untrusted input is added; the tsconfig objects were already loaded and interned by the resolver. The visibility widening on enclosing_tsconfig_json matches the sibling enclosing_package_json field.

Level of scrutiny

High. This is a deliberate, ecosystem-facing behavior change to bun run: files that previously transpiled under the cwd's tsconfig now transpile under their nearest enclosing one. That aligns with bun build, tsc, and editors — almost certainly the right call — but it can flip decorator mode, class-field semantics, or JSX runtime for existing projects, and the PR itself notes it changes which tsconfig the repo's own test files see. A maintainer should sign off on shipping the semantics change and on the precedence rule that an explicit NODE_ENV overrides a nested tsconfig's react-jsx/react-jsxdev.

Other factors

Implementation looks correct: the resolver lookup stays on the JS thread (avoiding the documented worker-thread hazard on the bytewise transpiler copy), &'static TSConfigJSON is process-interned so carrying it into the job is sound, and tsconfig_parse_options is a pure read of &self.options plus the tsconfig so it's safe on the worker. The runtime transpiler cache already keys on all four settings (per the description), so no cache-poisoning concern. Test coverage is thorough across both code paths and multiple cwds. No prior human review on the thread.

Comment thread src/bundler/transpiler.rs Resolved
@robobun

robobun commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 12:14 PM PT - Sep 6th, 2026

❌ @robobun, your commit 4a21fd8 has 3 failures in Build #111468 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 38719

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

bun-38719 --bun

Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/jsc/RuntimeTranspilerStore.rs Resolved
Comment thread src/resolver/dir_info.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/bundler/transpiler.rs Resolved
Comment thread src/jsc/RuntimeTranspilerStore.rs Resolved
Comment thread src/resolver/dir_info.rs Resolved
@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Confirmed #28605 is this bug: its layout (package tsconfig with jsxImportSource, launched from a workspace root with no tsconfig) fails on 1.4.0 with the issue's exact Cannot find module 'react/jsx-dev-runtime' and passes on this branch. Added it as a case in jsx-tsconfig-react-jsx.test.ts (6d22835) and Fixes #28605 to the description; #28606 was the same fix against the Zig sources. The later pushes only shorten comments.

On the review's open question: the behavior change itself (nearest tsconfig instead of the cwd's) and keeping an explicit NODE_ENV ahead of a nested tsconfig's react-jsx/react-jsxdev are the two calls for a maintainer; the second one is what bundle_v2 already does per parse task, and dropping it crashes NODE_ENV=production runs on react's production jsx-dev-runtime.

Comment thread src/bundler/transpiler.rs Resolved
@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Answered the merge-base finding in its thread: finalize_result starts from resolver.opts.jsx (resolver.rs:1200), which is the same cwd-inclusive base, and bun build 1.4.0 emits the root's import source for that layout just like this branch's bun run does, so the two agree there as well. eb12344 adds a test pinning that agreement without fixing which base wins. Whether the base should stop including the cwd tsconfig (as Bun.build already behaves) is a separate change that needs to land for bun build and the runtime together; filing it on its own.

The module loader took experimentalDecorators, emitDecoratorMetadata,
useDefineForClassFields and the jsx settings from the tsconfig.json in
the cwd for every file it transpiled, so the same file changed meaning
depending on the directory bun was launched from, and disagreed with
bun build, which applies the tsconfig nearest to each file.

Look up the file's enclosing tsconfig (the DirInfo the resolver already
cached for it) at both runtime parse sites and derive those ParseOptions
from it, keeping the cwd-derived values for files that have none. The
dev/production JSX runtime still follows an explicit NODE_ENV, as the
bundler does, since react's production jsx-dev-runtime exports no jsxDEV.
@robobun
robobun force-pushed the farm/5d1fa5f3/per-file-tsconfig-runtime branch from 3c3559f to f7f3d52 Compare August 24, 2026 05:01
Comment thread src/bundler/transpiler.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed this PR and didn't find any bugs (the earlier merge-base concern was refuted with evidence and pinned by a test; the read_dir_info_ignore_error nit was applied). Because it changes runtime tsconfig resolution for every TS/TSX file — including the repo's own test suite — and the author flagged the nearest-tsconfig semantics and the NODE_ENV-over-tsconfig precedence as maintainer calls, a human sign-off is still worthwhile.

Checked: the resolver lookup runs on the JS thread only (the interned &'static TSConfigJSON is carried into the thread-pool job, whose bytewise transpiler copy never touches the resolver); tsconfig_parse_options on the worker reads only &self.options scalars and clones the pragma; the None branch preserves today's cwd-derived values for virtual/non-absolute paths; use_define_for_class_fields.unwrap_or(true) matches the existing default.

Extended reasoning...

Overview

Makes bun run transpile each file with the tsconfig.json nearest to it (via the resolver's cached DirInfo.enclosing_tsconfig_json) instead of the process-wide cwd tsconfig, aligning with bun build/tsc. Adds Transpiler::tsconfig_for_file (JS-thread resolver lookup) and tsconfig_parse_options (derives the four tsconfig-controlled ParseOptions fields), threads an Option<&'static TSConfigJSON> into TranspilerJob, and wires both runtime parse sites (transpile_source_code_inner and RuntimeTranspilerStore::run via Bun__transpileFile). enclosing_tsconfig_json becomes pub. ~100 LOC of Rust across 4 files, ~240 LOC of tests covering decorators, useDefineForClassFields, and the JSX matrix (nearest-factory, dev/prod under NODE_ENV, the #28605 workspace layout, and a run/build agreement guard).

Security risks

None identified. No parsing of untrusted input beyond what the resolver already does; TSConfigJSON is process-lifetime interned so the &'static carried across threads is sound; no new FFI surface.

Level of scrutiny

High. This is a user-visible semantic change to how every TS/TSX file is transpiled at runtime. It also changes which tsconfig applies to Bun's own test files (they now get test/tsconfig.json), which the author says only affects jsx-production fixtures. The two design decisions the author explicitly deferred to a maintainer — adopting nearest-tsconfig semantics at all, and keeping explicit NODE_ENV ahead of a nested tsconfig's react-jsx/react-jsxdev — are exactly the kind of behavioral policy call REVIEW.md says needs maintainer agreement.

Other factors

Prior review activity: my earlier 🔴 about the JSX merge base was refuted (finalize_result starts from resolver.opts.jsx, which is the same cwd-inclusive base; verified against 1.4.0 and pinned by the new run/build-agreement test), and the 🟡 read_dir_info_ignore_error nit was applied in 8fc947b. All comment-cop threads are resolved. Tests are thorough (both parse paths, four cwds, static+dynamic import, the exact #28605 layout) and hermetic. The remaining open item is not a code defect — it's whether the behavior change itself is the one Bun wants.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-09-06.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
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.

jsxImportSource from nested tsconfig ignored when running from workspace root

2 participants