From 1fdcc38c873209783cdd27fb09187fec8916c508 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 20 Oct 2025 19:43:25 -0700 Subject: [PATCH 1/2] BREAKING: remove functions.config() implementation Replace functions.config() implementation with an error that provides clear migration guidance to the params module. This removes the deprecated API as planned for the next major release while helping developers migrate. The error message directs users to: https://firebase.google.com/docs/functions/config-env#migrate-config BREAKING CHANGE: functions.config() now throws an error instead of returning configuration values. Migrate to environment parameters using the params module. --- spec/v1/config.spec.ts | 56 ++++++++------------------------------ src/v1/config.ts | 62 ++++++------------------------------------ 2 files changed, 19 insertions(+), 99 deletions(-) diff --git a/spec/v1/config.spec.ts b/spec/v1/config.spec.ts index 97d7b6faa..a5981df0b 100644 --- a/spec/v1/config.spec.ts +++ b/spec/v1/config.spec.ts @@ -21,53 +21,19 @@ // SOFTWARE. import { expect } from "chai"; -import * as fs from "fs"; -import * as process from "process"; -import * as sinon from "sinon"; -import { config, resetCache } from "../../src/v1/config"; +import { config } from "../../src/v1/config"; describe("config()", () => { - let readFileSync: sinon.SinonStub; - let cwdStub: sinon.SinonStub; - - before(() => { - readFileSync = sinon.stub(fs, "readFileSync"); - readFileSync.throws("Unexpected call"); - cwdStub = sinon.stub(process, "cwd"); - cwdStub.returns("/srv"); - }); - - after(() => { - sinon.verifyAndRestore(); - }); - - afterEach(() => { - resetCache(); - delete process.env.FIREBASE_CONFIG; - delete process.env.CLOUD_RUNTIME_CONFIG; - delete process.env.K_CONFIGURATION; - }); - - it("will never load in GCFv2", () => { - const json = JSON.stringify({ - foo: "bar", - firebase: {}, - }); - readFileSync.withArgs("/srv/.runtimeconfig.json").returns(Buffer.from(json)); - - process.env.K_CONFIGURATION = "my-service"; - expect(config).to.throw(Error, /transition to using environment variables/); - }); - - it("loads config values from .runtimeconfig.json", () => { - const json = JSON.stringify({ - foo: "bar", - firebase: {}, - }); - readFileSync.withArgs("/srv/.runtimeconfig.json").returns(Buffer.from(json)); - const loaded = config(); - expect(loaded).to.not.have.property("firebase"); - expect(loaded).to.have.property("foo", "bar"); + it("throws an error with migration guidance", () => { + expect(config).to.throw( + Error, + /functions\.config\(\) has been removed in firebase-functions v7/ + ); + expect(config).to.throw(Error, /migrate to environment parameters using the params module/); + expect(config).to.throw( + Error, + /https:\/\/firebase\.google\.com\/docs\/functions\/config-env#migrate-config/ + ); }); }); diff --git a/src/v1/config.ts b/src/v1/config.ts index 2eafa3150..e034ab0f6 100644 --- a/src/v1/config.ts +++ b/src/v1/config.ts @@ -20,63 +20,17 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import * as fs from "fs"; -import * as path from "path"; - export { firebaseConfig } from "../common/config"; -/** @internal */ -export let singleton: Record; - -/** @internal */ -export function resetCache(): void { - singleton = undefined; -} - /** - * Store and retrieve project configuration data such as third-party API - * keys or other settings. You can set configuration values using the - * Firebase CLI as described in - * https://firebase.google.com/docs/functions/config-env. - * - * @deprecated Using functions.config() is discouraged. See https://firebase.google.com/docs/functions/config-env. + * @deprecated functions.config() has been removed in firebase-functions v7. + * Please migrate to environment parameters using the params module. + * Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config */ export function config(): Record { - // K_CONFIGURATION is only set in GCFv2 - if (process.env.K_CONFIGURATION) { - throw new Error( - "functions.config() is no longer available in Cloud Functions for " + - "Firebase v2. Please see the latest documentation for information " + - "on how to transition to using environment variables" - ); - } - if (typeof singleton === "undefined") { - init(); - } - return singleton; -} - -function init() { - try { - const parsed = JSON.parse(process.env.CLOUD_RUNTIME_CONFIG); - delete parsed.firebase; - singleton = parsed; - return; - } catch (e) { - // Do nothing - } - - try { - const configPath = - process.env.CLOUD_RUNTIME_CONFIG || path.join(process.cwd(), ".runtimeconfig.json"); - const contents = fs.readFileSync(configPath); - const parsed = JSON.parse(contents.toString("utf8")); - delete parsed.firebase; - singleton = parsed; - return; - } catch (e) { - // Do nothing - } - - singleton = {}; + throw new Error( + "functions.config() has been removed in firebase-functions v7. " + + "Please migrate to environment parameters using the params module. " + + "Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config" + ); } From d626911efd8c67e611155acda64b335baf133bdd Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Tue, 21 Oct 2025 14:14:25 -0700 Subject: [PATCH 2/2] Update wording. --- spec/v1/config.spec.ts | 9 +++------ src/v1/config.ts | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/spec/v1/config.spec.ts b/spec/v1/config.spec.ts index a5981df0b..45d51f09c 100644 --- a/spec/v1/config.spec.ts +++ b/spec/v1/config.spec.ts @@ -28,12 +28,9 @@ describe("config()", () => { it("throws an error with migration guidance", () => { expect(config).to.throw( Error, - /functions\.config\(\) has been removed in firebase-functions v7/ - ); - expect(config).to.throw(Error, /migrate to environment parameters using the params module/); - expect(config).to.throw( - Error, - /https:\/\/firebase\.google\.com\/docs\/functions\/config-env#migrate-config/ + "functions.config() has been removed in firebase-functions v7. " + + "Migrate to environment parameters using the params module. " + + "Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config" ); }); }); diff --git a/src/v1/config.ts b/src/v1/config.ts index e034ab0f6..6b1522f33 100644 --- a/src/v1/config.ts +++ b/src/v1/config.ts @@ -23,14 +23,14 @@ export { firebaseConfig } from "../common/config"; /** - * @deprecated functions.config() has been removed in firebase-functions v7. - * Please migrate to environment parameters using the params module. + * @deprecated `functions.config()` has been removed in firebase-functions v7. + * Migrate to environment parameters using the `params` module immediately. * Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config */ export function config(): Record { throw new Error( "functions.config() has been removed in firebase-functions v7. " + - "Please migrate to environment parameters using the params module. " + + "Migrate to environment parameters using the params module. " + "Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config" ); }