sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.19k stars 1.85k forks source link

Make `wrangler` optional when installing the Cloudflare adapters #11986

Open eltigerchino opened 4 months ago

eltigerchino commented 4 months ago

Describe the problem

Currently, we use wrangler to emulate the event.platform variable for cloudflare bindings, etc during development.

But the wrangler package is pretty big and is not exactly essential if you're not planning on using any of the cloudflare services such as D1 databases, etc. (which is unlikely) or if you're just creating a quick repro on stackblitz. This makes dependency install times much longer (potentially affecting CI/CD for builds and tests? I'm not well versed in that area).

Additionally, your app simply won't run on environments such as stackblitz where workerd is not supported. https://stackblitz.com/edit/sveltejs-kit-template-default-rnvvem?file=svelte.config.js

cc: @dario-piotrowicz how are other frameworks handling this? and is this even worth pursuing?

Describe the proposed solution

Is it possible for us to make it an optional dependency or a peer optional dependency? Would that prevent it from being installed automatically?

Alternatives considered

Maybe this isn't even worth pursuing and we'd only want the cloudflare adapters to work in environments that can run a workerd emulation by wrangler.

Importance

nice to have

Additional Information

No response

dario-piotrowicz commented 4 months ago

how are other frameworks handling this?

other frameworks usually have wrangler as a peer dependency, or only have the wrangler (peer) dependency in their Cloudflare specific adapter packages.

For example:


and is this even worth pursuing?

personally I would say that it might not be, since it only applies to your Cloudflare specific adapters (and if people use those they might as well get access to the proper platform variables)

(the only noticeable negative being stackblitz... but I am not sure how many developers use stackblitz with SvelteKit and Cloudflare, it doesn't feel to me like a common/core use case)

if you do want to reap out the wrangler dependency you could do what nitro/nuxt is doing, basically by not including wrangler as a peer dependency, and simply trying to dynamically import the getPlatformProxy and define a fallback behaviour if wrangler is not present/the import fails (for example by presenting an error to the user and returning a no-op version of the platform proxy)

eltigerchino commented 3 months ago

https://github.com/sveltejs/kit/issues/12049 is a related issue. The adapter isn't able to build on Alpine.