Skip to content

Commit 99babf9

Browse files
linnil1teemingc
andauthored
Support wrangler.json configuration file in adapter-cloudflare-workers (#13148)
* feat: support wrangler.json * feat: Find the wrangler.json if the default config not found * Update packages/adapter-cloudflare-workers/index.js --------- Co-authored-by: Tee Ming <[email protected]>
1 parent 8749894 commit 99babf9

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ export default {
3434

3535
### config
3636

37-
Path to your custom `wrangler.toml` config file.
37+
Path to your custom `wrangler.toml` or `wrangler.json` config file.
3838

3939
### platformProxy
4040

4141
Preferences for the emulated `platform.env` local bindings. See the [getPlatformProxy](https://developers.cloudflare.com/workers/wrangler/api/#syntax) Wrangler API documentation for a full list of options.
4242

4343
## Basic Configuration
4444

45-
This adapter expects to find a [wrangler.toml](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It should look something like this:
45+
This adapter expects to find a [wrangler.toml/wrangler.json](https://developers.cloudflare.com/workers/platform/sites/configuration) file in the project root. It should look something like this:
4646

4747
```toml
4848
/// file: wrangler.toml

packages/adapter-cloudflare-workers/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,24 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {})
185185
* @returns {WranglerConfig}
186186
*/
187187
function validate_config(builder, config_file) {
188+
if (!existsSync(config_file) && config_file === 'wrangler.toml' && existsSync('wrangler.json')) {
189+
builder.log.minor('Default wrangler.toml does not exist. Using wrangler.json.');
190+
config_file = 'wrangler.json';
191+
}
188192
if (existsSync(config_file)) {
189193
/** @type {WranglerConfig} */
190194
let wrangler_config;
191195

192196
try {
193-
wrangler_config = /** @type {WranglerConfig} */ (
194-
toml.parse(readFileSync(config_file, 'utf-8'))
195-
);
197+
if (config_file.endsWith('.json')) {
198+
wrangler_config = /** @type {WranglerConfig} */ (
199+
JSON.parse(readFileSync(config_file, 'utf-8'))
200+
);
201+
} else {
202+
wrangler_config = /** @type {WranglerConfig} */ (
203+
toml.parse(readFileSync(config_file, 'utf-8'))
204+
);
205+
}
196206
} catch (err) {
197207
err.message = `Error parsing ${config_file}: ${err.message}`;
198208
throw err;

0 commit comments

Comments
 (0)