Functions can now declare dependencies on additional APIs#1900
Merged
Conversation
### Description Adds a new user-facing `requiresAPI` function to declare Google Cloud API dependencies in code. These are appended to the wire protocol manifest. ### Scenarios Tested - Unit tests verify that `requiresAPI` correctly populates the `requiredAPIs` field in the generated manifest.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the requiresAPI function to both v1 and v2 SDKs, allowing developers to declare Google Cloud API dependencies directly in their code. These dependencies are collected globally and appended to the manifest during stack loading. The review feedback highlights a critical issue where the global globalRequiredAPIs array is not cleared after stack loading, which can lead to state accumulation and duplicate entries in long-running processes like the Firebase Emulator. Additionally, it is recommended to add input validation to the requiresAPI function to ensure that the API name is a valid, non-empty string.
- Enforced `${string}.googleapis.com` template literal type and runtime validation for `requiresAPI`.
- Cleared global API state after `loadStack` to prevent memory leaks in long running watch processes.
- Added unit tests covering the new validation logic.
wandamora
approved these changes
Jun 11, 2026
Fixes CI unit test failures where global parameter state from previous unit tests leaked into subsequent test expectations.
Fixes edge-case CI test failures where Node.js `require.cache` prevented fixture modules from re-executing and re-populating global parameter and API states when loaded a second time via absolute paths.
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.
Description
Adds a new user-facing
requiresAPIfunction to declare Google Cloud API dependencies in code. These are appended to the wire protocol manifest.Scenarios Tested
requiresAPIcorrectly populates therequiredAPIsfield in the generated manifest.