Skip to content

add env variable to specify which downloadable emulator version to use#9960

Open
aalej wants to merge 8 commits intomainfrom
aalej_emulator-version-env
Open

add env variable to specify which downloadable emulator version to use#9960
aalej wants to merge 8 commits intomainfrom
aalej_emulator-version-env

Conversation

@aalej
Copy link
Contributor

@aalej aalej commented Feb 21, 2026

Description

Adds FIREBASE_TOOLS_*_EMULATOR_VERSION which can be used to specify which version of the downloadable emulator to use.

Developers who encounter issues with the latest version of a downloadable emulator will often need to use an older version of firebase tools. For example:

  • firebase-tools 15.6.0 uses version 1.2.3 of emulator X
  • firebase-tools 15.5.0 uses version 1.2.0 of emulator X

If version 1.2.3 has a bug, developers would need to downgrade to firebase-tools 15.5.0 to use emulator X version 1.2.0. They will need to use an older version of firebase-tools until the bug in emulator X is fixed. This env config should give a viable workaround by setting FIREBASE_TOOLS_X_EMULATOR_VERSION=1.2.0

Scenarios Tested

$ export FIREBASE_TOOLS_FIRESTORE_EMULATOR_VERSION=1.19.6
$ export FIREBASE_TOOLS_PUBSUB_EMULATOR_VERSION=0.8.17
$ firebase emulators:start
i  emulators: Starting emulators: firestore, pubsub
⚠  firestore: Env variable override detected. Using custom firestore emulator version 1.19.6.
i  firestore: downloading cloud-firestore-emulator-v1.19.6.jar...
Progress: =========================================================================================================> (100% of 67MB)
i  firestore: Removing outdated emulator files: cloud-firestore-emulator-v1.20.2.jar
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator UI websocket is running on 9150.
⚠  pubsub: Env variable override detected. Using custom pubsub emulator version 0.8.17.
i  pubsub: downloading pubsub-emulator-0.8.17.zip...
Progress: =========================================================================================================> (100% of 66MB)
i  pubsub: Removing outdated emulator files: pubsub-emulator-0.8.27
i  pubsub: Removing outdated emulator files: pubsub-emulator-0.8.27.zip
i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ 127.0.0.1:8080 │ http://127.0.0.1:4000/firestore │
├───────────┼────────────────┼─────────────────────────────────┤
│ Pub/Sub   │ 127.0.0.1:8085 │ n/a                             │
└───────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub host: 127.0.0.1 port: 4400
  Other reserved ports: 4500, 9150

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

The warning message Env variable override detected. Using custom pubsub emulator version 0.8.17. will only appear on the initial download of the emulator. Succeeding emulators:start will no longer show this if the same version is used.

Sample Commands

Notes

the env variable FIREBASE_TOOLS_*_EMULATOR_VERSION may not be the best env variable name? we can change it to something like *_EMULATOR_VERSION if preferred, but I'm not sure if this will conflict with some other envs(ones use by other tools)?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aalej, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Firebase Emulators experience by allowing users to explicitly define which version of a downloadable emulator to use via environment variables. This change provides crucial flexibility, enabling developers to bypass issues with the latest emulator releases without needing to downgrade their entire firebase-tools installation, thus improving stability and developer workflow.

Highlights

  • Emulator Version Overrides: Introduced environment variables (e.g., FIREBASE_TOOLS_FIRESTORE_EMULATOR_VERSION) to allow developers to specify a particular version of a downloadable emulator, providing a workaround for potential bugs in newer versions.
  • Warning Message for Overrides: Added a warning log message when an emulator's version is being overridden by an environment variable, informing the user of the custom version being used.
  • Test Coverage: Added a new test case to ensure that the emulator version override functionality works as expected, verifying that the correct version, download path, and remote URL are used.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CHANGELOG.md
    • Added FIREBASE_TOOLS_*_EMULATOR_VERSION env variables to allow overriding specific versions of downloadable emulators
  • src/emulator/download.ts
    • Added a warning log to indicate when an emulator version is being overridden by an environment variable.
  • src/emulator/downloadableEmulators.spec.ts
    • Added a test case to verify that emulator versions are correctly overridden when the corresponding environment variable is set.
  • src/emulator/downloadableEmulators.ts
    • Defined a map for environment variable names to emulator types.
    • Modified generateDownloadDetails to apply version overrides from environment variables, updating download paths and remote URLs accordingly.
    • Added a new function isVersionOverride to check if an emulator's version is being overridden.
