Skip to content

Commit

Permalink
Load runtime config when loading triggers in the Functions Emulator (#…
Browse files Browse the repository at this point in the history
…4162)

Addresses #4158.

I've tried to find a way to add a test for this usecase, but there isn't a framework where I can easily hook in a change like this without big investments. I'm leaning towards releasing this bugfix as is, and finding a less urgent time to add regression test.
  • Loading branch information
taeold committed Feb 15, 2022
1 parent c07e9ff commit eca1b4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixes an issue where ext:list was not printing out information about installed Extension instances.
- Fixes issue where Functions Emulator crashed when parsing triggers if accessing functions config values.
14 changes: 13 additions & 1 deletion src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export class FunctionsEmulator implements EmulatorInstance {
if (emulatableBackend.predefinedTriggers) {
triggerDefinitions = emulatedFunctionsByRegion(emulatableBackend.predefinedTriggers);
} else {
const runtimeConfig = this.getRuntimeConfig(emulatableBackend);
const runtimeDelegate = await getRuntimeDelegate({
projectId: this.args.projectId,
projectDir: this.args.projectDir,
Expand All @@ -462,7 +463,7 @@ export class FunctionsEmulator implements EmulatorInstance {
await runtimeDelegate.build();
logger.debug(`Analyzing ${runtimeDelegate.name} backend spec`);
const discoveredBackend = await runtimeDelegate.discoverSpec(
{},
runtimeConfig,
// Don't include user envs when parsing triggers.
{
...this.getSystemEnvs(),
Expand Down Expand Up @@ -871,6 +872,17 @@ export class FunctionsEmulator implements EmulatorInstance {
return process.execPath;
}

getRuntimeConfig(backend: EmulatableBackend): Record<string, string> {
const configPath = `${backend.functionsDir}/.runtimeconfig.json`;
try {
const configContent = fs.readFileSync(configPath, "utf8");
return JSON.parse(configContent.toString());
} catch (e) {
// This is fine - runtime config is optional.
}
return {};
}

getUserEnvs(backend: EmulatableBackend): Record<string, string> {
const projectInfo = {
functionsSource: backend.functionsDir,
Expand Down

0 comments on commit eca1b4d

Please sign in to comment.