From c7ec16a4bfb0e06e29688713d385579eb5cd9a1f Mon Sep 17 00:00:00 2001 From: linnil1 Date: Wed, 11 Dec 2024 23:17:09 +0800 Subject: [PATCH 1/3] feat: support wrangler.json --- .../70-adapter-cloudflare-workers.md | 2 +- packages/adapter-cloudflare-workers/index.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md index bd53dd4d8e7d..ba04a0808209 100644 --- a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md +++ b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md @@ -34,7 +34,7 @@ export default { ### config -Path to your custom `wrangler.toml` config file. +Path to your custom `wrangler.toml` or `wrangler.json` config file. ### platformProxy diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index 8a4f9252d1ac..cd4caaed416d 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -190,9 +190,15 @@ function validate_config(builder, config_file) { let wrangler_config; try { - wrangler_config = /** @type {WranglerConfig} */ ( - toml.parse(readFileSync(config_file, 'utf-8')) - ); + if (config_file.endsWith('.json')) { + wrangler_config = /** @type {WranglerConfig} */ ( + JSON.parse(readFileSync(config_file, 'utf-8')) + ); + } else { + wrangler_config = /** @type {WranglerConfig} */ ( + toml.parse(readFileSync(config_file, 'utf-8')) + ); + } } catch (err) { err.message = `Error parsing ${config_file}: ${err.message}`; throw err; From c6e3ffd3fe49aec25db9594839b1a09362f12520 Mon Sep 17 00:00:00 2001 From: linnil1 Date: Wed, 11 Dec 2024 23:18:07 +0800 Subject: [PATCH 2/3] feat: Find the wrangler.json if the default config not found --- .../docs/25-build-and-deploy/70-adapter-cloudflare-workers.md | 2 +- packages/adapter-cloudflare-workers/index.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md index ba04a0808209..e9ab68b4f085 100644 --- a/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md +++ b/documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md @@ -42,7 +42,7 @@ Preferences for the emulated `platform.env` local bindings. See the [getPlatform ## Basic Configuration -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: +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: ```toml /// file: wrangler.toml diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index cd4caaed416d..65bf85d568e8 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -185,6 +185,10 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {}) * @returns {WranglerConfig} */ function validate_config(builder, config_file) { + if (!existsSync(config_file) && config_file === 'wrangler.toml' && existsSync('wrangler.json')) { + builder.log.minor('Default wrangler.toml not existed. Using wrangler.json.'); + config_file = 'wrangler.json'; + } if (existsSync(config_file)) { /** @type {WranglerConfig} */ let wrangler_config; From 45cf6340e4dfcb4a3df9e8eb776c91306b338130 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Thu, 12 Dec 2024 12:06:15 +0800 Subject: [PATCH 3/3] Update packages/adapter-cloudflare-workers/index.js --- packages/adapter-cloudflare-workers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index 65bf85d568e8..02f8c7caff86 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -186,7 +186,7 @@ export default function ({ config = 'wrangler.toml', platformProxy = {} } = {}) */ function validate_config(builder, config_file) { if (!existsSync(config_file) && config_file === 'wrangler.toml' && existsSync('wrangler.json')) { - builder.log.minor('Default wrangler.toml not existed. Using wrangler.json.'); + builder.log.minor('Default wrangler.toml does not exist. Using wrangler.json.'); config_file = 'wrangler.json'; } if (existsSync(config_file)) {