Skip to content

Commit 721bff0

Browse files
authored
output more wrangler command logs on errors (#1034)
1 parent 7159f6f commit 721bff0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.changeset/fresh-taxis-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
output more wrangler command logs when the command fails

packages/cloudflare/src/cli/utils/run-wrangler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) {
5656
}
5757

5858
export function runWrangler(options: BuildOptions, args: string[], wranglerOpts: WranglerOptions = {}) {
59+
const shouldPipeLogs = wranglerOpts.logging === "error";
60+
5961
const result = spawnSync(
6062
options.packager,
6163
[
@@ -74,10 +76,9 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts:
7476
],
7577
{
7678
shell: true,
77-
stdio: wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit",
79+
stdio: shouldPipeLogs ? ["ignore", "pipe", "pipe"] : "inherit",
7880
env: {
7981
...process.env,
80-
...(wranglerOpts.logging === "error" ? { WRANGLER_LOG: "error" } : undefined),
8182
// `.env` files are handled by the adapter.
8283
// Wrangler would load `.env.<wrangler env>` while we should load `.env.<process.env.NEXTJS_ENV>`
8384
// See https://opennext.js.org/cloudflare/howtos/env-vars
@@ -87,6 +88,11 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts:
8788
);
8889

8990
if (result.status !== 0) {
91+
if (shouldPipeLogs) {
92+
process.stdout.write(result.stdout.toString());
93+
process.stderr.write(result.stderr.toString());
94+
}
95+
9096
logger.error("Wrangler command failed");
9197
process.exit(1);
9298
}

0 commit comments

Comments
 (0)