Skip to content
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

Single project mode #4890

Merged
merged 6 commits into from Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
- Enable single project mode for firestore by default (#4890).
3 changes: 3 additions & 0 deletions schema/firebase-config.json
Expand Up @@ -266,6 +266,9 @@
},
"type": "object"
},
"singleProjectMode": {
"type": "boolean"
},
"storage": {
"additionalProperties": false,
"properties": {
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