diff --git a/CHANGELOG.md b/CHANGELOG.md index c34f3d920f9..9effcb8b088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ - Fixes bug where passing `--port` flag in `functions:shell` does not set which port to emulate functions (#5521) - Improve error message during deploy when given invalid hosting rewrite rule (#5533) - Generate ESM-compatible SSR function for web frameworks (#5540) +- Fix bug emulators:exec script didn't populate FIREBASE_CONFIG environment variable (#5544) diff --git a/src/emulator/commandUtils.ts b/src/emulator/commandUtils.ts index 1bea0bc62b7..bba72c808d2 100644 --- a/src/emulator/commandUtils.ts +++ b/src/emulator/commandUtils.ts @@ -329,6 +329,18 @@ async function runScript(script: string, extraEnv: Record): Prom utils.logBullet(`Running script: ${clc.bold(script)}`); const env: NodeJS.ProcessEnv = { ...process.env, ...extraEnv }; + // Hyrum's Law strikes here: + // Scripts that imported older versions of Firebase Functions SDK accidentally made + // the FIREBASE_CONFIG environment variable always available to the script. + // Many users ended up depending on this behavior, so we conditionally inject the env var + // if the FIREBASE_CONFIG env var isn't explicitly set in the parent process. + if (env.GCLOUD_PROJECT && !env.FIREBASE_CONFIG) { + env.FIREBASE_CONFIG = JSON.stringify({ + projectId: env.GCLOUD_PROJECT, + storageBucket: `${env.GCLOUD_PROJECT}.appspot.com`, + databaseURL: `https://${env.GCLOUD_PROJECT}.firebaseio.com`, + }); + } const emulatorInfos = EmulatorRegistry.listRunningWithInfo(); setEnvVarsForEmulators(env, emulatorInfos); @@ -448,7 +460,7 @@ const JAVA_HINT = "Please make sure Java is installed and on your system PATH."; /** * Return whether Java major verion is supported. Throws if Java not available. * - * @returns Java major version (for Java >= 9) or -1 otherwise + * @return Java major version (for Java >= 9) or -1 otherwise */ export async function checkJavaMajorVersion(): Promise { return new Promise((resolve, reject) => { @@ -510,7 +522,7 @@ export async function checkJavaMajorVersion(): Promise { }); }).then((output) => { let versionInt = -1; - const match = output.match(JAVA_VERSION_REGEX); + const match = JAVA_VERSION_REGEX.exec(output); if (match) { const version = match[1]; versionInt = parseInt(version, 10);