From 4b2242e28b9a3d0c7fa16b0405b5a989b79ed893 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 11 May 2022 09:44:20 -0700 Subject: [PATCH] Provide runtime config in Node discovery (#4541) * Provide runtime config in Node discovery * Changelog --- CHANGELOG.md | 1 + src/deploy/functions/runtimes/node/index.ts | 26 ++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9fe90ececf..a3e68cf6045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ +- Fix bug where functions failed to deploy if Runtime Config is accessed at global scope (#4541) - Updates [firebase-frameworks](https://github.com/FirebaseExtended/firebase-framework-tools) to 0.4.2 addressing several issues with the web frameworks integration. - Adds `hosting.source` to configuration schema as an allowed property. diff --git a/src/deploy/functions/runtimes/node/index.ts b/src/deploy/functions/runtimes/node/index.ts index df5165da412..d6ccefdb753 100644 --- a/src/deploy/functions/runtimes/node/index.ts +++ b/src/deploy/functions/runtimes/node/index.ts @@ -92,15 +92,23 @@ export class Delegate { return Promise.resolve(() => Promise.resolve()); } - serve(port: number, envs: backend.EnvironmentVariables): Promise<() => Promise> { + serve( + port: number, + config: backend.RuntimeConfigValues, + envs: backend.EnvironmentVariables + ): Promise<() => Promise> { + const env: Record = { + ...envs, + PORT: port.toString(), + FUNCTIONS_CONTROL_API: "true", + HOME: process.env.HOME, + PATH: process.env.PATH, + }; + if (Object.keys(config || {}).length) { + env.CLOUD_RUNTIME_CONFIG = JSON.stringify(config); + } const childProcess = spawn("./node_modules/.bin/firebase-functions", [this.sourceDir], { - env: { - ...envs, - PORT: port.toString(), - FUNCTIONS_CONTROL_API: "true", - HOME: process.env.HOME, - PATH: process.env.PATH, - }, + env, cwd: this.sourceDir, stdio: [/* stdin=*/ "ignore", /* stdout=*/ "pipe", /* stderr=*/ "inherit"], }); @@ -157,7 +165,7 @@ export class Delegate { if (!discovered) { const getPort = promisify(portfinder.getPort) as () => Promise; const port = await getPort(); - const kill = await this.serve(port, env); + const kill = await this.serve(port, config, env); try { discovered = await discovery.detectFromPort(port, this.projectId, this.runtime); } finally {