cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.59k stars 670 forks source link

🚀 Feature Request: Expose `readConfig` as API for programmatically use #3897

Open alexanderniebuhr opened 1 year ago

alexanderniebuhr commented 1 year ago

Describe the solution

When using Wrangler in combination with other development servers like Astro, it becomes necessary to read the Wrangler configuration programmatically. Currently, there's no straightforward way to do this, which makes integration cumbersome and less efficient.

I propose exposing the readConfig function as a programmatic API. This would allow developers to easily read the Wrangler configuration when using Wrangler programmatically in combination with other tools.

  1. Manually reading and parsing the wrangler.toml file: This is error-prone and doesn't account for any internal logic that Wrangler might use to read its configuration, or any added options.
  2. Using child processes to run Wrangler commands and parse the output: This is inefficient and can lead to various issues related to process management.

This feature would be particularly useful for developers who are using Wrangler in a more complex setup, where multiple development servers or build tools are involved. For example, when using Wrangler with Astro, one could read the Wrangler config to programmatically set up proxying, environment variables, etc.

sdarnell commented 12 months ago

Also note that it appears there is a move to switch from .toml to .json (Yay! 🥳 ) but when that happens it'll be more complicated and error prone (to support both).

alexanderniebuhr commented 12 months ago

Sure, would love to see exposed APIs for json also. :)