Repository navigation
Conversation
|
Warning Review limit reached
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. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (7)
Comment |
|
Status: reproduced on bun 1.4.0 with the repro in the description ( Rebased onto main; the one conflict was a SAFETY comment in |
|
Found 1 issue this PR may fix:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
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.
|
Updated 12:14 PM PT - Sep 6th, 2026
❌ @robobun, your commit 4a21fd8 has 3 failures in
Add 🧪 To try this PR locally: bunx bun-pr 38719That installs a local version of the PR into your bun-38719 --bun |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Confirmed #28605 is this bug: its layout (package tsconfig with On the review's open question: the behavior change itself (nearest tsconfig instead of the cwd's) and keeping an explicit |
|
Answered the merge-base finding in its thread: |
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.
3c3559f to
f7f3d52
Compare
There was a problem hiding this comment.
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.
…ecked against bun build
|
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. |
Fixes #28605
Problem
bun runtranspiles every file with thecompilerOptionsof the tsconfig.json sitting in the cwd. The sameproj/sub/a.tsgets legacy(target, key, descriptor)decorators when run fromproj/and TC39(value, context)decorators when run fromproj/sub/or from aboveproj/(repro below).emitDecoratorMetadata,useDefineForClassFieldsand thejsx*settings flip the same way.bun build, tsc and editors apply the tsconfig.json nearest to each file, so in a monorepobun runboth disagrees withbun buildof 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 thejsxImportSourceform of this (workspace root without a tsconfig, so every package's.tsxfalls back toreact/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.configure_linker_with_auto_jsx(src/bundler/transpiler.rs:700) copies the cwd tsconfig intotranspiler.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) andsrc/jsc/RuntimeTranspilerStore.rs:852(imports transpiled on the thread pool). The bundler instead uses the per-fileResolveResultflags thatResolver::finalize_result(src/resolver/resolver.rs:1644) fills fromDirInfo.enclosing_tsconfig_json.Fix
Transpiler::tsconfig_for_filereturns the file'senclosing_tsconfig_jsonfrom the resolver'sDirInfocache (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_optionsderives the four tsconfig-controlledParseOptionsfields from that tsconfig exactly asfinalize_resultandBun.Transpiler({ tsconfig })already do: decorator flags straight from it,useDefineForClassFieldsdefaulting to true,jsxmerged over the process-wide pragma (options.jsx, the same basebun buildseedsresolver.opts.jsxfrom, 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.NODE_ENV(options.production/force_node_env) still wins over a tsconfig'sreact-jsx/react-jsxdev, which is the precedencePragma::developmentdocuments and the bundler applies per parse task (bundle_v2.rs:2663). Without it,NODE_ENV=productionplus a nestedreact-jsxdevtsconfig emitsjsxDEV, which react's productionjsx-dev-runtimeexports asundefined(caught by the existingjsx-production.test.ts).hash_for_runtime_transpiler), so byte-identical files under different tsconfigs transpile differently; verified with the on-disk cache enabled.DirInfo.enclosing_tsconfig_jsonbecomespub, like its siblingenclosing_package_json, which the module loader already reads.--tsconfig-overrideapply 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.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 byimport()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: nesteduseDefineForClassFields: falseapplied from the parent cwd.test/bundler/transpiler/jsx-tsconfig-react-jsx.test.ts: nestedjsxFactory(run and build agree), nestedreact-jsxdevunder areact-jsxcwd, the same withNODE_ENV=productionstill 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 withjsxImportSource, 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 inbun runandbun build, whatever the shared base is. Also a cross-package matrix: two packages with their ownpathsalias andjsxImportSource, one importing the other, run from four cwds (repo root, each package, and asrc/dir that has no tsconfig of its own but whose parent does) and compared withbun build. On 1.4.xpathsis already per file whilejsxImportSourcefollows the cwd, so every cwd prints a different pair; with this change all four matchbun build(am/jsxA,bm/jsxB).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 fmtandcargo clippyon the four touched crates are clean.test/tsconfig.json(which extendstsconfig.base.json: same decorator flags as the root tsconfig, plusjsx: react-jsx) instead of the roottsconfig.json. The only in-tree fixtures whose transform this changes are thejsx-productionones, which pass.Background
DirInfois the resolver's cached record for one directory.tsconfig_jsonis the tsconfig found in that directory itself;enclosing_tsconfig_jsonis the nearest one at or above it, copied down when a child directory is first read (dir_info_uncached). Per-filepathsresolution at runtime and the bundler both already use the enclosing one; only the runtime's transpile settings used the cwd's own.transpile_source_code_inner(jsc_hooks.rs) runs synchronously on the JS thread for the entry point,require()and imports made before startup finishes.RuntimeTranspilerStoretranspiles later imports on the work pool:transpile()creates a job on the JS thread, andrun()on a worker parses using a bytewise copy of the VM'sTranspiler, whose resolver caches are not safe to use from there, hence the lookup happens at job creation.TSConfigJSONobjects are interned for the life of the process (only the intermediate configs of anextendschain are freed), which is whyDirInfoholds them as&'staticand the job can carry one across threads.force_node_env/set_productionrecord an explicitNODE_ENV=development/production;configure_definesfolds that intooptions.jsx.developmentat startup. When neither was given, tsconfig'sreact-jsx(productionjsx) vsreact-jsxdev(jsxDEV) decides.Repro
With this change all three
bun runinvocations printlegacy. TheInternal error: directory mismatchline--tsconfig-overrideprints on stderr is #34980, andexperimentalDecoratorsset in a tsconfig thatextendsanother 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)
passes on PR (with fix)
diff hotspot
gate history · 3 passed · 0 rejected · iteration 2
evidence per changed file