Skip to content

Commit

Permalink
fix(create-cloudflare): Fix regression in C3's next template
Browse files Browse the repository at this point in the history
[#7676](#7676)
switched C3 templates to default to `wrangler.json` instead
of `wrangler.toml`. Unfortunately, this unintendedly broke
the `next` template, which was still attempting to read
`wrangler.toml` specifically.

This commit fixes the regression.

Fixes #7770
  • Loading branch information
CarmenPopoviciu committed Jan 15, 2025
1 parent dceb196 commit ac0b555
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
9 changes: 9 additions & 0 deletions .changeset/chilly-kings-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"create-cloudflare": patch
---

Fix regression in C3's `next` template

[#7676](https://github.com/cloudflare/workers-sdk/pull/7676) switched C3 templates to default to `wrangler.json` instead of `wrangler.toml`. Unfortunately, this unintendedly broke the `next` template, which was still attempting to read `wrangler.toml` specifically. This commit fixes the regression.

Fixes #7770
1 change: 0 additions & 1 deletion packages/create-cloudflare/e2e-tests/frameworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ function getFrameworkTests(opts: {
},
],
testCommitMessage: true,
quarantine: true,
verifyBuildCfTypes: {
outputFile: "env.d.ts",
envInterfaceName: "CloudflareEnv",
Expand Down
5 changes: 2 additions & 3 deletions packages/create-cloudflare/templates/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ In order to enable the example:
// KV Example:
```
and uncomment the commented lines below it (also uncomment the relevant imports).
- Do the same in the `wrangler.toml` file, where
the comment is:
- In the `wrangler.json` file add the following configuration line:
```
# KV Example:
"kv_namespaces": [{ "binding": "MY_KV_NAMESPACE", "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }],
```
- If you're using TypeScript run the `cf-typegen` script to update the `env.d.ts` file:
```bash
Expand Down
24 changes: 3 additions & 21 deletions packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,9 @@ const generate = async (ctx: C3Context) => {

await runFrameworkGenerator(ctx, [projectName]);

const wranglerToml = readFile(join(getTemplatePath(ctx), "wrangler.toml"));

// Note: here we add `# KV Example:` to the toml file for the KV example, we don't actually
// include the comment in the template wrangler.toml file just so to keep it identical
// and consistent with that of all the other frameworks
// (instead of making it a special case which needs extra care)
const newTomlContent = wranglerToml.replace(
/#\s+\[\[kv_namespaces\]\]\n#\s+binding\s+=\s+"MY_KV_NAMESPACE"\n#\s+id\s+=\s+"[a-zA-Z0-9]+?"/,
($1) => `# KV Example:\n${$1}`,
);

if (!/# KV Example/.test(newTomlContent)) {
// This should never happen to users, it is a check mostly so that
// if the toml file is changed in a way that breaks the "KV Example" addition
// the C3 Next.js e2e runs will fail with this
throw new Error("Failed to properly generate the wrangler.toml file");
}

writeFile(join(ctx.project.path, "wrangler.toml"), newTomlContent);

updateStatus("Created wrangler.toml file");
const wranglerConfig = readFile(join(getTemplatePath(ctx), "wrangler.json"));
writeFile(join(ctx.project.path, "wrangler.json"), wranglerConfig);
updateStatus("Created wrangler.json file");
};

const updateNextConfig = (usesTs: boolean) => {
Expand Down

0 comments on commit ac0b555

Please sign in to comment.