1
- import { readFile , stat , access , constants } from 'node:fs/promises'
1
+ import { readFile , access , constants } from 'node:fs/promises'
2
2
import stripJsonComments from 'strip-json-comments'
3
3
import type { ConsolaInstance } from 'consola'
4
- import type { VueFireNuxtModuleOptions } from './options'
4
+ import type { VueFireNuxtModuleOptionsResolved } from './options'
5
5
6
6
export async function willUseEmulators (
7
- { emulators } : VueFireNuxtModuleOptions ,
7
+ { emulators } : VueFireNuxtModuleOptionsResolved ,
8
8
firebaseJsonPath : string ,
9
9
logger : ConsolaInstance
10
10
) : Promise < NonNullable < FirebaseEmulatorsJSON [ 'emulators' ] > | null > {
11
11
const isEmulatorEnabled =
12
- ( typeof emulators === 'object' ? emulators . enabled : ! ! emulators ) &&
12
+ // emulators is always defined
13
+ emulators . enabled &&
13
14
// Disable emulators on production unless the user explicitly enables them
14
15
( process . env . NODE_ENV !== 'production' || process . env . VUEFIRE_EMULATORS )
15
16
@@ -26,10 +27,6 @@ export async function willUseEmulators(
26
27
return null
27
28
}
28
29
29
- const fileStats = await stat ( firebaseJsonPath )
30
- if ( ! fileStats . isFile ( ) ) {
31
- return null
32
- }
33
30
let firebaseJson : FirebaseEmulatorsJSON | null = null
34
31
try {
35
32
firebaseJson = JSON . parse (
@@ -54,31 +51,34 @@ export async function willUseEmulators(
54
51
* @param logger - The logger instance
55
52
*/
56
53
export function detectEmulators (
57
- { emulators : _emulatorsOptions , auth } : VueFireNuxtModuleOptions ,
58
- emulators : NonNullable < FirebaseEmulatorsJSON [ 'emulators' ] > ,
54
+ {
55
+ emulators : _vuefireEmulatorsOptions ,
56
+ auth,
57
+ } : VueFireNuxtModuleOptionsResolved ,
58
+ firebaseEmulatorsConfig : NonNullable < FirebaseEmulatorsJSON [ 'emulators' ] > ,
59
59
logger : ConsolaInstance
60
60
) {
61
61
// normalize the emulators option
62
- const emulatorsOptions =
63
- typeof _emulatorsOptions === 'object'
64
- ? _emulatorsOptions
62
+ const vuefireEmulatorsOptions =
63
+ typeof _vuefireEmulatorsOptions === 'object'
64
+ ? _vuefireEmulatorsOptions
65
65
: {
66
- enabled : _emulatorsOptions ,
66
+ enabled : _vuefireEmulatorsOptions ,
67
67
}
68
68
69
- if ( ! emulators ) {
70
- if ( emulatorsOptions . enabled !== false ) {
69
+ if ( ! firebaseEmulatorsConfig ) {
70
+ if ( vuefireEmulatorsOptions . enabled !== false ) {
71
71
logger . warn (
72
72
'You enabled emulators but there is no `emulators` key in your `firebase.json` file. Emulators will not be enabled.'
73
73
)
74
74
}
75
75
return
76
76
}
77
77
78
- const defaultHost : string = emulatorsOptions . host || '127.0.0.1'
78
+ const defaultHost : string = vuefireEmulatorsOptions . host || '127.0.0.1'
79
79
80
80
const emulatorsToEnable = services . reduce ( ( acc , service ) => {
81
- if ( emulators [ service ] ) {
81
+ if ( firebaseEmulatorsConfig [ service ] ) {
82
82
// these env variables are automatically picked up by the admin SDK too
83
83
// https://firebase.google.com/docs/emulator-suite/connect_rtdb?hl=en&authuser=0#admin_sdks
84
84
// Also, Firestore is the only one that has a different env variable
@@ -109,7 +109,7 @@ export function detectEmulators(
109
109
}
110
110
111
111
// take the values from the firebase.json file
112
- const emulatorsServiceConfig = emulators [ service ]
112
+ const emulatorsServiceConfig = firebaseEmulatorsConfig [ service ]
113
113
// they might be picked up from the environment variables
114
114
host ??= emulatorsServiceConfig ?. host || defaultHost
115
115
port ??= emulatorsServiceConfig ?. port
0 commit comments