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 2 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
9 changes: 6 additions & 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,12 @@
}

static getLocatorFilePath(projectId: string): string {
const dir = os.tmpdir();
const filename = `hub-${projectId}.json`;
return path.join(dir, filename);
return path.join(

Check failure on line 67 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Replace `⏎······os.homedir(),⏎········".cache",⏎········"firebase",⏎········`hub-${projectId}.json`,⏎······` with `os.homedir(),·".cache",·"firebase",·`hub-${projectId}.json``

Check failure on line 67 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `⏎······os.homedir(),⏎········".cache",⏎········"firebase",⏎········`hub-${projectId}.json`,⏎······` with `os.homedir(),·".cache",·"firebase",·`hub-${projectId}.json``

Check failure on line 67 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎······os.homedir(),⏎········".cache",⏎········"firebase",⏎········`hub-${projectId}.json`,⏎······` with `os.homedir(),·".cache",·"firebase",·`hub-${projectId}.json``

Check failure on line 67 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Replace `⏎······os.homedir(),⏎········".cache",⏎········"firebase",⏎········`hub-${projectId}.json`,⏎······` with `os.homedir(),·".cache",·"firebase",·`hub-${projectId}.json``

Check failure on line 67 in src/emulator/hub.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎······os.homedir(),⏎········".cache",⏎········"firebase",⏎········`hub-${projectId}.json`,⏎······` with `os.homedir(),·".cache",·"firebase",·`hub-${projectId}.json``
os.homedir(),
".cache",
"firebase",
`hub-${projectId}.json`,
);
}

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

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

Check warning on line 112 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 118 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 118 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 119 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 119 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 +127,7 @@
res.status(200).send({
message: "OK",
});
} catch (e: any) {

Check warning on line 130 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