Repository navigation
fix(bun-plugins): make the Vue and Hono plugins work as bun:test preloads - #1186
Merged
Merged
Conversation
…t files Every Bun plugin instance registers hooks for the shared `?tsrx-css&lang.css` query. The first instance claimed every virtual stylesheet and served an empty one for files another instance compiled, so builds that split `.tsrx` files across instances with `include`/`exclude` silently lost the later instance's styles. An instance now resolves and loads only the stylesheets it compiled and returns `undefined` for the rest, so Bun passes them on to the instance that owns them. The React, Preact, Solid, and Vue plugins share this code. The virtual CSS stays in the `file` namespace: a custom namespace would make `Bun.plugin()` preloads reject the `css` loader. Fixes tsrx-org#940 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The React, Preact, and Hono Bun plugins pre-transformed compiled `.tsrx` output with a separate `Bun.Transpiler`, which has no production mode and always emits `jsxDEV` calls from `<source>/jsx-dev-runtime`. React's production dev runtime leaves `jsxDEV` undefined, so a production React build succeeded and then threw when a component rendered. The same happened under `NODE_ENV=production` with a `Bun.plugin()` preload. The plugins now return the compiled TSX to Bun with a `@jsxImportSource` pragma, so Bun's own TSX transform picks the development or production runtime for the build, as it does for `.tsx` files. The pragma keeps the configured import source and the automatic runtime whatever the project tsconfig sets. The Hono plugin no longer requires `Bun.Transpiler`. The Solid and Vue plugins do not emit JSX runtime calls and are unchanged. Fixes tsrx-org#859 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…thout root When `Bun.build()` omitted `root`, the Bun plugins searched for the nearest tsconfig from the working directory. Bun builds from the common ancestor directory of the entrypoints instead, so a nested project whose tsconfig selects `ios` built with the parent tsconfig's `web` platform, while Bun resolved path aliases from the nested tsconfig. Without `root`, the plugins now search from the entrypoints' common ancestor directory. An explicit `root` is still used as is, and a relative `tsconfig` option still resolves from the working directory. All five Bun plugins share this code. Fixes tsrx-org#567 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ation The Bun plugins hand `import.meta.env.platform.*` values to Bun through `build.config.define`, which only `Bun.build()` provides. Under `Bun.plugin()`, including the documented `bun:test` preload, a configured platform still pruned exact `if` guards at compile time, but a flag read as a value stayed in the output and threw `undefined is not an object` at runtime. Without a build config, the plugins now replace the flags left in compiled `.tsrx` output with their values, as the Turbopack integration does. All five Bun plugins share this code. Fixes tsrx-org#865 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The entrypoint-derived tsconfig base from the previous commit took the directory of a virtual `BuildConfig.files` entry, such as `/virtual`, which holds no tsconfig. Bun builds from the working directory when every entrypoint is an in-memory file, so the plugins now search from there in that case, and the working directory's `tsrx.platform` applies again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `@jsxImportSource` pragma from the production-runtime fix regressed two cases against main in the React, Preact, and Hono Bun plugins: - Under a classic `"jsx": "react"` tsconfig, Bun ignores a lone `@jsxImportSource` and emits `React.createElement`, `h(...)`, or `jsx(...)` with no import, so components threw when they rendered, in builds and in `bun:test` preloads. - The pragma went above a leading `#!` line, which made the module a syntax error. The plugins now read the `jsx` option of the tsconfig Bun applies: the one nearest each file for `Bun.build()`, and the working directory's for `Bun.plugin()`, whose runtime transpiler ignores nested tsconfigs. Under a classic setting they add `@jsxRuntime automatic`, which gives main's output, the automatic development runtime. Other settings keep the build-selected runtime. The pragma now goes after a leading shebang line. `@tsrx/core/config` exports `resolveTsconfigJsx()` for the lookup, because the Bun plugins cannot depend on `get-tsconfig` without a lockfile change. React and Preact get real-Bun `native.test.ts` suites like Hono's, wired into CI. They cover both runtimes, classic tsconfigs, shebangs, `bun:test` preloads, and in-memory entrypoints. The READMEs now say that a production JSX runtime needs an automatic JSX setting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ases Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under `Bun.plugin()` and `bun:test` preloads, the classic-JSX check searched parent folders from the working directory, but Bun's runtime applies only `cwd/tsconfig.json`. A classic tsconfig in a parent folder therefore made the plugins force the development runtime, and production React modules threw `jsxDEV is not a function`, while plain `.tsx` files rendered. Runtime registration now consults `cwd/tsconfig.json` only when it exists and otherwise treats the setting as unset. `Bun.build()` keeps the nearest tsconfig lookup per file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ation As a `bun:test` preload, the plugin failed every test file with "Expected module mock to return an object", including files that import no `.tsrx` module. The `createVaporApp` interop hook returned nothing for modules it leaves unchanged and for files in node_modules. `Bun.build()` then loads the file itself, but `Bun.plugin()` registration requires an object from every onLoad hook. The hook now skips node_modules in its filter, which Bun evaluates before calling it. Without a build config it returns an unchanged module's source with Bun's default loader, which is `jsx` for `.js` files. The transformed `.js` case uses that loader too. The new native test runs a preload over an ordinary module and a `.tsrx` module. CI runs it like the Hono, React and Preact native tests. Fixes tsrx-org#1151 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the plugin as a `bun:test` preload, importing a component with a `<style>` block failed with `Expected loader to be one of "js", …` (Bun 1.3.14) or "Cannot find module '@tsrx/bun-plugin-hono-css:…'" (Bun 1.3.10). The plugin resolved the virtual stylesheet into its own namespace, and Bun's runtime accepts the `css` loader only in the `file` namespace. The stylesheet now stays in the `file` namespace, as in the React, Preact, Solid and Vue plugins. The onResolve hook still claims only stylesheets this instance compiled. The onLoad hook now leaves other stylesheets to the instance that compiled them instead of serving an empty sheet. Fixes tsrx-org#1152 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ugin() Under `Bun.plugin()` registration, including `bun:test` preloads, Bun calls only the first onLoad hook whose filter matches. If that hook returns nothing, Bun fails with "onLoad() expects an object returned" instead of trying the next hook. The `.tsrx` hook returned nothing for files left out by `include`/`exclude`. The stylesheet hook returned nothing for sheets another instance compiled. So `exclude` and setups with several instances failed at runtime in all five plugins. Instances registered at runtime now share state on a global symbol that every TSRX Bun plugin uses: the compiled stylesheets, and one loader per instance. An instance hands a `.tsrx` file it leaves out to the first registered instance that compiles it, including instances from another TSRX plugin. When none does, it returns what Bun loads without a plugin, a module whose default export is the file's path. Its stylesheet hook serves any instance's sheet and never returns nothing. `Bun.build()` keeps per-instance stylesheets and lets the next hook take a request. New native tests run a preload that splits files between two instances, leaves one file out of both, and hands a file from a React instance to a Hono instance. Solid gets a native test file, and CI runs the Solid and Vue native tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… Bun.plugin() Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under `Bun.plugin()`, the async interop hook answered for every project
`.js`, `.ts`, `.cjs` and `.cts` file. Bun loads a module an async hook
returns as an async module, and `require()` can't load one. So
`require('./legacy.cjs')`, directly or through `createRequire`, threw
"require() async module … is unsupported" under the preload. A sync hook
would still break `module.exports` in `.cjs` files.
The hook is now registered only for `Bun.build()`. A preload compiles
`.tsrx` modules and leaves every other module to Bun. The README says to
install `vaporInteropPlugin` by hand there. It also says that Vue
preloads cover `.tsrx` modules that export plain values: Vue 3.6's
`node` entry, which Bun's runtime resolves, has no Vapor APIs for a
component with a template.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Bun plugins share their runtime state on a global symbol. Name it `@tsrx/bun-plugin.runtime.v1`, so a later change to the state's shape can take a new key without breaking older plugins installed alongside. `Bun.plugin.clearAll()` gives plugins no notice, so instances registered before it stay in the shared list. The comment says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
jonkwheeler
marked this pull request as ready for review
October 27, 2026 17:27
This was referenced Oct 28, 2026
This was referenced Nov 6, 2026
main now has tsrx-org#1091's squash commit; merged against the parent commit this branch has so git doesn't redo that work. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler
added a commit
to jonkwheeler/tsrx
that referenced
this pull request
Nov 12, 2026
main now has tsrx-org#1186's squash commit; merged against the parent commit this branch has so git doesn't redo that work. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
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.
Stacked on #1091; review the commits after 01eae48; merge after #1091.
Summary
The Bun plugins now work as
bun:testpreloads, that is,Bun.plugin(...)in a--preloadfile.Under
Bun.plugin()registration, Bun calls only the firstonLoadhook whose filter matches. If that hook returns nothing, Bun fails with "onLoad() expects an object returned" (or "Expected module mock to return an object" for an async hook) instead of trying the next hook.Bun.build()falls through to the next hook. The plugins relied on falling through in three places:@tsrx/bun-plugin-vue([Bug]: bun-plugin-vue can't be used as a bun:test preload ("Expected module mock to return an object") #1151). Before, every test file failed before its first test, even files that import no.tsrxmodule. ThecreateVaporAppinterop hook returned nothing for files it leaves alone and fornode_modules.Bun.build(). A preload compiles.tsrxmodules and leaves every other module to Bun.Bun.plugin(), an async hook that answered for project files would make Bun load them as async modules, andrequire()of a.cjs,.jsor.ctsfile would throw "require() async module … is unsupported". A sync hook would still breakmodule.exportsin.cjsfiles.vaporInteropPlugintocreateVaporApp()by hand under a preload, and that Vue preloads cover.tsrxmodules exporting plain values (see below).Bun.build(), the hook's filter now leaves outnode_moduleswith a negative lookahead, which Bun evaluates before calling the hook. Rewritten modules use Bun's default loader, which isjsxfor.js.@tsrx/bun-plugin-hono([Bug]: bun-plugin-hono as a bun:test preload fails to load a styled component: Expected loader to be one of "js", … #1152). Before, a component with a<style>block failed withExpected loader to be one of "js", "jsx", …on Bun 1.3.14, orCannot find module '@tsrx/bun-plugin-hono-css:…'on 1.3.10. Bun's runtime accepts thecssloader only in thefilenamespace, so the virtual stylesheet now stays there, as in the other four plugins.include/excludeand multiple instances, all five plugins. Under a preload, a.tsrxfile left out byexcludefailed, as did another instance's stylesheet, so fix(bun-plugins): per-instance CSS, production JSX runtime, inferred root, and preload platform flags #1091's multi-instance split broke there. Instances registered withBun.plugin()now share state onSymbol.for('@tsrx/bun-plugin.runtime.v1'): the compiled stylesheets, and one loader per instance. The version in the key lets a later change to the state's shape take a new key without breaking older plugins installed alongside.Bun.plugin.clearAll()gives plugins no notice, so instances registered before it stay in the shared list..tsrxfile it leaves out to the first registered instance that compiles it. That can be an instance of another TSRX Bun plugin.Bun.build()keeps its per-instance stylesheets and still lets the next hook take a request.I didn't make this hook "return the file unchanged" for
.tsrx. Bun calls only the first hook, so returning the raw file would stop the instance that includes the file from ever compiling it.Two limits are outside the plugins. A Vapor
.tsrxcomponent still can't be evaluated underbun test, because Vue 3.6.0-beta.12's Node entry has no Vapor exports (Export named 'template' not found), and Bun's runtime doesn't call pluginonResolvefor the barevuespecifier. Solid's server build, which Bun's runtime resolves, rejects compiled DOM components with "Client-only API called on the server side". So the Vue and Solid native tests use.tsrxmodules that export plain values.Not fixed here:
addVaporInteropToCreateVaporAppskips the rewrite when another named import comes before thevueimport. #1101 replaces that regex with a parse and fixes it.Verification
Bun.plugin()dispatch (first matching hook only, which must return an object), two instances split the source files and each one's stylesheet loads.node_modulespaths.Bun.plugin(), and still leaves it alone underBun.build().bun test --preloadin a temporary fixture):.tsrxmodule importing.jsand.tshelpers, andrequire()s a.cjs,.jsand.ctsfile directly and throughcreateRequire(0 of 3 passed before the interop hook moved toBun.build()).test:nativescripts and CI steps.bunpackage) and 1.3.14: React 9/9, Preact 8/8, Solid 1/1, Vue 3/3, Hono 9/9. Bun vitest projects: 70 passed.npx vitest run(before the review fixes): 10037 passed, 82 skipped, 13 failed. All 13 were timeouts intypescript-pluginandtsrx-vuewhile other suites ran in parallel. Those 3 files pass with--testTimeout=120000(34 tests). Before this round, the full run had no failures (10041 passed).pnpm typecheck,pnpm changeset:checkand prettier are clean.Related
Fixes #1151
Fixes #1152
🤖 Generated with Claude Code
Note
Medium Risk
Touches module loading for all framework Bun plugins and global shared state at runtime; mis-handling could break builds, tests, or CSS under
Bun.plugin(), though behavior is heavily tested.Overview
All five TSRX Bun plugins now register correctly for
bun:testviaBun.plugin()in a--preloadscript. Under that mode Bun invokes only the first matchingonLoadand requires a return value, so the plugins no longer rely on returningundefinedto fall through.Instances share
Symbol.for('@tsrx/bun-plugin.runtime.v1'): a global stylesheet map and a per-instance loader list. Excluded.tsrxfiles are delegated to another registered instance (including cross-plugin, e.g. React → Hono); files no instance owns export the path as default. CSS virtual modules stay in thefilenamespace so thecssloader works at runtime (@tsrx/bun-plugin-honodrops its custom CSS namespace).@tsrx/bun-plugin-vuelimitscreateVaporApp/vaporInteropPluginrewriting toBun.build()only so preloads do not breakrequire()on project CommonJS; README documents manualvaporInteropPluginfor preloads. The build-time interop filter skipsnode_modulesand treats.jsasjsx.CI adds
test:nativefor Vue and Solid; unit and native tests cover preload behavior, multi-instance splits, and styled components.Reviewed by Cursor Bugbot for commit 2421f3a. Bugbot is set up for automated code reviews on this repo. Configure here.