Skip to content

Make emulator hub locator path more robust to environment changes #8604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/emulator/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { maybeUsePortForwarding } from "./env";

// We use the CLI version from package.json
const pkg = require("../../package.json");

Check warning on line 19 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 19 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

export interface Locator {
version: string;
Expand All @@ -33,7 +33,7 @@
export type GetEmulatorsResponse = Partial<Record<Emulators, EmulatorInfo>>;

export class EmulatorHub extends ExpressBasedEmulator {
static CLI_VERSION = pkg.version;

Check warning on line 36 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 36 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .version on an `any` value
static PATH_EXPORT = "/_admin/export";
static PATH_DISABLE_FUNCTIONS = "/functions/disableBackgroundTriggers";
static PATH_ENABLE_FUNCTIONS = "/functions/enableBackgroundTriggers";
Expand Down Expand Up @@ -64,9 +64,7 @@
}

static getLocatorFilePath(projectId: string): string {
const dir = os.tmpdir();
const filename = `hub-${projectId}.json`;
return path.join(dir, filename);
return path.join(os.homedir(), ".cache", "firebase", `hub-${projectId}.json`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the parent directories do not exist? Can we find some existing code in the rest of the CLI code base that creates the parents and reuse the logic?

Copy link
Contributor

@joehan joehan May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is why the integration tests are failing btw - the runner does not have this directory

}

constructor(private args: EmulatorHubArgs) {
Expand Down Expand Up @@ -106,14 +104,14 @@
res.json(this.getRunningEmulatorsMapping());
});

app.post(EmulatorHub.PATH_EXPORT, async (req, res) => {

Check warning on line 107 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise returned in function argument where a void return was expected
if (req.headers.origin) {
res.status(403).json({
message: `Export cannot be triggered by external callers.`,
});
}
const path: string = req.body.path;

Check warning on line 113 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 113 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .path on an `any` value
const initiatedBy: string = req.body.initiatedBy || "unknown";

Check warning on line 114 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 114 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .initiatedBy on an `any` value
utils.logLabeledBullet("emulators", `Received export request. Exporting data to ${path}.`);
try {
await new HubExport(this.args.projectId, {
Expand All @@ -124,7 +122,7 @@
res.status(200).send({
message: "OK",
});
} catch (e: any) {

Check warning on line 125 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const errorString = e.message || JSON.stringify(e);
utils.logLabeledWarning("emulators", `Export failed: ${errorString}`);
res.status(500).json({
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class FirebaseMcpServer {

async getEmulatorHubClient(): Promise<EmulatorHubClient | undefined> {
// Single initilization
if (this.emulatorHubClient) {
if (this.emulatorHubClient && this.emulatorHubClient.foundHub()) {
return this.emulatorHubClient;
}
const projectId = await this.getProjectId();
Expand Down
Loading