Skip to content

Commit

Permalink
create a wrangler.json instead of a wrangler.jsonc (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz authored Jan 6, 2025
1 parent 0ee77b2 commit 0c45b0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .changeset/lazy-balloons-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"@opennextjs/cloudflare": patch
---

check and create a `wrangler.jsonc` file for the user in case a `wrangler.(toml|json|jsonc)` file is not already present
check and create a `wrangler.json` file for the user in case a `wrangler.(toml|json|jsonc)` file is not already present

also introduce a new `--skipWranglerConfigCheck` cli flag and a `SKIP_WRANGLER_CONFIG_CHECK`
environment variable that allows users to opt out of the above check (since developers might
Expand Down
11 changes: 7 additions & 4 deletions packages/cloudflare/src/cli/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,16 @@ function ensureCloudflareConfig(config: OpenNextConfig) {
}

/**
* Creates a `wrangler.jsonc` file for the user if a wrangler config file doesn't already exist,
* Creates a `wrangler.json` file for the user if a wrangler config file doesn't already exist,
* but only after asking for the user's confirmation.
*
* If the user refuses a warning is shown (which offers ways to opt out of this check to the user).
*
* Note: we generate a wrangler.json file with comments instead of using the jsonc extension,
* we decided to do that since json is more common than jsonc, wrangler also parses
* them in the same way and we also expect developers to associate `wrangler.json`
* files to the jsonc language
*
* @param projectOpts The options for the project
*/
async function createWranglerConfigIfNotExistent(projectOpts: ProjectOptions): Promise<void> {
Expand All @@ -201,8 +206,6 @@ async function createWranglerConfigIfNotExistent(projectOpts: ProjectOptions): P
return;
}

const wranglerConfigPath = join(projectOpts.sourceDir, "wrangler.jsonc");

const answer = await askConfirmation(
"No `wrangler.(toml|json|jsonc)` config file found, do you want to create one?"
);
Expand Down Expand Up @@ -238,7 +241,7 @@ async function createWranglerConfigIfNotExistent(projectOpts: ProjectOptions): P
);
}

writeFileSync(wranglerConfigPath, wranglerConfigContent);
writeFileSync(join(projectOpts.sourceDir, "wrangler.json"), wranglerConfigContent);
}

function getAppNameFromPackageJson(sourceDir: string): string | undefined {
Expand Down

0 comments on commit 0c45b0b

Please sign in to comment.