Activity
  • The author aalej created this pull request to address the need for specifying older emulator versions as a workaround for bugs.
  • The PR description clearly outlines the problem, the proposed solution using environment variables, and provides a detailed example of its usage with Firestore and Pub/Sub emulators.
  • The author raised a question regarding the naming convention of the environment variables, suggesting *_EMULATOR_VERSION as an alternative to FIREBASE_TOOLS_*_EMULATOR_VERSION.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable feature allowing developers to override specific downloadable emulator versions using environment variables. This provides a flexible workaround for potential issues with newer emulator versions. The implementation is well-structured, utilizing a dedicated map for environment variable names and correctly handling the skipChecksumAndSize flag when an override is applied. The addition of a comprehensive test case ensures the new functionality works as expected. Overall, this is a well-executed and beneficial change.

@aalej aalej requested a review from joehan February 21, 2026 12:34
const replaceVersion = (s: string) => s.split(oldVersion).join(overrideVersion);

details.version = overrideVersion;
details.downloadPath = replaceVersion(details.downloadPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to have extra error handling for the case where the user sets a version number that doesn't exist in our bucket. Might require some more piping, but ideally, it should print an error message like:

<OVERRIDE_ENV_VAR> set to 99.99.99, but no such version of <emulator name> was found.  Please double check the version number, or unset this environment variable to use the latest default.

const EMULATOR_INSTANCE_KILL_TIMEOUT = 4000; /* ms */

const EMULATOR_VERSION_OVERRIDE_ENV_MAP: { [key: string]: string } = {
database: "FIREBASE_TOOLS_DATABASE_EMULATOR_VERSION",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar concept we use for testing <emulatorName>_EMULATOR_BINARY_PATH - I'd use a similar name here and go with <emulatorName>_EMULATOR_VERSION.

Also, as a nit, we can make this code slightly cleaner as a function like:

function emulatorVersionOverride(emulator: DownloadableEmulators) {
  return process.env[`${emulator.toUpperCase()}_EMULATOR_BINARY_PATH`];
}

Copy link
Member

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks 90% of the way there - thanks for making this change!

@aalej
Copy link
Contributor Author

aalej commented Feb 24, 2026

Thanks for reviewing! Changes applied

  • Replacing FIREBASE_TOOLS_*_EMULATOR_VERSION with *_EMULATOR_VERSION in 4a1d7b3
  • Better error handling in 9bbca9f

When user sets an invalid version like export PUBSUB_EMULATOR_VERSION=4.2.0, an error message would show

$ firebase emulators:start
i  emulators: Starting emulators: firestore, pubsub
⚠  firestore: Env variable override detected. Using custom firestore emulator version 1.19.6.
i  firestore: downloading cloud-firestore-emulator-v1.19.6.jar...
Progress: ===================================================================================================================================================> (100% of 67MB)
i  firestore: Removing outdated emulator files: cloud-firestore-emulator-v1.20.2.jar
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator UI websocket is running on 9150.
⚠  pubsub: Env variable override detected. Using custom pubsub emulator version 4.2.0.
i  pubsub: downloading pubsub-emulator-4.2.0.zip...
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
i  pubsub: Stopping Pub/Sub Emulator
i  hub: Stopping emulator hub

Error: env variable PUBSUB_EMULATOR_VERSION set to 4.2.0, but no such version of pubsub was found. Please double check the version number, or unset this environment variable to use the latest default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants