@@ -15,7 +15,9 @@ import { createOpenNextConfigIfNotExistent, ensureCloudflareConfig } from "../bu
1515export type WithWranglerArgs < T = unknown > = T & {
1616 // Array of arguments that can be given to wrangler commands, including the `--config` and `--env` args.
1717 wranglerArgs : string [ ] ;
18- wranglerConfigPath : string | undefined ;
18+ wranglerConfigPath : string [ ] | undefined ;
19+ // The first wrangler config path passed into the CLI, if any. Assumed to be the one used for OpenNext.
20+ nextjsWranglerConfigPath : string | undefined ;
1921 env : string | undefined ;
2022} ;
2123
@@ -101,7 +103,7 @@ export function getNormalizedOptions(config: OpenNextConfig, buildDir = nextAppD
101103 * @returns Wrangler config.
102104 */
103105export function readWranglerConfig ( args : WithWranglerArgs ) {
104- return unstable_readConfig ( { env : args . env , config : args . wranglerConfigPath } ) ;
106+ return unstable_readConfig ( { env : args . env , config : args . nextjsWranglerConfigPath } ) ;
105107}
106108
107109/**
@@ -111,6 +113,7 @@ export function withWranglerOptions<T extends yargs.Argv>(args: T) {
111113 return args
112114 . option ( "config" , {
113115 type : "string" ,
116+ array : true ,
114117 alias : "c" ,
115118 desc : "Path to Wrangler configuration file" ,
116119 } )
@@ -128,7 +131,7 @@ export function withWranglerOptions<T extends yargs.Argv>(args: T) {
128131
129132type WranglerInputArgs = {
130133 configPath : string | undefined ;
131- config : string | undefined ;
134+ config : string [ ] | undefined ;
132135 env : string | undefined ;
133136} ;
134137
@@ -143,15 +146,15 @@ function getWranglerArgs(args: WranglerInputArgs & { _: (string | number)[] }):
143146
144147 if ( args . config ) {
145148 logger . error (
146- "Multiple config flags found. Please use the `--config` flag for your Wrangler config path."
149+ "Duplicate config flags found. Unable to pass both `--config` and `--configPath` . Please use the `--config` flag for your Wrangler config path."
147150 ) ;
148151 process . exit ( 1 ) ;
149152 }
150153 }
151154
152155 return [
153156 ...( args . configPath ? [ "--config" , args . configPath ] : [ ] ) ,
154- ...( args . config ? [ "--config" , args . config ] : [ ] ) ,
157+ ...( args . config ? args . config . flatMap ( ( c ) => [ "--config" , c ] ) : [ ] ) ,
155158 ...( args . env ? [ "--env" , args . env ] : [ ] ) ,
156159 // Note: the first args in `_` will be the commands.
157160 ...args . _ . slice ( args . _ [ 0 ] === "populateCache" ? 2 : 1 ) . map ( ( a ) => `${ a } ` ) ,
@@ -166,9 +169,15 @@ function getWranglerArgs(args: WranglerInputArgs & { _: (string | number)[] }):
166169export function withWranglerPassthroughArgs < T extends yargs . ArgumentsCamelCase < WranglerInputArgs > > (
167170 args : T
168171) : WithWranglerArgs < T > {
172+ const wranglerConfigPath = args . config ?? ( args . configPath ? [ args . configPath ] : undefined ) ;
173+ if ( wranglerConfigPath && wranglerConfigPath ?. length > 1 ) {
174+ logger . info ( "Multiple Wrangler config paths found, first config assumed as opennext config." ) ;
175+ }
176+
169177 return {
170178 ...args ,
171- wranglerConfigPath : args . config ?? args . configPath ,
179+ wranglerConfigPath,
180+ nextjsWranglerConfigPath : wranglerConfigPath ?. [ 0 ] ,
172181 wranglerArgs : getWranglerArgs ( args ) ,
173182 } ;
174183}
0 commit comments