|
| 1 | +--- |
| 2 | +"wrangler": minor |
| 3 | +--- |
| 4 | + |
| 5 | +feat: add support for redirecting Wrangler to a generated config when running deploy-related commands |
| 6 | + |
| 7 | +This new feature is designed for build tools and frameworks to provide a deploy-specific configuration, |
| 8 | +which Wrangler can use instead of user configuration when running deploy-related commands. |
| 9 | +It is not expected that developers of Workers will need to use this feature directly. |
| 10 | + |
| 11 | +### Affected commands |
| 12 | + |
| 13 | +The commands that use this feature are: |
| 14 | + |
| 15 | +- `wrangler deploy` |
| 16 | +- `wrangler dev` |
| 17 | +- `wrangler versions upload` |
| 18 | +- `wrangler versions deploy` |
| 19 | +- `wrangler pages deploy` |
| 20 | +- `wrangler pages build` |
| 21 | +- `wrangler pages build-env` |
| 22 | + |
| 23 | +### Config redirect file |
| 24 | + |
| 25 | +When running these commands, Wrangler will look up the directory tree from the current working directory for a file at the path `.wrangler/deploy/config.json`. This file must contain only a single JSON object of the form: |
| 26 | + |
| 27 | +```json |
| 28 | +{ "configPath": "../../path/to/wrangler.json" } |
| 29 | +``` |
| 30 | + |
| 31 | +When this file exists Wrangler will follow the `configPath` (relative to the `.wrangler/deploy/config.json` file) to find an alternative Wrangler configuration file to load and use as part of this command. |
| 32 | + |
| 33 | +When this happens Wrangler will display a warning to the user to indicate that the configuration has been redirected to a different file than the user's configuration file. |
| 34 | + |
| 35 | +### Custom build tool example |
| 36 | + |
| 37 | +A common approach that a build tool might choose to implement. |
| 38 | + |
| 39 | +- The user writes code that uses Cloudflare Workers resources, configured via a user `wrangler.toml` file. |
| 40 | + |
| 41 | + ```toml |
| 42 | + name = "my-worker" |
| 43 | + main = "src/index.ts" |
| 44 | + [[kv_namespaces]] |
| 45 | + binding = "<BINDING_NAME1>" |
| 46 | + id = "<NAMESPACE_ID1>" |
| 47 | + ``` |
| 48 | + |
| 49 | + Note that this configuration points `main` at user code entry-point. |
| 50 | + |
| 51 | +- The user runs a custom build, which might read the `wrangler.toml` to find the entry-point: |
| 52 | + |
| 53 | + ```bash |
| 54 | + > my-tool build |
| 55 | + ``` |
| 56 | + |
| 57 | +- This tool generates a `dist` directory that contains both compiled code and a new deployment configuration file, but also a `.wrangler/deploy/config.json` file that redirects Wrangler to this new deployment configuration file: |
| 58 | + |
| 59 | + ```plain |
| 60 | + - dist |
| 61 | + - index.js |
| 62 | + - wrangler.json |
| 63 | + - .wrangler |
| 64 | + - deploy |
| 65 | + - config.json |
| 66 | + ``` |
| 67 | + |
| 68 | + The `dist/wrangler.json` will contain: |
| 69 | + |
| 70 | + ```json |
| 71 | + { |
| 72 | + "name": "my-worker", |
| 73 | + "main": "./index.js", |
| 74 | + "kv_namespaces": [{ "binding": "<BINDING_NAME1>", "id": "<NAMESPACE_ID1>" }] |
| 75 | + } |
| 76 | + ``` |
| 77 | + |
| 78 | + And the `.wrangler/deploy/config.json` will contain: |
| 79 | + |
| 80 | + ```json |
| 81 | + { |
| 82 | + "configPath": "../../dist/wrangler.json" |
| 83 | + } |
| 84 | + ``` |
0 commit comments