Skip to content

Commit

Permalink
Single project mode config for the CLI and firestore.
Browse files Browse the repository at this point in the history
  • Loading branch information
christhompsongoogle committed Oct 3, 2022
1 parent 3b48be0 commit 4941195
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,5 @@
- Add the "experiments" family of commands (#4994)
- Enable detecting and skipping no-op function deploys (#5032).
- Catches errors when fetching CLI MOTD, allowing process to continue (#4998).
- Adds test lab triggers to firebase deploy (#5011).
- Adds test lab triggers to firebase deploy (#5011). TODO
- Enable single project mode for firestore by default (#4890).
3 changes: 3 additions & 0 deletions schema/firebase-config.json
Expand Up @@ -295,6 +295,9 @@
}
},
"type": "object"
},
"singleProjectMode": {
"type": "boolean"
}
},
"type": "object"
Expand Down
19 changes: 18 additions & 1 deletion src/emulator/controller.ts
Expand Up @@ -622,7 +622,7 @@ export async function startAll(
host: firestoreAddr.host,
port: firestoreAddr.port,
websocket_port: websocketPort,
projectId,
project_id: projectId,
auto_download: true,
};

Expand Down Expand Up @@ -677,6 +677,23 @@ export async function startAll(
);
}

// undefined in the config defaults to setting single_project_mode.
if (
options.config.src.emulators?.singleProjectMode === undefined ||
options.config.src.emulators?.singleProjectMode
) {
if (projectId) {
args.single_project_mode = true;
args.single_project_mode_error = false;
} else {
firestoreLogger.logLabeled(
"DEBUG",
"firestore",
"Could not enable single_project_mode: missing projectId."
);
}
}

const firestoreEmulator = new FirestoreEmulator(args);
await startEmulator(firestoreEmulator);
firestoreLogger.logLabeled(
Expand Down
4 changes: 4 additions & 0 deletions src/emulator/downloadableEmulators.ts
Expand Up @@ -163,6 +163,10 @@ const Commands: { [s in DownloadableEmulators]: DownloadableEmulatorCommand } =
"websocket_port",
"functions_emulator",
"seed_from_export",
"project_id",
"single_project_mode",
// TODO(christhompson) Re-enable after firestore accepts this flag.
// "single_project_mode_error",
],
joinArgs: false,
},
Expand Down
8 changes: 5 additions & 3 deletions src/emulator/firestoreEmulator.ts
Expand Up @@ -15,11 +15,13 @@ export interface FirestoreEmulatorArgs {
port?: number;
host?: string;
websocket_port?: number;
projectId?: string;
project_id?: string;
rules?: string;
functions_emulator?: string;
auto_download?: boolean;
seed_from_export?: string;
single_project_mode?: boolean;
single_project_mode_error?: boolean;
}

export class FirestoreEmulator implements EmulatorInstance {
Expand All @@ -35,7 +37,7 @@ export class FirestoreEmulator implements EmulatorInstance {
this.args.functions_emulator = EmulatorRegistry.getInfoHostString(functionsInfo);
}

if (this.args.rules && this.args.projectId) {
if (this.args.rules && this.args.project_id) {
const rulesPath = this.args.rules;
this.rulesWatcher = chokidar.watch(rulesPath, { persistent: true, ignoreInitial: true });
this.rulesWatcher.on("change", async () => {
Expand Down Expand Up @@ -94,7 +96,7 @@ export class FirestoreEmulator implements EmulatorInstance {
}

private async updateRules(content: string): Promise<Issue[]> {
const projectId = this.args.projectId;
const projectId = this.args.project_id;

const info = this.getInfo();
const body = {
Expand Down
1 change: 1 addition & 0 deletions src/firebaseConfig.ts
Expand Up @@ -168,6 +168,7 @@ export type EmulatorsConfig = {
host?: string;
port?: number;
};
singleProjectMode?: boolean;
};

export type ExtensionsConfig = Record<string, string>;
Expand Down
5 changes: 5 additions & 0 deletions src/init/features/emulators.ts
Expand Up @@ -100,6 +100,11 @@ export async function doSetup(setup: any, config: any) {
]);
}

// Set the default behavior to be single project mode.
if (setup.config.emulators.singleProjectMode === undefined) {
setup.config.emulators.singleProjectMode = true;
}

if (selections.download) {
for (const selected of selections.emulators) {
if (isDownloadableEmulator(selected)) {
Expand Down

0 comments on commit 4941195

Please sign in to comment.