From 698f7ce9321a5a2984af9472eb53384611f88a68 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 13 Oct 2025 18:53:20 +0200 Subject: [PATCH] refactor: do not create a wrangler config when a custom one is passed --- .changeset/thick-seas-walk.md | 5 +++++ packages/cloudflare/src/cli/build/build.ts | 5 ----- packages/cloudflare/src/cli/commands/build.ts | 17 +++++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 .changeset/thick-seas-walk.md diff --git a/.changeset/thick-seas-walk.md b/.changeset/thick-seas-walk.md new file mode 100644 index 000000000..22e8e079f --- /dev/null +++ b/.changeset/thick-seas-walk.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +refactor: do not create a wrangler config when a custom one is passed diff --git a/packages/cloudflare/src/cli/build/build.ts b/packages/cloudflare/src/cli/build/build.ts index 9ed43e72b..faa8ed5f1 100644 --- a/packages/cloudflare/src/cli/build/build.ts +++ b/packages/cloudflare/src/cli/build/build.ts @@ -17,7 +17,6 @@ import { compileInit } from "./open-next/compile-init.js"; import { compileSkewProtection } from "./open-next/compile-skew-protection.js"; import { compileDurableObjects } from "./open-next/compileDurableObjects.js"; import { createServerBundle } from "./open-next/createServerBundle.js"; -import { createWranglerConfigIfNotExistent } from "./utils/index.js"; import { getVersion } from "./utils/version.js"; /** @@ -87,10 +86,6 @@ export async function build( await bundleServer(options, projectOpts); - if (!projectOpts.skipWranglerConfigCheck) { - await createWranglerConfigIfNotExistent(projectOpts); - } - logger.info("OpenNext build complete."); } diff --git a/packages/cloudflare/src/cli/commands/build.ts b/packages/cloudflare/src/cli/commands/build.ts index 4b8dea6b9..9da954dbd 100644 --- a/packages/cloudflare/src/cli/commands/build.ts +++ b/packages/cloudflare/src/cli/commands/build.ts @@ -1,6 +1,7 @@ import type yargs from "yargs"; import { build as buildImpl } from "../build/build.js"; +import { createWranglerConfigIfNotExistent } from "../build/utils/index.js"; import type { WithWranglerArgs } from "./utils.js"; import { compileConfig, @@ -30,14 +31,18 @@ async function buildCommand( const { config, buildDir } = await compileConfig(args.openNextConfigPath); const options = getNormalizedOptions(config, buildDir); + const projectOpts = { ...args, minify: !args.noMinify, sourceDir: nextAppDir }; + + // Ask whether a `wrangler.jsonc` should be created when no config file exists. + // Note: We don't ask when a custom config file is specified via `--config` + // nor when `--skipWranglerConfigCheck` is used. + if (!projectOpts.wranglerConfigPath && !args.skipWranglerConfigCheck) { + await createWranglerConfigIfNotExistent(projectOpts); + } + const wranglerConfig = readWranglerConfig(args); - await buildImpl( - options, - config, - { ...args, minify: !args.noMinify, sourceDir: nextAppDir }, - wranglerConfig - ); + await buildImpl(options, config, projectOpts, wranglerConfig); } /**