feat: add Bun adapter - #16695
Conversation
… configuration - Add env.js for managing environment variables with validation and fallback options. - Introduce handler.js to manage the Bun-native SvelteKit request handling. - Create index.js to configure server options based on environment variables. - Implement static.js for serving static files and handling prerendered paths. - Add utils.js for utility functions related to byte parsing and header management. - Create tests for environment variable functions and utility functions. - Set up a basic SvelteKit application with routes, static files, and event streams. - Configure Playwright for end-to-end testing of the application.
…nd enhance type definitions
…ndling in Bun build process
…or executable generation
…serving with URL encoding support
…improved performance
…asset handling - Added TLS configuration options in serverOptions, allowing for certificate and key specification. - Introduced embedded asset handling for serving static files with metadata (size, type, lastModified, etag). - Updated file_route to support embedded assets and conditional requests. - Enhanced compile options to reserve runtime target and module format, ensuring user configurations are safely composed. - Added tests for TLS options and embedded asset functionality to ensure robustness. - Improved documentation to clarify usage of new features and options.
…ed shutdown logic
…ironment variables
…ation and updating related tests
…s module and removing unused assets
…necessary declarations
…lization and improve type definitions
…s for Bun integration
… usage in configuration
… type definitions
…or entrypoint logic
…trumentation logic
…paths resolve from the output root
…the svelte.config.js removal
Bun.build emits a copy of a side-effect-only chunk (import 'x'; export {};)
per importer and every copy targets the same output path, failing real-world
apps with 'Multiple files share the same output path'. Resolve each importer's
copy to a distinct synthetic module so the copies no longer collide.
workspace:^/catalog: specifiers only resolve inside the kit monorepo; bun resolves a file: directory dependency's devDependencies, so installing the package from a submodule checkout fails on them. Pin branch for polumeyv production use of PR sveltejs#16695; rebase onto the PR head to update.
| } | ||
| ``` | ||
|
|
||
| `platform.request` remains the original request even when the adapter normalizes the request URL to a configured or proxy-derived public origin before passing it to SvelteKit. |
There was a problem hiding this comment.
what's the rationale for passing this through? does platform.request have methods/properties that event.request doesn't (like request.cf on Cloudflare)? if not I don't really see why we'd pass this along, we don't for any other platform
There was a problem hiding this comment.
It's identity, not extra properties. server.upgrade(request) and server.requestIP(request) only work with the request object Bun passed to fetch. Behind a proxy the adapter hands SvelteKit new Request(public_origin + pathname, request) so the origin matches, which makes event.request a copy: on 1.4.0, upgrade(copy) returns false and the socket never opens, requestIP(copy) is null. Without platform.request a route behind a reverse proxy cannot upgrade a WebSocket. The docs example shows the least useful property of it. I'll reword it around server.upgrade.
There was a problem hiding this comment.
Correction: the generated server never sets websocket, so upgrade() throws there with either request and that argument is moot. What identity still buys is server.timeout(request, seconds) and server.requestIP(request), and getClientAddress() already covers the second. That's thin. I'll drop platform.request and keep platform.server unless you'd rather keep it for timeout.
There was a problem hiding this comment.
I've never regretted being more restrictive at first and then exposing new stuff as and when a need is demonstrated. In this case I think the global idleTimeout option is probably sufficient... though that said AFAICT we're not currently setting a value other than the default, which IIUC is 10 seconds? That might not be sufficient, given that we chose 30 seconds as the (probably somewhat arbitrary) threshold for sending keep-alive comments for query.live in #16063.
We could either change the default here or there. But given that it's an experimental feature it needn't prevent us from merging this and allowing early adopters to start kicking the tyres
The generated server never sets websocket, so server.upgrade() throws with either request; getClientAddress() already wraps requestIP with the original. Nothing left justifies a second copy of the request on platform.
workspace:^/catalog: specifiers only resolve inside the kit monorepo; bun resolves a file: directory dependency's devDependencies, so installing the package from a submodule checkout fails on them. Pin branch for polumeyv production use of PR sveltejs#16695; rebase onto the PR head to update.
workspace:^/catalog: specifiers only resolve inside the kit monorepo; bun resolves a file: directory dependency's devDependencies, so installing the package from a submodule checkout fails on them. Pin branch for polumeyv production use of PR sveltejs#16695; rebase onto the PR head to update.
|
Once this gets released we can update the docs — for now I put a bunch of |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to version-3, this PR will be updated.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ `version-3` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `version-3`.⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ # Releases ## @sveltejs/adapter-bun@1.0.0-next.1 ### Minor Changes - feat: add a Bun-native adapter with static file serving and single-executable support ([#16695](#16695)) ### Patch Changes - Updated dependencies [[`9b3d195`](9b3d195), [`385d378`](385d378), [`3782448`](3782448), [`d0d3a33`](d0d3a33), [`4b7a483`](4b7a483), [`e325d7d`](e325d7d), [`4f63c79`](4f63c79)]: - @sveltejs/kit@3.0.0-next.25 ## @sveltejs/kit@3.0.0-next.25 ### Minor Changes - feat: add an `applyReroute` helper for adapters that support split serverless function deployments ([#16665](#16665)) ### Patch Changes - chore: build streamed responses from async generators ([#16847](#16847)) - fix: tweak response logging for remote requests ([#16865](#16865)) - fix: discard invalidation results when a navigation completes while they load ([#16852](#16852)) - fix: route dev-server response logging through Vite's logger so it respects `logLevel` and `customLogger` ([#16858](#16858)) - chore: read build-time config from defines on the server instead of carrying it in `options` ([#16873](#16873)) - chore: read `options` from a single module instead of passing it through the server runtime ([#16871](#16871)) ## @sveltejs/adapter-netlify@7.0.0-next.10 ### Patch Changes - fix: correctly apply `reroute` results for apps configured with split serverless functions ([#16665](#16665)) - Updated dependencies [[`9b3d195`](9b3d195), [`385d378`](385d378), [`3782448`](3782448), [`d0d3a33`](d0d3a33), [`4b7a483`](4b7a483), [`e325d7d`](e325d7d), [`4f63c79`](4f63c79)]: - @sveltejs/kit@3.0.0-next.25 ## @sveltejs/adapter-vercel@7.0.0-next.8 ### Patch Changes - fix: omit ISR data endpoints for server-only routes ([#16731](#16731)) - fix: correctly apply `reroute` results for apps configured with split serverless functions ([#16665](#16665)) - Updated dependencies [[`9b3d195`](9b3d195), [`385d378`](385d378), [`3782448`](3782448), [`d0d3a33`](d0d3a33), [`4b7a483`](4b7a483), [`e325d7d`](e325d7d), [`4f63c79`](4f63c79)]: - @sveltejs/kit@3.0.0-next.25 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
opened sveltejs/svelte.dev#2186 which will allows us to remove the |
|
I am thrilled that this was merged! This was my first PR ever for SvelteKit. Any feedback for future PRs? |
Thank you. Some things that we might want to change in follow-up PRs:
|
|
Noted @teemingc. Will keep these in mind. |
closes #16070
Summary
This PR adds an official
@sveltejs/adapter-bunpackage that builds SvelteKit applications into standalone Bun-native servers usingBun.serve, Web API requests/responses, native routes, andBun.file.What changed
$app/serverreads,instrumentation.server.js, server-sent events, graceful shutdown, request-origin normalization, and trusted proxy headers.Requestand BunServerthroughevent.platform, including Bun metrics andrequestIP.Key differences from
adapter-nodeadapter-bunadapter-nodeBun.serveand Web APIssirvwith Brotli/gzip precompressionevent.platformhandler.jsand Node request contextApplication imports follow Bun's bundler behavior rather than
adapter-node'sdependencies/devDependenciesexternalization policy.Decisions and tradeoffs
HEADbehavior.fetchandroutesto preserve SvelteKit behavior.event.platform.requestretains the original Bun request required by native APIs.Known limitations and future work
*as a route wildcard, so filenames containing a literal*are currently rejected at build time.buildOptions, dependency externalization controls, MIME handling, and literal-wildcard support.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits