You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, adapter-cloudflare-workers(2.6.0) only supports wrangler.toml as the configuration file for Cloudflare Workers. If there is only a wrangler.json file in the project, running npm run build will fail because wrangler.toml does not exist. Even if the adapter is configured as:
adapter: adapter({config: 'wrangler.json'})
It does not work because the file is always read using the TOML format.
However, starting from version v3.91.0, Cloudflare Workers also supports wrangler.json as a configuration format. When using wrangler, it automatically searches for wrangler.json if wrangler.toml is not present in the base directory.
For projects with only a wrangler.json file, users are still forced to convert their JSON configuration to TOML, which is tedious and unnecessary.
Describe the proposed solution
The simplest solution is to check the file extension to support both wrangler.toml and wrangler.json. For example:
diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js
index 8a4f9252d..8bce9848b 100644
--- a/packages/adapter-cloudflare-workers/index.js+++ b/packages/adapter-cloudflare-workers/index.js
function validate_config(builder, config_file) {
let wrangler_config;
try {
+ if (config_file.endsWith(".json")) {+ wrangler_config = 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;
}
// rest of the function
}
Additionally, the adapter could automatically detect wrangler.json if wrangler.toml is not specified in the adapter's options or does not exist. This can be achieved by modifying the logic to include:
function validate_config(builder, config_file) {
+ if (!existsSync(config_file)) {+ config_file = "wrangler.json"+ }
if (existsSync(config_file)) {
Describe the problem
Currently,
adapter-cloudflare-workers
(2.6.0) only supportswrangler.toml
as the configuration file for Cloudflare Workers. If there is only awrangler.json
file in the project, runningnpm run build
will fail becausewrangler.toml
does not exist. Even if the adapter is configured as:It does not work because the file is always read using the TOML format.
However, starting from version
v3.91.0
, Cloudflare Workers also supportswrangler.json
as a configuration format. When usingwrangler
, it automatically searches forwrangler.json
ifwrangler.toml
is not present in the base directory.For projects with only a
wrangler.json
file, users are still forced to convert their JSON configuration to TOML, which is tedious and unnecessary.Describe the proposed solution
The simplest solution is to check the file extension to support both
wrangler.toml
andwrangler.json
. For example:Additionally, the adapter could automatically detect
wrangler.json
ifwrangler.toml
is not specified in the adapter's options or does not exist. This can be achieved by modifying the logic to include:Alternatives considered
No response
Importance
nice to have
Additional Information
The text was updated successfully, but these errors were encountered: