Replies: 1 comment 1 reply
|
Hey! 👋 Thanks for trying this out and sharing your findings! Just a note: the issue addressed by your first proposal is a Bun compatibility bug that has already been tracked here for quite some time: oven-sh/bun#4822 I'm not convinced we should change the AdonisJS codebase to work around runtime-specific issues, especially when the current implementation works correctly on Node.js. Ideally, those incompatibilities should be addressed on Bun side instead. Out of curiosity, what is your motivation for using Bun during development while still targeting Node.js in production? What benefits does that setup provide in practice? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I spent a couple of days running a real AdonisJS v7 app (Lucid + Inertia +
@adonisjs/vite, ~370 backend tests) with bun as the dev and ace runtime, keeping node as the production runtime. It works end to end:bun --hotreplaces hot-hook for backend reloads, bun's transpiler replaces the ts-exec loader, the in-process Vite dev server keeps React HMR, and a one-lineace.tsentrypoint (import './bin/console.js') replaces the scaffoldedace.js. A production build made withbun ace.ts buildboots and serves under plain node unchanged.Four things were needed to get there. Two are bun bugs I've reported separately: tsconfig
extendsvia a package specifier losescompilerOptions, which breaks Lucid's decorators (oven-sh/bun#34494), and a URL parsing divergence from node that breaks jsonschema, which@adonisjs/aceuses for command metadata validation (oven-sh/bun#34495). The other two are in AdonisJS's court, and they are the reason for this discussion.Proposal 1: ship the starter kits' imports map with a
bunconditionThe scaffolded subpath imports point at compiled paths:
{ "imports": { "#controllers/*": "./app/controllers/*.js" } }Under
node acethe ts-exec loader rewrites.jsto.ts, and in the build the.jsfiles exist. Bun resolves the map literally and finds neither, so every#aliasimport fails at boot. Conditional targets fix it with no effect on node, which never reads thebunkey:{ "imports": { "#controllers/*": { "bun": "./app/controllers/*.ts", "default": "./app/controllers/*.js" } } }I've run a full app plus test suite on this shape; node dev, node production build, and bun all resolve correctly. One caveat worth documenting: bun commits to the
buncondition without falling back, so running a built app under bun requires flattening the map back to thedefaultstrings (a build step could do this, since the compiled output has no use for the condition).Proposal 2: document the dev-server contract assembler uses
Everything
node ace serve --hmrdoes for the HTTP process turns out to be two environment variables injected into the child (assembler's#startHTTPServer):DEV_MODE=true, which makes@adonisjs/vite's provider start the dev server in-process, andVITE_HMR_PORT, which pins the HMR websocket port (without it the websocket fails to bind). Once you know that, a custom entrypoint on any runtime gets the full dev experience, Vite HMR included:Today this contract is only discoverable by reading assembler's source. I'd like to see it documented (or exposed as named constants) as the supported hook for custom dev servers and alternative runtimes. I'm happy to write the docs PR if there's interest.
One more finding from the same run, in case it saves someone a rabbit hole:
bun --hotre-evaluates the entrypoint without running shutdown hooks but preservesglobalThis, so a bun dev entrypoint should stashapp.terminateonglobalThisand await it before re-booting. Otherwise the previous instance's Vite websocket keeps its port and reloads silently fall back to the built manifest.References: bun's TypeScript runtime docs (https://bun.com/docs/runtime/typescript) and node's subpath imports and conditional exports (https://nodejs.org/api/packages.html#subpath-imports).
All reactions