@@ -16,12 +16,9 @@ const DEFAULT_NEXT_CONFIG_FILE = "next.config.js";
1616 * Overrides the user's Next Config file (next.config.[ts|js|mjs]) to add configs
1717 * optimized for Firebase App Hosting.
1818 */
19- export async function overrideNextConfig (
20- projectRoot : string ,
21- nextConfigFileName : string ,
22- userNextConfigExists : boolean ,
23- ) {
19+ export async function overrideNextConfig ( projectRoot : string , nextConfigFileName : string ) {
2420 console . log ( `Overriding Next Config to add configs optmized for Firebase App Hosting` ) ;
21+ const userNextConfigExists = await exists ( join ( projectRoot , nextConfigFileName ) ) ;
2522 if ( ! userNextConfigExists ) {
2623 console . log ( `No Next config file found, creating one with Firebase App Hosting overrides` ) ;
2724 try {
@@ -149,25 +146,28 @@ function defaultNextConfigForFAH() {
149146export async function validateNextConfigOverride (
150147 root : string ,
151148 projectRoot : string ,
152- originalConfigFileName : string ,
153- userNextConfigExists : boolean ,
149+ configFileName : string ,
154150) {
151+ const userNextConfigExists = await exists ( join ( projectRoot , configFileName ) ) ;
155152 if ( userNextConfigExists ) {
156153 // Ensure user's existing next config is preserved in a next.config.origin.* file
157- const originalConfigExtension = extname ( originalConfigFileName ) ;
158- const prservedConfigFileName = `next.config.original${ originalConfigExtension } ` ;
159- const preservedConfigFilePath = join ( root , prservedConfigFileName ) ;
154+ const originalConfigExtension = extname ( configFileName ) ;
155+ const preservedConfigFileName = `next.config.original${ originalConfigExtension } ` ;
156+ const preservedConfigFilePath = join ( root , preservedConfigFileName ) ;
160157 if ( ! ( await exists ( preservedConfigFilePath ) ) ) {
161158 throw new Error (
162159 `Next Config Override Failed: User's original Next.js config file not preserved ${ preservedConfigFilePath } ` ,
163160 ) ;
164161 }
165162 }
166163
167- const originalNextConfigFilePath = join ( root , originalConfigFileName ) ;
168- if ( ! ( await exists ( originalNextConfigFilePath ) ) ) {
164+ const configFilePath = join (
165+ root ,
166+ userNextConfigExists ? configFileName : DEFAULT_NEXT_CONFIG_FILE ,
167+ ) ;
168+ if ( ! ( await exists ( configFilePath ) ) ) {
169169 throw new Error (
170- `Next Config Override Failed: Next.js config file not found at ${ originalNextConfigFilePath } ` ,
170+ `Next Config Override Failed: Next.js config file not found at ${ configFilePath } ` ,
171171 ) ;
172172 }
173173
0 commit comments