From 7c0ed9e3d9bdaf5a8801f85bdb00054ec00b943c Mon Sep 17 00:00:00 2001 From: James Date: Sat, 6 Dec 2025 13:35:12 +0000 Subject: [PATCH 1/3] output more wrangler command logs in debug mode --- .changeset/fresh-taxis-pay.md | 5 +++ .../cloudflare/src/cli/utils/run-wrangler.ts | 33 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 .changeset/fresh-taxis-pay.md diff --git a/.changeset/fresh-taxis-pay.md b/.changeset/fresh-taxis-pay.md new file mode 100644 index 000000000..28e142b82 --- /dev/null +++ b/.changeset/fresh-taxis-pay.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +output more wrangler command logs in debug mode diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index 7371e3bd3..3f1eea36c 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -56,7 +56,7 @@ function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) { } export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: WranglerOptions = {}) { - const result = spawnSync( + const spawnArgs = [ options.packager, [ options.packager === "bun" ? "x" : "exec", @@ -72,19 +72,24 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: ].filter((v): v is string => !!v) ), ], - { - shell: true, - stdio: wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit", - env: { - ...process.env, - ...(wranglerOpts.logging === "error" ? { WRANGLER_LOG: "error" } : undefined), - // `.env` files are handled by the adapter. - // Wrangler would load `.env.` while we should load `.env.` - // See https://opennext.js.org/cloudflare/howtos/env-vars - CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: "false", - }, - } - ); + ] as const; + + // ensure the logs are on a new line so they don't get appended to tqdm progress bars + if (options.debug) console.log(); + logger.debug(`Running wrangler command: ${spawnArgs.flat().join(" ")}`); + + const result = spawnSync(...spawnArgs, { + shell: true, + stdio: !options.debug && wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit", + env: { + ...process.env, + ...(!options.debug && wranglerOpts.logging === "error" ? { WRANGLER_LOG: "error" } : undefined), + // `.env` files are handled by the adapter. + // Wrangler would load `.env.` while we should load `.env.` + // See https://opennext.js.org/cloudflare/howtos/env-vars + CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: "false", + }, + }); if (result.status !== 0) { logger.error("Wrangler command failed"); From 8ae9f9ee5177a0f574eeb068bed70eb3e5c81253 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 6 Dec 2025 16:54:36 +0000 Subject: [PATCH 2/3] pipe and output on error --- .../cloudflare/src/cli/utils/run-wrangler.ts | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/cloudflare/src/cli/utils/run-wrangler.ts b/packages/cloudflare/src/cli/utils/run-wrangler.ts index 3f1eea36c..226ea50b7 100644 --- a/packages/cloudflare/src/cli/utils/run-wrangler.ts +++ b/packages/cloudflare/src/cli/utils/run-wrangler.ts @@ -56,7 +56,9 @@ function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) { } export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: WranglerOptions = {}) { - const spawnArgs = [ + const shouldPipeLogs = wranglerOpts.logging === "error"; + + const result = spawnSync( options.packager, [ options.packager === "bun" ? "x" : "exec", @@ -72,26 +74,25 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: ].filter((v): v is string => !!v) ), ], - ] as const; - - // ensure the logs are on a new line so they don't get appended to tqdm progress bars - if (options.debug) console.log(); - logger.debug(`Running wrangler command: ${spawnArgs.flat().join(" ")}`); - - const result = spawnSync(...spawnArgs, { - shell: true, - stdio: !options.debug && wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit", - env: { - ...process.env, - ...(!options.debug && wranglerOpts.logging === "error" ? { WRANGLER_LOG: "error" } : undefined), - // `.env` files are handled by the adapter. - // Wrangler would load `.env.` while we should load `.env.` - // See https://opennext.js.org/cloudflare/howtos/env-vars - CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: "false", - }, - }); + { + shell: true, + stdio: shouldPipeLogs ? ["ignore", "pipe", "pipe"] : "inherit", + env: { + ...process.env, + // `.env` files are handled by the adapter. + // Wrangler would load `.env.` while we should load `.env.` + // See https://opennext.js.org/cloudflare/howtos/env-vars + CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV: "false", + }, + } + ); if (result.status !== 0) { + if (shouldPipeLogs) { + process.stdout.write(result.stdout.toString()); + process.stderr.write(result.stderr.toString()); + } + logger.error("Wrangler command failed"); process.exit(1); } From 17e913ec19943d20d62058d40ea07162f7a9dbfb Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 7 Dec 2025 10:17:24 +0100 Subject: [PATCH 3/3] Apply suggestion from @vicb --- .changeset/fresh-taxis-pay.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fresh-taxis-pay.md b/.changeset/fresh-taxis-pay.md index 28e142b82..2341b93dd 100644 --- a/.changeset/fresh-taxis-pay.md +++ b/.changeset/fresh-taxis-pay.md @@ -2,4 +2,4 @@ "@opennextjs/cloudflare": patch --- -output more wrangler command logs in debug mode +output more wrangler command logs when the command fails