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

[create-cloudflare] next.js with ts fix #7854

Merged
merged 16 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions .changeset/famous-coats-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-cloudflare": patch
---

# \[create-cloudflare\] next.js with ts fix #7854
beratbayram marked this conversation as resolved.
Show resolved Hide resolved

Removed top-level await in next.config.ts
beratbayram marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 0 additions & 9 deletions .changeset/moody-walls-shake.md

This file was deleted.

57 changes: 12 additions & 45 deletions packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
probePaths,
readFile,
readJSON,
removeFile,
usesEslint,
usesTypescript,
writeFile,
Expand All @@ -32,55 +31,27 @@ const generate = async (ctx: C3Context) => {
updateStatus("Created wrangler.json file");
};

const setupDevPlatformCode =
`import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';

// Here we use the @cloudflare/next-on-pages next-dev module to allow us to
// use bindings during local development (when running the application with \`next dev\`).
// For more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === 'development') {
await setupDevPlatform();
}

`.replace(/\n\t*/g, "\n");

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

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

const configContent = readFile(configFile);

const updatedConfigFile = setupDevPlatformCode + configContent;
const updatedConfigFile =
`import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';

writeFile(configFile, updatedConfigFile);

s.stop(`${brandColor(`Updated`)} ${dim(`\`${configFile}\``)}`);
};
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
// (when running the application with \`next dev\`) and has no effect outside of development, for more information see:
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
setupDevPlatform().catch(console.error);

const updateNextTsConfig = () => {
const s = spinner();
`.replace(/\n\t*/g, "\n") + configContent;

const oldConfigFile = `next.config.ts`;
const newConfigFile = `next.config.mjs`;

s.start(`Removing \`${oldConfigFile}\``);

const updatedConfigFile = setupDevPlatformCode +
`/** @type {import('next').NextConfig} */
const nextConfig = {
/* config options here */
};

export default nextConfig;
`.replace(/\n\t*/g, "\n");

removeFile(oldConfigFile);
writeFile(newConfigFile, updatedConfigFile);
writeFile(configFile, updatedConfigFile);

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

const configure = async (ctx: C3Context) => {
Expand Down Expand Up @@ -116,11 +87,7 @@ const configure = async (ctx: C3Context) => {
await writeEslintrc(ctx);
}

if (usesTs) {
updateNextTsConfig();
} else {
updateNextJsConfig();
}
updateNextConfig(usesTs);

copyFile(
join(getTemplatePath(ctx), "README.md"),
Expand Down
Loading