1- import { readFile , stat , access , constants } from 'node:fs/promises'
1+ import { readFile , access , constants } from 'node:fs/promises'
22import stripJsonComments from 'strip-json-comments'
33import type { ConsolaInstance } from 'consola'
4- import type { VueFireNuxtModuleOptions } from './options'
4+ import type { VueFireNuxtModuleOptionsResolved } from './options'
55
66export async function willUseEmulators (
7- { emulators } : VueFireNuxtModuleOptions ,
7+ { emulators } : VueFireNuxtModuleOptionsResolved ,
88 firebaseJsonPath : string ,
99 logger : ConsolaInstance
1010) : Promise < NonNullable < FirebaseEmulatorsJSON [ 'emulators' ] > | null > {
1111 const isEmulatorEnabled =
12- ( typeof emulators === 'object' ? emulators . enabled : ! ! emulators ) &&
12+ // emulators is always defined
13+ emulators . enabled &&
1314 // Disable emulators on production unless the user explicitly enables them
1415 ( process . env . NODE_ENV !== 'production' || process . env . VUEFIRE_EMULATORS )
1516
@@ -26,10 +27,6 @@ export async function willUseEmulators(
2627 return null
2728 }
2829
29- const fileStats = await stat ( firebaseJsonPath )
30- if ( ! fileStats . isFile ( ) ) {
31- return null
32- }
3330 let firebaseJson : FirebaseEmulatorsJSON | null = null
3431 try {
3532 firebaseJson = JSON . parse (
@@ -54,31 +51,34 @@ export async function willUseEmulators(
5451 * @param logger - The logger instance
5552 */
5653export 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' ] > ,
5959 logger : ConsolaInstance
6060) {
6161 // normalize the emulators option
62- const emulatorsOptions =
63- typeof _emulatorsOptions === 'object'
64- ? _emulatorsOptions
62+ const vuefireEmulatorsOptions =
63+ typeof _vuefireEmulatorsOptions === 'object'
64+ ? _vuefireEmulatorsOptions
6565 : {
66- enabled : _emulatorsOptions ,
66+ enabled : _vuefireEmulatorsOptions ,
6767 }
6868
69- if ( ! emulators ) {
70- if ( emulatorsOptions . enabled !== false ) {
69+ if ( ! firebaseEmulatorsConfig ) {
70+ if ( vuefireEmulatorsOptions . enabled !== false ) {
7171 logger . warn (
7272 'You enabled emulators but there is no `emulators` key in your `firebase.json` file. Emulators will not be enabled.'
7373 )
7474 }
7575 return
7676 }
7777
78- const defaultHost : string = emulatorsOptions . host || '127.0.0.1'
78+ const defaultHost : string = vuefireEmulatorsOptions . host || '127.0.0.1'
7979
8080 const emulatorsToEnable = services . reduce ( ( acc , service ) => {
81- if ( emulators [ service ] ) {
81+ if ( firebaseEmulatorsConfig [ service ] ) {
8282 // these env variables are automatically picked up by the admin SDK too
8383 // https://firebase.google.com/docs/emulator-suite/connect_rtdb?hl=en&authuser=0#admin_sdks
8484 // Also, Firestore is the only one that has a different env variable
@@ -109,7 +109,7 @@ export function detectEmulators(
109109 }
110110
111111 // take the values from the firebase.json file
112- const emulatorsServiceConfig = emulators [ service ]
112+ const emulatorsServiceConfig = firebaseEmulatorsConfig [ service ]
113113 // they might be picked up from the environment variables
114114 host ??= emulatorsServiceConfig ?. host || defaultHost
115115 port ??= emulatorsServiceConfig ?. port
0 commit comments