Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support wrangler.json configuration file in adapter-cloudflare-workers #13148

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export default {

### config

Path to your custom `wrangler.toml` config file.
Path to your custom `wrangler.toml` or `wrangler.json` config file.

### platformProxy

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.

## 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
Expand Down
16 changes: 13 additions & 3 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,24 @@ 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 does not exist. Using wrangler.json.');
config_file = 'wrangler.json';
}
if (existsSync(config_file)) {
/** @type {WranglerConfig} */
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;
Expand Down
Loading