-
-
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
WIP: Add adapter-deno #1271
WIP: Add adapter-deno #1271
Conversation
I'm not at all familiar with Deno. I noticed you had to use their server package, which doesn't support compression, etc. Can Deno not run Polka? It also seems a little annoying that Deno isn't capable of understanding the Anyway, glad to see that it seems like this mostly works! I do think it'd probably be better for this to live in an external repo, but we should surface it somewhere like /~https://github.com/sveltejs/integrations |
I'm also relatively new to working with Deno, and still struggling a bit with the Node-Deno interfacing and cross-compatibility issues. I did not try to get Instead, I looked around for the HTTP servers available at https://deno.land/x/, in the spirit of trying to keep it aligned with Deno conventions, even if the ecosystem is still very much in flux. I used The import map thing is indeed not ideal, although it might be possible to auto-generate it at build-time in |
The main problem I'm facing, though, is how to handle server-side code in Svelte components, API routes, or Looking at the other adapters, it seems like there is much less friction with this kind of issue, I guess because the underlying runtimes are Node-compatible. From what I understand, the same Svelte Kit project should be able to be built using any adapter, but this assumption seems to be naturally restricted to Node-compatible runtime adapters. This is also kind of related to the discussion in #754 regarding support for Web-only ESM packages, the same friction occurs between the client and the server runtimes, due to universal rendering imposing some degree of cross-compatibility of packages between target environments. |
Rather than providing an import map etc, I wonder if we should just be bundling kit/packages/adapter-vercel/index.js Lines 29 to 36 in bbbbe89
|
That does sound like a good option, the import map was mostly used as an interim solution, bundling is comparatively more resilient to a few of the cases I mentioned. I'll take a look at it later this week, looking at the However, I'd love to hear your opinion @Rich-Harris concerning Svelte Kit's cross-adapter/runtime compatibility. Unless the Node compatibility layer is used for everything, it won't be possible in practice for a single SvelteKit application to support both Node-style adapters and the Deno adapter. Is that consistent with the philosophy you're aiming for? |
Can you elaborate? The SvelteKit runtime doesn't (or at least shouldn't) have any Node dependencies — in theory it will run anywhere JavaScript runs. (Of course, that doesn't take account of other app dependencies that use Node built-ins; presumably we'd need SvelteKit itself to run on Deno in order to prevent those sneaking in) |
Exactly, I was thinking of external Node dependencies that will inevitably be used in real applications. In practice, once a non-pure JS dependency is needed (either Node or Deno), you have to commit to the corresponding runtime. For a significant fraction of projects I guess it would be feasible to do something like starting with For someone starting with Deno today (and using Deno-specific libraries, URL imports, in their SSR code, hooks, etc.), migration to another runtime would be comparatively non-trivial, at least in the absence of a comparable Node-supported Deno compatibility layer. That's kind of the gist of the argument, although your proposal for just bundling in the imports/requires does simplify matters for pure JS libraries, I'll try to put something together that at least successfully builds the Svelte Kit demo and Realworld apps. |
6573742
to
e045f6d
Compare
I made some further progress on this branch:
I did get the Svelte Kit demo application fully working, whereas before I couldn't get the
It seems like there is indeed some subtle coupling with Node in a couple of functions, due to the way they are typed. I guess it's always possible to argue that the caller is responsible for converting into these interfaces, but that does not necessarily provide the best experience in terms of dev ergonomics. |
yeah, the |
packages/adapter-deno/src/http.js
Outdated
return null; | ||
} | ||
|
||
const data = await Deno.readAll(req.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider changing this, see https://deno.com/blog/v1.9#new-api-deprecations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw that this morning, updated it to use the std/io
readAll
instead of the deprecated global Deno
namespace one. Can you check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, good job
@buttercubz what would you say would be the logical next step for this? I was thinking of writing basic smoke tests (adapted from the other adapters), but I guess it would make sense to write it already under the Deno runtime and conventions, so using Going down that route, I wonder whether it would make sense to use |
my apologies for the slow response, I think tests should be added, a good solution is https://www.npmjs.com/package/deno-bin, regarding the bundle I think rollup would be more than enough. also we can build a deno deploy adapter, i think |
Use esbuild to build server/app.js Use Deno-specific version of getRawBody() to handle differences in ServerRequest object types
6a2bf85
to
221d868
Compare
|
@jpaquim it's really great that you shared this with us and awesome to see it progressing! We're trying to have most of the adapters maintained externally as we don't have enough expertise with the various platforms. We're going to launch a new version of sveltesociety.dev written in SvelteKit that has a section listing out the various SvelteKit adapters that have been created and link to that from the SvelteKit site. It'd be great to see this work get its own repo and listed there. You can send a PR to list I'm going to go ahead and close this, but please let us know if there are API issues you need to solve to support Deno |
Thanks for the feedback @benmccann , I'll proceed as you mentioned and move this to a separate repository. Is there any community maintained organization where it would make sense to create the repo? Or should I just create it under my personal account/org? And I guess the naming convention for the npm package should be something like |
There's no community-maintained org, so putting it in your own account or org would make sense. |
@benmccann @buttercubz and whoever may be interested, I moved the Deno adapter code to a new repo, and published an initial version to NPM: Repo: /~https://github.com/pluvial/svelte-adapter-deno Everyone is welcome to join in on the development, next steps will be writing tests, and filling out the missing functionality such as cookie handling. And I've yet to try out Deno Deploy, there may be something interesting to do there, more similar to the Cloudflare Workers adapter. |
Cool! I added it to sveltejs/integrations and to the Svelte Society rewrite (when the latter is done it will replace the former) |
I just saw this issue #976, so please feel free to close this if there's no interest.
This is still a work-in-progress, but my goal was to have some kind of working adapter for Deno, or otherwise understand the main points when integrating with the current Svelte Kit code.
The good news is I managed to get a couple of examples working, the
skeleton
template, and thedefault
template almost working.The process I used for testing was setting up a new Svelte Kit app with
npm init
,npm link
ing my localadapter-deno
, and using a process equivalent toadapter-node
:To actually run the built code with deno, I'm using
# deno run --import-map=import-map.json --allow-env --allow-read --allow-net build/index.js
where
import-map.json
maps the module names to the corresponding location in the filesystem:To actually run the
default
Svelte Kit template, I had to adapthooks.js
to use the Deno version ofuuid/v4
, and removed thecookie
-handling for now.There's definitely still a lot of work to be done, and I have a feeling that I'll soon hit a roadblock, but still wanted to put this out there in case anyone else wants to do something with it.