Skip to content

Commit

Permalink
Merge b258727 into 9dc5400
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern committed Jul 23, 2019
2 parents 9dc5400 + b258727 commit 0058024
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion changelog.txt
Expand Up @@ -2,4 +2,5 @@
* Allows emulated Cloud Functions to talk to production RTDB/Firestore if the emulators are not running.
* Fixes an issue where internal logs would sometimes appear in stdout.
* Improves RTDB emulator support for JWT algorithms and arbitrary Google Cloud auth tokens.
* Fixes an issue where functions:shell logs could be double escaped.
* Fixes an issue where functions:shell logs could be double escaped.
* Fixes an issue with false noisy logging about emulators not running.
26 changes: 15 additions & 11 deletions src/emulator/functionsEmulator.ts
Expand Up @@ -410,7 +410,6 @@ You can probably fix this by running "npm install ${
}

readonly projectId: string = "";
readonly bundleTemplate: FunctionsRuntimeBundle;
nodeBinary: string = "";

private server?: http.Server;
Expand All @@ -427,14 +426,6 @@ You can probably fix this by running "npm install ${
this.options.config.get("functions.source")
);

this.bundleTemplate = {
cwd: this.functionsDir,
projectId: this.projectId,
triggerId: "",
ports: {},
disabled_features: this.args.disabledRuntimeFeatures,
};

// TODO: Would prefer not to have static state but here we are!
EmulatorLogger.verbosity = this.args.quiet ? Verbosity.QUIET : Verbosity.DEBUG;
}
Expand All @@ -446,7 +437,7 @@ You can probably fix this by running "npm install ${
this.firebaseConfig = await functionsConfig.getFirebaseConfig(this.options);

const { host, port } = this.getInfo();
this.server = FunctionsEmulator.createHubServer(this.bundleTemplate, this.nodeBinary).listen(
this.server = FunctionsEmulator.createHubServer(this.getBaseBundle(), this.nodeBinary).listen(
port,
host
);
Expand Down Expand Up @@ -479,7 +470,7 @@ You can probably fix this by running "npm install ${
A "diagnostic" FunctionsRuntimeBundle looks just like a normal bundle except functionId == "".
*/
const runtime = InvokeRuntime(this.nodeBinary, this.bundleTemplate);
const runtime = InvokeRuntime(this.nodeBinary, this.getBaseBundle());

runtime.events.on("log", (el: EmulatorLog) => {
FunctionsEmulator.handleRuntimeLog(el);
Expand Down Expand Up @@ -698,6 +689,19 @@ You can probably fix this by running "npm install ${
return this.triggers;
}

getBaseBundle(): FunctionsRuntimeBundle {
return {
cwd: this.functionsDir,
projectId: this.projectId,
triggerId: "",
ports: {
firestore: EmulatorRegistry.getPort(Emulators.FIRESTORE),
database: EmulatorRegistry.getPort(Emulators.DATABASE),
},
disabled_features: this.args.disabledRuntimeFeatures,
};
}

/**
* Returns the path to a "node" executable to use.
*/
Expand Down
11 changes: 5 additions & 6 deletions src/emulator/functionsEmulatorRuntime.ts
Expand Up @@ -511,11 +511,6 @@ function getDefaultConfig(): any {
* We also mock out firestore.settings() so we can merge the emulator settings with the developer's.
*/
async function InitializeFirebaseAdminStubs(frb: FunctionsRuntimeBundle): Promise<void> {
if (!isFeatureEnabled(frb, "admin_stubs")) {
logDebug("Admin stubs disabled, not stubbing Firebase Admin");
return;
}

const adminResolution = await resolveDeveloperNodeModule(frb, "firebase-admin");
if (!adminResolution.resolution) {
throw new Error("Could not resolve 'firebase-admin'");
Expand Down Expand Up @@ -973,8 +968,12 @@ async function main(): Promise<void> {
await InitializeFunctionsConfigHelper(frb.cwd);
}

// TODO: Should this feature have a flag as well or is it required?
await InitializeFirebaseFunctionsStubs(frb);
await InitializeFirebaseAdminStubs(frb);

if (isFeatureEnabled(frb, "admin_stubs")) {
await InitializeFirebaseAdminStubs(frb);
}

let triggers: EmulatedTriggerMap;
const triggerDefinitions: EmulatedTriggerDefinition[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/functionsEmulatorShell.ts
Expand Up @@ -69,7 +69,7 @@ export class FunctionsEmulatorShell implements FunctionsShellController {
};

FunctionsEmulator.startFunctionRuntime(
this.emu.bundleTemplate,
this.emu.getBaseBundle(),
name,
this.emu.nodeBinary,
proto
Expand Down

0 comments on commit 0058024

Please sign in to comment.