feature: functions can now declare lifecycle hooks#1915
Open
wandamora wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for post-deployment lifecycle hooks (afterInstall and afterUpdate) by adding a new lifecycle module, updating the manifest stack loader to capture these hooks, and exposing the module exports in package.json. The review feedback highlights a correctness issue in src/runtime/loader.ts where falsy but valid JSON values (such as 0 or false) are incorrectly omitted during serialization, and suggests using TypeScript union types in src/lifecycle/index.ts to enforce mutually exclusive properties at compile-time.
02d17b8 to
9489ef4
Compare
…e falsy body/params in loader
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
This PR adds support for declaring codebase lifecycle hooks in the Firebase Functions SDK. Developers can now register actions (
afterInstallandafterUpdate) that are automatically executed post-deployment.Summary of Changes
1. Hook Registrations (
src/lifecycle/index.ts)firebase-functions/lifecycle:afterInstall(action: LifecycleAction): Registers a hook to run when resources in the codebase are deployed for the first time.afterUpdate(action: LifecycleAction): Registers a hook to run when resources in the codebase are updated.task: Triggers a task queue function with an optional payloadbody.call: Calls a function (callable trigger) with optionalparams.http: Triggers a HTTP endpoint via requesturl/function,method, andbody.afterInstallandafterUpdatecan be registered per codebase at runtime.2. Stack Manifest Parsing (
src/runtime/loader.ts,src/runtime/manifest.ts)ManifestLifecycleActionand updatedManifestStacktypes to include thelifecycleHooksfield.loadStackinsideloader.tsto capture any declared lifecycle hooks from global symbols during function discovery, mapping them into the compiled JSON/wire format returned tofirebase-tools.stackToWireserialization helper to recursively resolve CEL expressions and reset values insidelifecycleHooksproperties.3. Tests
spec/lifecycle/lifecycle.spec.tsto test hook registration and duplicate hook prevention.spec/runtime/loader.spec.tsverifying thatafterInstallandafterUpdatedeclarations are correctly discovered and serialized into theManifestStack.Code sample