feat: discover Firebase Emulator from FIRESTORE_EMULATOR_HOST env vars - #12
Open
dan-nyanko wants to merge 4 commits into
Open
feat: discover Firebase Emulator from FIRESTORE_EMULATOR_HOST env vars#12dan-nyanko wants to merge 4 commits into
dan-nyanko wants to merge 4 commits into
Conversation
jsdom does not reliably expose localStorage across runtimes (e.g. Node 26's experimental built-in shadows it), causing projectsPersistence/projectsSlice tests to fail with 'localStorage is undefined'. Add a minimal in-memory shim guarded by typeof check so it only applies when absent, keeping behavior identical on environments where jsdom already provides it.
The existing scan only reads the Emulator Hub locator file, which is absent when the emulator is started without the Hub (e.g. firebase emulators:start --only firestore). Add discovery via FIRESTORE_EMULATOR_HOST, FIREBASE_AUTH_EMULATOR_HOST and FIREBASE_STORAGE_EMULATOR_HOST, merged with the hub scan and de-duplicated by Firestore host:port.
…OUD_PROJECT readProjectIdGuess previously only consulted .firebaserc and fell back to the generic 'demo-project'. When connecting to a gcloud Firestore emulator (started with --project <id>), the discovered project id now honors FIRESTORE_EMULATOR_PROJECT or GCLOUD_PROJECT so it matches the emulator's actual project and returns data.
gRPC clients resolve 'localhost' to IPv6 ::1 and can hang/fail to connect to the emulator. Rewrite 'localhost' (and wildcard bind addresses) to 127.0.0.1 in normalizeHost so discovered emulator hosts connect reliably over IPv4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FireStudio now discovers a locally running emulator via the standard Emulator Suite environment variables (
FIRESTORE_EMULATOR_HOST,FIREBASE_AUTH_EMULATOR_HOST,FIREBASE_STORAGE_EMULATOR_HOST), in addition to the existing hub-locator-file scan. This makes discovery work even when the Emulator Hub (port 4400) is not running — e.g.firebase emulators:start --only firestore, or thegcloudFirestore emulator.It also derives the project ID from
FIRESTORE_EMULATOR_PROJECT/GCLOUD_PROJECT, and normalizeslocalhost(and wildcard bind addresses) to127.0.0.1so clients connect reliably over IPv4.Problem
Previously, emulator discovery only read the hub locator file
hub-<projectId>.jsonfromos.tmpdir(), which is only written when the Emulator Hub is up. Consequences:--only firestore, or thegcloudFirestore emulator), the hub file is absent andFIRESTORE_EMULATOR_HOSTwas never picked up — FireStudio reported no running emulator.demo-project, so even when connected, requests targeted the wrong project and returned no data.localhostresolve to IPv6::1for gRPC clients and can hang/fail to connect; only127.0.0.1connects reliably.Fix
In
electron/controllers/emulatorController.js:scanEnv()— discovers emulators from the standard env vars (authoritative signal of a running emulator) and maps them to a normalized emulator descriptor.parseHostPort()/normalizeHost()— parseshost:portand rewriteslocalhostand wildcard bind addresses (0.0.0.0,::,[::],::1) to127.0.0.1, since clients can't reliably connect to a wildcard/::1address as a destination.readProjectIdGuess()— best-effort project ID: checksFIRESTORE_EMULATOR_PROJECT/GCLOUD_PROJECT, then.firebaserc(walking up from cwd), falling back to Firebase's conventionaldemo-projectplaceholder.scanRunningEmulators()— merges the hub-file scan andscanEnv(), de-duplicating by Firestorehost:portso one running emulator isn't reported twice. Exported for reuse.emulators:scanHubIPC handler now callsscanRunningEmulators().Testing / verification
FIRESTORE_EMULATOR_HOST/FIRESTORE_EMULATOR_PROJECT) is discovered with the correct project ID and connects over127.0.0.1, and its collections appear in FireStudio.pnpm run lint,pnpm run format:check,pnpm run typecheck→ all pass (controller is plain JS; formatted by prettier).Notes
localStoragetest-shim fix (fromfix/tests-localstorage-polyfill) so CI tests pass on runtimes where jsdom doesn't exposelocalStorage.