-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overhaul adapter API #2931
Overhaul adapter API #2931
Conversation
🦋 Changeset detectedLatest commit: 0de1aa3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
So how does it work now? |
yes, Kit as middleware works fine and same way as it's written in docs. |
@Mlocik97 can you point me to an example? https://kit.svelte.dev/docs#adapters-supported-environments-node-js |
it's partially described here: https://github.com/sveltejs/kit/tree/master/packages/adapter-node#custom-server but I see it's missing in docs (it was there before), not sure why... but when they rewrote those adapter sections, somehow, part for this was deleted. |
as far as I can remember it was only in the readme, like the current version |
if I remember correctly there was short description about it and link to Readme. It's not now... anyway it would be better to add it to docs. |
I'm starting porting over svelte-adapter-appengine to this new API, the serving part is pretty straight forward there (based on the adapter-node), but the routes are a bit more tricky. I need to create a routing file that correctly sends traffic either to static/prerendered content that is hosted from cloud storage (so never hitting the node server), or the dynamic traffic to the node server. The new createEntries function seem to be a step forward in terms of creating this routing file correctly, but one thing I'm wondering about is how to determine in that function if a page is actually prerendered, and therefore shouldn't be handled by the node server. I could check if the |
@HalfdanJ kit/packages/kit/types/config.d.ts Lines 85 to 87 in 1a6adc8
|
Aha ok that helps a bit, |
pardon for asking here about this but how do i solve this issue not that the esbuild option is gone from the adapter config?
has no effect on this issue. |
I second this ^^; My vercel build has also been failing since the removal of the esBuild config options in @sveltejs/adapter-vercel. I've continued developing using the following package versions (last working):
However, that's definitely less than ideal as I'm continuing to build around an outdated API for both @sveltejs/kit & @sveltejs/adapter-vercel. The dependency causing my build issues (@napi-rs/*) is a package required indirectly as a dependency of a package in a shared monorepo used in the frontend. (Backend defines db schema, controllers, autogen type definitions, etc. that are used both in the frontend and for writing real time data scraped from various sources to the db, hence the monorepo greatly streamlines the dev process). I'd previously built the frontend project successfully using both Vite resolve.alias and via installing the pnpm symlinked version of the built package as a dependency during the build process (setting pnpm to shamefully-hoist when building on Vercel) using the following esBuild config options:
Following the breaking API changes, I've tested with updated versions of @sveltejs/kit & @sveltejs/adapter-vercel using at least the following Vite config settings (both individually and in varying combinations), but to no avail. Vite Config Options Tested:
(I think I'd tried setting it as a rollup external as well using Vite config options, but that also failed to resolve the issue) Build always fails with the following error:
Any solutions for getting this build to work with the latest versions of @sveltejs/kit and @sveltejs/adapter-vercel? |
@jmsunseri @cryptodeal comments like these on merged PRs are easily lost. If this PR removed a feature you needed, can you open an issue instead? |
I wasn't entirely sure it was an issue and maybe just me misunderstanding the correct path to take now that it's been removed. I had assumed there was a new better way to do it. If that's indeed not the case I will happily open a new issue. |
Good call, @geoffrich; I just opened Issue #3588. |
At present,
svelte-kit build
generates a monolithicapp.js
, via Vite. Adapters interact with it by importing theinit
andrender
functions therein and using them in the context of a platform-specific function —adapter-node
callsrender
inside a Polka handler,adapter-netlify
calls it inside a Lambda event handler, and so on.This doesn't scale. Lambdas have a size limit of 50MB; Cloudflare Workers have just 1MB. Many apps won't reach these limits but many will. We need to be able to split apps into smaller chunks. Doing so has additional benefits:
This PR implements that idea, by updating the adapter API with a method to output multiple functions.
need to be able to return an array of entries, because of how Architect handles catch-alls (see below)sharp
ASSETS
is passed in; it's currently duplicative with the app manifestpnpm-workspace.yaml
and lockfile.svelte-kit
— hardcoding that directory feels super brittleutils
tobuilder
, which still isn't a great name but is definitely betterIt would also be nice to reach out to adapter authors who will be affected by these breaking changes.
Closes #2580 as well as the issues mentioned in that PR. I.e. closes #2517, closes #2581
Platform quirks
I think the API I've come up with,
createEntries
, is about as simple as it could be, though feedback is welcome. There's a fair bit of complexity inherent in this problem, because every platform does routing a little bit differently, and SvelteKit has two features in particular that are tricky to express on some of them:/foo/*
is okay,/foo/*/bar
is not*
as 1 or more segments, meaning that to express/foo/[...rest]/bar
we need both/foo/*
and/foo/bar
routes pointing to the same functionfoo/bar-[baz]
will match/foo/bar-x
but not/foo/qux-x
. Most platforms only allow you to express/foo/:param
In summary, a platform route needn't correspond to an app route, and the way that they're grouped will differ between platforms.
The
createEntries
method generates those groups:It's a little complicated, but then it's doing a slightly complicated thing. Most SvelteKit users will never need to understand this or touch it.
Notable API changes
This felt like as good a time as any to introduce some overdue changes to the adapter API (though maybe it would be kind to deprecate certain methods instead of nuking them altogether).
We use snake_case inside the SvelteKit codebase, because it's inherently superior to camelCase. Since the wider JavaScript community isn't yet in agreement, our policy is to use camelCase for public APIs. Currently, the adapter API violates that principle.
In addition to adding
createEntries
, this PR updates the following method names:copy_client_files
->writeClient
copy_server_files
->writeServer
copy_static_files
->writeStatic
The
copy
method signature has changed:The
app.js
file still exists, but whereas it previously exportedinit
andrender
functions, it now exports anApp
class that expects a manifest of the form created by theentry.generateManifest({...})
method above:It also exports an
override
function, but this is used by SvelteKit during prerendering andsvelte-kit preview
; adapter authors don't need to use it.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0