@@ -33,44 +33,48 @@ export async function getDeployedFunctions(client: FirebaseClient): Promise<stri
33
33
logger . debug ( "Project ID:" , process . env . PROJECT_ID ) ;
34
34
logger . debug ( "Working directory:" , process . cwd ( ) ) ;
35
35
logger . debug ( "Config file:" , "./firebase.json" ) ;
36
-
36
+
37
37
// Check if PROJECT_ID is set
38
38
if ( ! process . env . PROJECT_ID ) {
39
39
logger . error ( "PROJECT_ID environment variable is not set" ) ;
40
40
return [ ] ;
41
41
}
42
-
42
+
43
43
// Try to list functions with explicit project ID
44
44
const functions = await client . functions . list ( {
45
45
project : process . env . PROJECT_ID ,
46
46
config : "./firebase.json" ,
47
47
nonInteractive : true ,
48
48
cwd : process . cwd ( ) ,
49
49
} ) ;
50
-
50
+
51
51
logger . success ( `Successfully listed functions: ${ functions . length } ` ) ;
52
52
return functions . map ( ( fn : { name : string } ) => fn . name ) ;
53
53
} catch ( error ) {
54
54
logger . warning ( "Could not list functions, assuming none deployed:" , error ) ;
55
-
55
+
56
56
// Provide more detailed error information
57
- if ( error && typeof error === ' object' && ' message' in error ) {
57
+ if ( error && typeof error === " object" && " message" in error ) {
58
58
const errorMessage = String ( error . message ) ;
59
59
logger . debug ( " Error message:" , errorMessage ) ;
60
- if ( ' status' in error ) logger . debug ( " Error status:" , error . status ) ;
61
- if ( ' exit' in error ) logger . debug ( " Error exit code:" , error . exit ) ;
62
-
60
+ if ( " status" in error ) logger . debug ( " Error status:" , error . status ) ;
61
+ if ( " exit" in error ) logger . debug ( " Error exit code:" , error . exit ) ;
62
+
63
63
// Check if it's an authentication error
64
64
if ( errorMessage . includes ( "not logged in" ) || errorMessage . includes ( "authentication" ) ) {
65
- logger . warning ( "This might be an authentication issue. Try running 'firebase login' first." ) ;
65
+ logger . warning (
66
+ "This might be an authentication issue. Try running 'firebase login' first."
67
+ ) ;
66
68
}
67
-
69
+
68
70
// Check if it's a project access error
69
71
if ( errorMessage . includes ( "not found" ) || errorMessage . includes ( "access" ) ) {
70
- logger . warning ( "This might be a project access issue. Check if the project ID is correct and you have access to it." ) ;
72
+ logger . warning (
73
+ "This might be a project access issue. Check if the project ID is correct and you have access to it."
74
+ ) ;
71
75
}
72
76
}
73
-
77
+
74
78
return [ ] ;
75
79
}
76
80
}
@@ -112,9 +116,7 @@ async function deleteFunctionWithRetry(
112
116
retries : MAX_RETRIES ,
113
117
onFailedAttempt : ( error ) => {
114
118
logger . error (
115
- `Failed to delete ${ functionName } (attempt ${ error . attemptNumber } /${
116
- MAX_RETRIES + 1
117
- } ):`,
119
+ `Failed to delete ${ functionName } (attempt ${ error . attemptNumber } /${ MAX_RETRIES + 1 } ):` ,
118
120
error . message
119
121
) ;
120
122
} ,
@@ -179,42 +181,42 @@ export async function deployFunctionsWithRetry(
179
181
logger . deployment ( `Deploying ${ functionsToDeploy . length } functions with rate limiting...` ) ;
180
182
logger . deployment ( `Functions to deploy:` , functionsToDeploy ) ;
181
183
logger . deployment ( `Project ID: ${ process . env . PROJECT_ID } ` ) ;
182
- logger . deployment ( `Region: ${ process . env . REGION || ' us-central1' } ` ) ;
184
+ logger . deployment ( `Region: ${ process . env . REGION || " us-central1" } ` ) ;
183
185
logger . deployment ( `Runtime: ${ process . env . TEST_RUNTIME } ` ) ;
184
-
186
+
185
187
// Pre-deployment checks
186
188
logger . group ( "Pre-deployment checks" ) ;
187
189
logger . debug ( `- Project ID set: ${ ! ! process . env . PROJECT_ID } ` ) ;
188
190
logger . debug ( `- Working directory: ${ process . cwd ( ) } ` ) ;
189
-
191
+
190
192
// Import fs dynamically for ES modules
191
- const fs = await import ( 'fs' ) ;
192
-
193
- logger . debug ( `- Functions directory exists: ${ fs . existsSync ( ' ./functions' ) } ` ) ;
194
- logger . debug ( `- Functions.yaml exists: ${ fs . existsSync ( ' ./functions/functions.yaml' ) } ` ) ;
195
- logger . debug ( `- Package.json exists: ${ fs . existsSync ( ' ./functions/package.json' ) } ` ) ;
196
-
193
+ const fs = await import ( "fs" ) ;
194
+
195
+ logger . debug ( `- Functions directory exists: ${ fs . existsSync ( " ./functions" ) } ` ) ;
196
+ logger . debug ( `- Functions.yaml exists: ${ fs . existsSync ( " ./functions/functions.yaml" ) } ` ) ;
197
+ logger . debug ( `- Package.json exists: ${ fs . existsSync ( " ./functions/package.json" ) } ` ) ;
198
+
197
199
if ( ! process . env . PROJECT_ID ) {
198
200
throw new Error ( "PROJECT_ID environment variable is not set" ) ;
199
201
}
200
-
201
- if ( ! fs . existsSync ( ' ./functions' ) ) {
202
+
203
+ if ( ! fs . existsSync ( " ./functions" ) ) {
202
204
throw new Error ( "Functions directory does not exist" ) ;
203
205
}
204
-
205
- if ( ! fs . existsSync ( ' ./functions/functions.yaml' ) ) {
206
+
207
+ if ( ! fs . existsSync ( " ./functions/functions.yaml" ) ) {
206
208
throw new Error ( "functions.yaml file does not exist in functions directory" ) ;
207
209
}
208
-
210
+
209
211
// Check functions.yaml content
210
212
try {
211
- const functionsYaml = fs . readFileSync ( ' ./functions/functions.yaml' , ' utf8' ) ;
213
+ const functionsYaml = fs . readFileSync ( " ./functions/functions.yaml" , " utf8" ) ;
212
214
logger . debug ( ` - Functions.yaml content preview:` ) ;
213
215
logger . debug ( ` ${ functionsYaml . substring ( 0 , 200 ) } ...` ) ;
214
216
} catch ( error : any ) {
215
217
logger . warning ( ` - Error reading functions.yaml: ${ error . message } ` ) ;
216
218
}
217
-
219
+
218
220
// Set up Firebase project configuration
219
221
logger . debug ( ` - Setting up Firebase project configuration...` ) ;
220
222
process . env . FIREBASE_PROJECT = process . env . PROJECT_ID ;
@@ -241,7 +243,7 @@ export async function deployFunctionsWithRetry(
241
243
logger . deployment ( `Project ID: ${ process . env . PROJECT_ID } ` ) ;
242
244
logger . deployment ( `Working directory: ${ process . cwd ( ) } ` ) ;
243
245
logger . deployment ( `Functions source: ${ process . cwd ( ) } /functions` ) ;
244
-
246
+
245
247
const deployOptions = {
246
248
only : "functions" ,
247
249
force : true ,
@@ -250,9 +252,9 @@ export async function deployFunctionsWithRetry(
250
252
nonInteractive : true ,
251
253
cwd : process . cwd ( ) ,
252
254
} ;
253
-
255
+
254
256
logger . debug ( `Deploy options:` , JSON . stringify ( deployOptions , null , 2 ) ) ;
255
-
257
+
256
258
try {
257
259
await client . deploy ( deployOptions ) ;
258
260
logger . success ( `Deployment command completed successfully` ) ;
@@ -261,13 +263,13 @@ export async function deployFunctionsWithRetry(
261
263
logger . error ( ` Error type: ${ deployError . constructor . name } ` ) ;
262
264
logger . error ( ` Error message: ${ deployError . message } ` ) ;
263
265
logger . error ( ` Error stack: ${ deployError . stack } ` ) ;
264
-
266
+
265
267
// Log all properties of the error object
266
268
logger . debug ( ` Error properties:` ) ;
267
- Object . keys ( deployError ) . forEach ( key => {
269
+ Object . keys ( deployError ) . forEach ( ( key ) => {
268
270
try {
269
271
const value = deployError [ key ] ;
270
- if ( typeof value === ' object' && value !== null ) {
272
+ if ( typeof value === " object" && value !== null ) {
271
273
logger . debug ( ` ${ key } : ${ JSON . stringify ( value , null , 4 ) } ` ) ;
272
274
} else {
273
275
logger . debug ( ` ${ key } : ${ value } ` ) ;
@@ -276,7 +278,7 @@ export async function deployFunctionsWithRetry(
276
278
logger . debug ( ` ${ key } : [Error serializing property]` ) ;
277
279
}
278
280
} ) ;
279
-
281
+
280
282
throw deployError ;
281
283
}
282
284
} ) ;
@@ -287,7 +289,7 @@ export async function deployFunctionsWithRetry(
287
289
logger . error ( `Deployment failed (attempt ${ error . attemptNumber } /${ MAX_RETRIES + 1 } ):` ) ;
288
290
logger . error ( ` Error message: ${ error . message } ` ) ;
289
291
logger . error ( ` Error type: ${ error . constructor . name } ` ) ;
290
-
292
+
291
293
// Log detailed error information during retries
292
294
if ( error . children && error . children . length > 0 ) {
293
295
logger . debug ( "Detailed deployment errors:" ) ;
@@ -304,20 +306,20 @@ export async function deployFunctionsWithRetry(
304
306
}
305
307
} ) ;
306
308
}
307
-
309
+
308
310
// Log the full error structure for debugging
309
311
logger . debug ( "Full error details:" ) ;
310
312
logger . debug ( ` - Message: ${ error . message } ` ) ;
311
313
logger . debug ( ` - Status: ${ error . status } ` ) ;
312
314
logger . debug ( ` - Exit code: ${ error . exit } ` ) ;
313
315
logger . debug ( ` - Attempt: ${ error . attemptNumber } ` ) ;
314
316
logger . debug ( ` - Retries left: ${ error . retriesLeft } ` ) ;
315
-
317
+
316
318
// Log error context if available
317
319
if ( error . context ) {
318
320
logger . debug ( ` - Context: ${ JSON . stringify ( error . context , null , 2 ) } ` ) ;
319
321
}
320
-
322
+
321
323
// Log error body if available
322
324
if ( error . body ) {
323
325
logger . debug ( ` - Body: ${ JSON . stringify ( error . body , null , 2 ) } ` ) ;
@@ -338,7 +340,7 @@ export async function deployFunctionsWithRetry(
338
340
logger . error ( ` Error type: ${ error . constructor . name } ` ) ;
339
341
logger . error ( ` Error message: ${ error . message } ` ) ;
340
342
logger . error ( ` Error stack: ${ error . stack } ` ) ;
341
-
343
+
342
344
// Log detailed error information
343
345
if ( error . children && error . children . length > 0 ) {
344
346
logger . debug ( "Detailed deployment errors:" ) ;
@@ -351,31 +353,31 @@ export async function deployFunctionsWithRetry(
351
353
}
352
354
} ) ;
353
355
}
354
-
356
+
355
357
// Log the full error structure for debugging
356
358
logger . debug ( "Final error details:" ) ;
357
359
logger . debug ( ` - Message: ${ error . message } ` ) ;
358
360
logger . debug ( ` - Status: ${ error . status } ` ) ;
359
361
logger . debug ( ` - Exit code: ${ error . exit } ` ) ;
360
362
logger . debug ( ` - Attempt: ${ error . attemptNumber } ` ) ;
361
363
logger . debug ( ` - Retries left: ${ error . retriesLeft } ` ) ;
362
-
364
+
363
365
// Log error context if available
364
366
if ( error . context ) {
365
367
logger . debug ( ` - Context: ${ JSON . stringify ( error . context , null , 2 ) } ` ) ;
366
368
}
367
-
369
+
368
370
// Log error body if available
369
371
if ( error . body ) {
370
372
logger . debug ( ` - Body: ${ JSON . stringify ( error . body , null , 2 ) } ` ) ;
371
373
}
372
-
374
+
373
375
// Log all error properties
374
376
logger . debug ( ` - All error properties:` ) ;
375
- Object . keys ( error ) . forEach ( key => {
377
+ Object . keys ( error ) . forEach ( ( key ) => {
376
378
try {
377
379
const value = error [ key ] ;
378
- if ( typeof value === ' object' && value !== null ) {
380
+ if ( typeof value === " object" && value !== null ) {
379
381
logger . debug ( ` ${ key } : ${ JSON . stringify ( value , null , 4 ) } ` ) ;
380
382
} else {
381
383
logger . debug ( ` ${ key } : ${ value } ` ) ;
@@ -384,7 +386,7 @@ export async function deployFunctionsWithRetry(
384
386
logger . debug ( ` ${ key } : [Error serializing property]` ) ;
385
387
}
386
388
} ) ;
387
-
389
+
388
390
throw error ;
389
391
}
390
392
}
0 commit comments