@@ -159,16 +159,22 @@ function parseFirebaseConfiguration({target, sourceRewriteMatch, firebaseJsonPat
159
159
throw new Error ( 'Error: Cloud Function name must use only alphanumeric characters and underscores and cannot be longer than 63 characters' ) ;
160
160
}
161
161
162
- // If function, ensure function root-level field is present
163
- if ( ! firebaseConfig ?. functions || ! firebaseConfig . functions ?. source || ! isString ( firebaseConfig . functions . source ) ) {
164
- throw new Error ( 'Error: Required "functions.source" field is missing from Firebase Configuration file.' ) ;
162
+ // If function, ensure function root-level field is present. If functions is an array, gets the first entry
163
+ let functions ;
164
+ if ( firebaseConfig ?. functions ) {
165
+ functions = Array . isArray ( firebaseConfig . functions ) ? firebaseConfig . functions [ 0 ] : firebaseConfig . functions ;
166
+ if ( ! functions || ! isString ( functions . source ) ) {
167
+ throw new Error ( 'Error: Required "functions.source" or "functions[].source" field is missing from Firebase Configuration file.' ) ;
168
+ }
169
+ } else {
170
+ throw new Error ( 'Error: Required "functions" field is missing from Firebase Configuration file.' ) ;
165
171
}
166
172
167
173
return {
168
174
functions : {
169
175
name : rewriteConfig . function ?? rewriteConfig . run . serviceId ,
170
- source : path . join ( path . dirname ( firebaseJson ) , firebaseConfig . functions . source ) ,
171
- runtime : firebaseConfig . functions ?. runtime ,
176
+ source : path . join ( path . dirname ( firebaseJson ) , functions . source ) ,
177
+ runtime : functions ?. runtime ,
172
178
} ,
173
179
publicDir : path . join ( path . dirname ( firebaseJson ) , hostingConfig . public ) ,
174
180
} ;
0 commit comments