unjs / unenv

🕊️ Convert javaScript code to be runtime agnostic
MIT License
340 stars 18 forks source link

Dedicated `wrangler` preset #262

Open pi0 opened 2 weeks ago

pi0 commented 2 weeks ago

We have introduced a new cloudflare preset and set of $cloudflare polyfill variations set by this preset to allow leveraging hybrid Node.js compatibility available in workerd runtime.

Initially, cloudflare preset was introduced to be included in Nitro (rollup based) and we are working with cloudflare team to also integrate unenv into wrangler tooling (esbuild based)

Apart from bundler subtle differences (rollup and esbuild), from discussions like #257 i can predict in the future, we might have legit reasons that Nitro and Wrangler might need different ways of adding Cloudflare polyfills.

One way is to expose standard plugin (~> https://github.com/unjs/unenv/issues/263) but still decisions might vary on tool level between wrangler and Nitro objectives.

I propose to introduce a new wrangler preset ahead of time (maintained by @IgorMinar @jculvey as well) to allow forward-compatible way to collaborate releases between unenv and wrangler without imposing unwanted changes to the end users.

IgorMinar commented 2 weeks ago

I'll think about this more, but I'd really like to avoid wrangler specific preset. The hybrid polyfill we implemented relies on aligning versions of workerd and unenv and this will become much harder to reason about if we in addition to this also have to think about two different presets.

pi0 commented 2 weeks ago

I also wish minimum possible variations and wrangler preset (extending cloudflare > nodeless) to be as empty as possible.

My intention is not to duplicate efforts but have a safe space that we can put wrangler-specific requirements. For example injection for global Performance polyfills with Node.js addons.

(i might have better idea for configurable presets to avoid additional one but the gist of idea will be same: a way to cerianly know if we are exporting preset for wrangler or nitro and with or without Node global API)