Replies: 16 comments 11 replies
-
I think #3 is a very important point to make and principle to follow - using wrangler should be as easy as possible and provide the best possible developer experience. JSON is more easily readable, more difficult to write incorrectly, and more familiar in the javascript ecosystem; ergo, a better developer experience. (Disclaimer: this comment is brought to you by a couple of hours of trying to debug an issue with wrangler that turned out to be two brackets in the wrong place in my TOML file) |
Beta Was this translation helpful? Give feedback.
-
Agree that JSON is the most familiar to the JS ecosystem. Another good thing about JSON is that it's a subset of YAML, so any developers that want to use YAML can just convert it to JSON. On another note, I'm not sure what the official plans are but it would be nice to have some sort of modular configuration so different resources can be defined in "blocks", similar to what Kubernetes does with its resources type. This will allow us to:
|
Beta Was this translation helpful? Give feedback.
-
Sharing from an internal discussion: Something like cuelang could be interesting. However, it is a newer config language that has a bit of its own learning curve, and for that reason alone it may be more of a fun though experiment then something practical. |
Beta Was this translation helpful? Give feedback.
-
Adding a concrete example to @zaynehz 's comment. When referencing the docs for [[r2_buckets]]
binding = 'MY_BUCKET' # <~ valid JavaScript variable name
bucket_name = '<YOUR_BUCKET_NAME>' While writing workers with just a single top level environment this syntax is clear but once you add environments into the mix things become more confusing and less intuitive. For example name = "default-environment"
[[r2_buckets]]
binding = 'MY_BUCKET' # <~ valid JavaScript variable name
bucket_name = '<YOUR_BUCKET_NAME>'
[env.staging]
name = "staging-environment"
[[r2_buckets]] # this actually doesn't exist under `env.staging` prefix!
binding = 'MY_BUCKET' # <~ valid JavaScript variable name
bucket_name = '<YOUR_BUCKET_NAME>' We can see here that the intent it the second There is a toml syntax for we can adopt in the docs to help make things clearer but the solution still isn't perfect. It involves not using the inline tables syntax. name = "default-environment"
r2_buckets = [
{ binding = 'MY_BUCKET' , bucket_name = '<YOUR_BUCKET_NAME>' }
]
[env.staging]
name = "staging-environment"
r2_buckets = [
{ binding = 'MY_BUCKET' , bucket_name = '<YOUR_BUCKET_NAME>' }
] This confusion extends to the other developer platform products as well and not just R2. A non-exhaustive list is
Finally, I should note for those who prefer the inline syntax, the correct form is to use a fully-qualified keyname. [env.staging]
name = "staging-environment"
[[env.staging.r2_buckets]]
binding = 'MY_BUCKET' # <~ valid JavaScript variable name
bucket_name = '<YOUR_BUCKET_NAME>' Footnotes |
Beta Was this translation helpful? Give feedback.
-
Though I’ve not thought through the details, and this is a very ambiguous proposal to make, I’d like to at least float the idea of a CDK-first approach (eg. AWS CDK or Terraform), not just for bindings but for the infra as a whole. This is obviously a large conversation to try to tackle at once, but it seems like a very intriguing idea. Especially given AWS is heavily leaning towards infra as code (CDK) compared to static config, especially internally. (But otherwise, as a short term solution, I definitely prefer JSON or point 4 from above, for all of the other reasons mentioned in the thread) |
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for the responses! It seems there's a general consensus to move to JSON(C/5)/YAML from TOML, with various other ideas on the horizon. Limiting the scope of this to just the syntax of configuration, here's a proposed plan for how we get to a place where we've replaced
|
Beta Was this translation helpful? Give feedback.
-
cosmiconfig is quite popular as a solution in the JS ecosystem. This allows users to choose whether they want JS, JSON, YAML, whatever (even in |
Beta Was this translation helpful? Give feedback.
-
Regardless of the formats supported, I think a json schema for |
Beta Was this translation helpful? Give feedback.
-
I'm a little late to respond here, but I'd like to vote against YAML, please, at least as the recommended or default config. Wrangler recently moved to hard tabs for indentation for accessibility reasons as per my issue opened at #1298. Many of Cloudflare's other projects are doing the same. Using a config language that's inherently inaccessible by not supporting tabs for indentation is a bad idea. There are of course hacks that could be done to allow tabs for indentation, but many editors and IDEs won't play nicely with this. JSON support seems the most logical to me, with lots of tooling already using it, such as the |
Beta Was this translation helpful? Give feedback.
-
The even-better-toml VSCode extension supports JSON schemas, using the |
Beta Was this translation helpful? Give feedback.
-
With the recent Release https://github.com/cloudflare/wrangler2/releases/tag/wrangler%402.9.0 there is now a |
Beta Was this translation helpful? Give feedback.
-
I'm wondering if anyone knows of a JSON schema for |
Beta Was this translation helpful? Give feedback.
-
No schema, as such. But if you run a Wrangler command in a directory containing the directory containing the wrangler.toml, Wrangler will fail if the file is invalid. It actually is better than a schema as the validation can check a few more complex constraints. |
Beta Was this translation helpful? Give feedback.
-
Hi, if anyone's interested, I ended up defining a JSON Schema for Wrangler using https://github.com/sinclairzx81/typebox. You can find the repo here: And the generated JSON Schema file here: |
Beta Was this translation helpful? Give feedback.
-
Is there a plan for when the json configuration will be marked as stable? I would like to start using it in production. |
Beta Was this translation helpful? Give feedback.
-
Personally, I would love to see wrangler config move towards using js/ts for config. For most users, it would still just feel like glorified JSON - although less annoying with commas/quotes and would allow for comments. (sidenote: would love to see more JSONC/5 adoption but shockingly IDE tooling still sucks!). But you'd actually get full IDE support and intellisense, not just the half-baked version we get with json schema or other IDE plugins. Plus for those situations that require it, you could easily use regular code to construct your config as you see fit. Plus it would provide a much cleaner way to start thinking about plugins/hooks/etc... Look at vite for inspiration. |
Beta Was this translation helpful? Give feedback.
-
Following on from #1929 —it's probably worthwhile having a discussion about the future of configuration for Wrangler, pulling together the various discussions there have been at different points. The linked PR shows one approach—wholesale migrating from TOML->JSON—but I know there are different opinions to be heard here. From my own thinking (to kick this off):
wrangler.ts
orwrangler.js
file that describes the configuration of your Worker (but see point 1, this can't be the only way)The outcome of this discussion could well be that we decide to stick with TOML, but I thought it was worth airing all the various thoughts on this in one place, rather than spread across different GitHub issues.
Beta Was this translation helpful? Give feedback.
All reactions