Open IgorMinar opened 3 months ago
This mostly works today, by generating a wrangler.toml
file in the source directory of the project during the build. I'm not sure I'm quite clear on the specific ask here:
wrangler.toml
file during the build, which users would never seewrangler.toml
files: How are frameworks planning to reconcile a user-written wrangler.toml
and the framework authored one? Is this for things like automatically adding a compat flag? I wonder if wrangler.toml
is the wrong abstraction for frameworks to use here, since it sounds like there's a need for much greater control over the output than users would want/need directly. Maybe supporting frameworks outputting a _worker.bundle
file directly might be the way to go here? That would allow them to fully customise the wrangler.toml
parsing and metadata construction behaviour, as well as completely bypass Wrangler's bundling & module rules.
Supporting _worker.bundle
would be fantastic for Nitro-based deployments.
- Increasing noise for developers: Frameworks can generate a dynamic
wrangler.toml
file during the build, which users would never see
@penalosa you'd see it if you were doing direct deploy rather than using the pages CI to deploy.
Maybe supporting frameworks outputting a
_worker.bundle
file directly might be the way to go here?
That's what I'm thinking as well. The build output will then become environment specific (unlike today when it's environment-agnostic since _worker.bundle is created during deployment based on env selection), but that's ok.
This mostly works today, by generating a wrangler.toml file in the source directory of the project during the build. I'm not sure I'm quite clear on the specific ask here:
Just made an experimental change to try this (https://github.com/unjs/nitro/pull/2355) as a short-time hotfix.
Here is the simple repo for a nitro app: https://github.com/pi0/nitro-app-cf
If you want to try the CI locally, you can use pnpm install
> CI=1 pnpm build
and notice it will generate a top-level wrangler.toml
file (it is dynamically generated by nitro)
From build logs, notice that No Pages config file found
is thrown before build command.
@pi0 Because the wrangler.toml
file is generated during the build, build-time environment variables won't be injected (which is what that initial error message refers to). However, bindings, compatibility flags, and runtime environment variables should all work for the deployed project
@penalosa After some trial and error (and some pointers re wrangler validation thanks to @atinux) I found with a default name
(any value is that ok?) and pages_build_output_dir
(tested here) it only works with after build.
But it has the issue that if a framework wants to auto-enable a certain flag (like nodejs_als
) it makes the bindings defined by user in UI, not work anymore and disabled because as I could understand, the auto-generated wrangler.toml
becomes the only new source of trust. It makes it essentially a breaking change for our users when they configure bindings through UI.
Would _worker.bundle
and _build.metadata.json
in https://github.com/cloudflare/workers-sdk/pull/5580 allow to support both user config and framework auto generated config combined?
(btw thank you so much for the quick response โค๏ธ)
@pi0 oof, I was hoping that we could avoid this because this will result in weird "source of truth" issues. This is why we design the wrangler.toml support in Pages to override and not augment the dash config.
Now I understand some of your comments. It seems that what you really want is an ability to intercept the runtime config creation in wrangler and augment it. Is that right?
@pi0 we intentionally lock the dashboard in cases like this (where we would have to merge config from a file and from the UI), because it's not always clear how that merging should work. For instance, what if a user added some compatibility flags via the dashboard? In the Nuxt case ideally that list would be merged with the Nuxt provided list so that nodejs_compat
was preserved, but that's not the only way to do that merging (potentially in another scenario the user would want UI flags to override config flags entirely). Because of that potential for conflict, when Pages config is managed via a config file we lock the dashboard UI to prevent confusing states.
However, what the linked PR would give you is a way to manage the merging of user config (from a file) and framework config yourself, within the framework build command. This would let frameworks individually decide on the specific logic they want to use for merging, although it wouldn't let users edit things through the dashboard.
Describe the solution
NuxtHub, Nuxt, and Nitro would like to be able to hide / abstract away wrangler.toml configuration for full-stack app deployments via
wrangler pages deploy
and Pages CI.In the ideal scenario, Nitro (powering Nuxt and NuxtHub) would as part of the build generate a config file (wrangler.toml or more likely a subset of it stored in a simpler format), and this configuration would be picked up by wrangler when the application is deployed to pages.
The configuration supported in this way is limited to JS runtime config (compat flags and date and bindings config). This would enable to frameworks to completely manage runtime configuration on behalf of the user without exposing them to often unnecessary deployment configuration.
Without any other changes, the only way to approximate this behavior now is by the framework generating wrangler.toml and writing it into the source directory of the project, which increases noise for developers and creates a potential for clobbering developer's modifications.
// @pi0 @atinux