@@ -6,6 +6,10 @@ import { normalizeAndValidate } from "../functions/projectConfig";
6
6
import { getProjectAdminSdkConfigOrCached } from "../emulator/adminSdkConfig" ;
7
7
import { needProjectId } from "../projectUtils" ;
8
8
import { FirebaseError } from "../error" ;
9
+ import * as ensureApiEnabled from "../ensureApiEnabled" ;
10
+ import { runtimeconfigOrigin } from "../api" ;
11
+ import * as experiments from "../experiments" ;
12
+ import { getFunctionsConfig } from "../deploy/functions/prepareFunctionsUpload" ;
9
13
10
14
export const command = new Command ( "internaltesting:functions:discover" )
11
15
. description ( "discover function triggers defined in the current project directory" )
@@ -18,9 +22,35 @@ export const command = new Command("internaltesting:functions:discover")
18
22
"Admin SDK config unexpectedly undefined - have you run firebase init?" ,
19
23
) ;
20
24
}
21
- const builds = await loadCodebases ( fnConfig , options , firebaseConfig , {
22
- firebase : firebaseConfig ,
23
- } ) ;
24
- logger . info ( JSON . stringify ( builds , null , 2 ) ) ;
25
- return builds ;
25
+
26
+ let runtimeConfig : Record < string , unknown > = { firebase : firebaseConfig } ;
27
+ const allowFunctionsConfig = experiments . isEnabled ( "dangerouslyAllowFunctionsConfig" ) ;
28
+
29
+ if ( allowFunctionsConfig ) {
30
+ try {
31
+ const runtimeConfigApiEnabled = await ensureApiEnabled . check (
32
+ projectId ,
33
+ runtimeconfigOrigin ( ) ,
34
+ "runtimeconfig" ,
35
+ /* silent=*/ true ,
36
+ ) ;
37
+
38
+ if ( runtimeConfigApiEnabled ) {
39
+ runtimeConfig = { ...runtimeConfig , ...( await getFunctionsConfig ( projectId ) ) } ;
40
+ }
41
+ } catch ( err ) {
42
+ logger . debug ( "Could not check Runtime Config API status, assuming disabled:" , err ) ;
43
+ }
44
+ }
45
+
46
+ const wantBuilds = await loadCodebases (
47
+ fnConfig ,
48
+ options ,
49
+ firebaseConfig ,
50
+ runtimeConfig ,
51
+ undefined , // no filters
52
+ ) ;
53
+
54
+ logger . info ( JSON . stringify ( wantBuilds , null , 2 ) ) ;
55
+ return wantBuilds ;
26
56
} ) ;
0 commit comments