@@ -56,7 +56,9 @@ function injectPassthroughFlagForArgs(options: BuildOptions, args: string[]) {
5656}
5757
5858export function runWrangler ( options : BuildOptions , args : string [ ] , wranglerOpts : WranglerOptions = { } ) {
59- const spawnArgs = [
59+ const shouldPipeLogs = wranglerOpts . logging === "error" ;
60+
61+ const result = spawnSync (
6062 options . packager ,
6163 [
6264 options . packager === "bun" ? "x" : "exec" ,
@@ -72,26 +74,25 @@ export function runWrangler(options: BuildOptions, args: string[], wranglerOpts:
7274 ] . filter ( ( v ) : v is string => ! ! v )
7375 ) ,
7476 ] ,
75- ] as const ;
76-
77- // ensure the logs are on a new line so they don't get appended to tqdm progress bars
78- if ( options . debug ) console . log ( ) ;
79- logger . debug ( `Running wrangler command: ${ spawnArgs . flat ( ) . join ( " " ) } ` ) ;
80-
81- const result = spawnSync ( ...spawnArgs , {
82- shell : true ,
83- stdio : ! options . debug && wranglerOpts . logging === "error" ? [ "ignore" , "ignore" , "inherit" ] : "inherit" ,
84- env : {
85- ...process . env ,
86- ...( ! options . debug && wranglerOpts . logging === "error" ? { WRANGLER_LOG : "error" } : undefined ) ,
87- // `.env` files are handled by the adapter.
88- // Wrangler would load `.env.<wrangler env>` while we should load `.env.<process.env.NEXTJS_ENV>`
89- // See https://opennext.js.org/cloudflare/howtos/env-vars
90- CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV : "false" ,
91- } ,
92- } ) ;
77+ {
78+ shell : true ,
79+ stdio : shouldPipeLogs ? [ "ignore" , "pipe" , "pipe" ] : "inherit" ,
80+ env : {
81+ ...process . env ,
82+ // `.env` files are handled by the adapter.
83+ // Wrangler would load `.env.<wrangler env>` while we should load `.env.<process.env.NEXTJS_ENV>`
84+ // See https://opennext.js.org/cloudflare/howtos/env-vars
85+ CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV : "false" ,
86+ } ,
87+ }
88+ ) ;
9389
9490 if ( result . status !== 0 ) {
91+ if ( shouldPipeLogs ) {
92+ process . stdout . write ( result . stdout . toString ( ) ) ;
93+ process . stderr . write ( result . stderr . toString ( ) ) ;
94+ }
95+
9596 logger . error ( "Wrangler command failed" ) ;
9697 process . exit ( 1 ) ;
9798 }
0 commit comments