UNPKG

firebase-functions

Version:
72 lines (70 loc) 2.47 kB
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js'); //#region src/lifecycle/index.ts var lifecycle_exports = /* @__PURE__ */ require_rolldown_runtime.__export({ afterFirstDeploy: () => afterFirstDeploy, afterRedeploy: () => afterRedeploy, clearDeclaredLifecycleHooks: () => clearDeclaredLifecycleHooks, declaredLifecycleHooks: () => declaredLifecycleHooks }); /** * Use a global singleton to manage the list of declared lifecycle hooks. * * This ensures that lifecycle hooks are shared between CJS and ESM builds, * avoiding the "dual-package hazard" where the src/bin/firebase-functions.ts (CJS) sees * an empty list while the user's code (ESM) populates a different list. */ const majorVersion = typeof "0" !== "undefined" ? "0" : "0"; const GLOBAL_SYMBOL = Symbol.for(`firebase-functions:lifecycle:declaredHooks:v${majorVersion}`); const globalSymbols = globalThis; if (!globalSymbols[GLOBAL_SYMBOL]) { globalSymbols[GLOBAL_SYMBOL] = {}; } /** * Singleton dictionary of declared lifecycle hooks. * @internal */ const declaredLifecycleHooks = globalSymbols[GLOBAL_SYMBOL]; /** * Registers an action to be executed automatically post-deployment when resources in this codebase * are deployed for the first time. * * @param action The lifecycle action to execute. */ function afterFirstDeploy(action) { if (declaredLifecycleHooks.afterFirstDeploy) { throw new Error("Only one afterFirstDeploy lifecycle hook is allowed per codebase."); } declaredLifecycleHooks.afterFirstDeploy = action; } /** * Registers an action to be executed automatically post-deployment when resources in this codebase * are updated. * * @param action The lifecycle action to execute. */ function afterRedeploy(action) { if (declaredLifecycleHooks.afterRedeploy) { throw new Error("Only one afterRedeploy lifecycle hook is allowed per codebase."); } declaredLifecycleHooks.afterRedeploy = action; } /** * Helper to clear declared lifecycle hooks. * @internal */ function clearDeclaredLifecycleHooks() { for (const key of Object.keys(declaredLifecycleHooks)) { delete declaredLifecycleHooks[key]; } } //#endregion exports.afterFirstDeploy = afterFirstDeploy; exports.afterRedeploy = afterRedeploy; exports.clearDeclaredLifecycleHooks = clearDeclaredLifecycleHooks; exports.declaredLifecycleHooks = declaredLifecycleHooks; Object.defineProperty(exports, 'lifecycle_exports', { enumerable: true, get: function () { return lifecycle_exports; } });