Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/moody-carrots-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

use the Cloudflare maintained Next.js template
43 changes: 13 additions & 30 deletions packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
import { brandColor, dim } from "@cloudflare/cli/colors";
import { spinner } from "@cloudflare/cli/interactive";
import { brandColor } from "@cloudflare/cli/colors";
import { runFrameworkGenerator } from "frameworks/index";
import { readFile, usesTypescript, writeFile } from "helpers/files";
import { installPackages } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";

const generate = async (ctx: C3Context) => {
await runFrameworkGenerator(ctx, [ctx.project.name]);
await runFrameworkGenerator(ctx, [
ctx.project.name,
"--skip-install",
// We are using the Cloudflare template for Next.js projects
// This is a template maintained by Cloudflare that based on a standard Next.js starter project,
// and has already been configured to work with Cloudflare Workers
"--example",
"https://github.com/cloudflare/templates/tree/main/next-starter-template",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving the template to the OpenNext repo instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely an option. The question is who will maintain it?
If we put it in OpenNext will it be kept up to date (at least more than than the Cloudflare templates repo)?
If there is no capacity to maintain it in Open Next then at least there is a team that is supposed to be on the hook to maintain the templates repo. I am told that this is a template they do intend to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are 2 things to take into consideration here:

  1. impact on maintenance
  2. impact on the users

About the maintenance:

I have never been in contact with that team which is not a positive signal ("not positive" != negative). I just opened the template and see that for ex it doesn't configure binding access in the next config (i.e. calling initOpenNextCloudflareForDev).

Second question is what would framework support be split across different teams?

Last question is how to test changes in the template. It's pretty easy to do that today with a local build of c3. What about moving the template to another repo (either the templates or the open next repo).

Impact on users:

With the current template, users can create a Next app at any Next version as long as it is supported by the adapter (latest 14 minor and any 15 as of today).

The proposed template used a fixed version of Next.

Probably not a huge deal to instantiate 14 or 15 but I can foresee that it becomes a problem when 16 is supported. Implementing the Adapters API will probably imply a different template.

]);
};

const configure = async (ctx: C3Context) => {
const configure = async () => {
// Although the template is pre-configured for Cloudflare Workers,
// we still need to install the latest minor of the OpenNext Cloudflare adapter package.
await installPackages(["@opennextjs/cloudflare@^1.3.0"], {
startText: "Adding the Cloudflare adapter",
doneText: `${brandColor(`installed`)} @opennextjs/cloudflare)}`,
});

const usesTs = usesTypescript(ctx);

updateNextConfig(usesTs);
};

const updateNextConfig = (usesTs: boolean) => {
const s = spinner();

const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
s.start(`Updating \`${configFile}\``);

const configContent = readFile(configFile);

const updatedConfigFile =
configContent +
`
// added by create cloudflare to enable calling \`getCloudflareContext()\` in \`next dev\`
import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';
initOpenNextCloudflareForDev();
`.replace(/\n\t*/g, "\n");

writeFile(configFile, updatedConfigFile);

s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
};

const envInterfaceName = "CloudflareEnv";
Expand Down
Loading