-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[VS Code] Fix the no project emulator experience #9072
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
eecb596
improve error handling of resolving service_id in VS Code
fredzqm 1a3dd24
remove rc from fdc toolkit
fredzqm cbd646c
Fall back to demo-local project
fredzqm e8565dc
m
fredzqm ec21799
Update firebase-vscode/src/data-connect/service.ts
fredzqm 95ad006
Merge branch 'master' into fz/service-path
fredzqm e7b7a7e
changelog
fredzqm 8a33cf2
m
fredzqm 92a0df9
Merge remote-tracking branch 'origin/master' into fz/service-path
fredzqm 4622456
use demo local
fredzqm d28c59d
hard code a locator file
fredzqm 0d9552b
cleanup
fredzqm 4299a0b
use a fixed demo-no-project
fredzqm 24cae69
Merge remote-tracking branch 'origin/master' into fz/service-path
fredzqm 82e0e67
nits
fredzqm 764ed09
Merge remote-tracking branch 'origin/master' into fz/service-path
fredzqm f796243
changelog
fredzqm 1bdb3dc
m
fredzqm b887d00
cleanup emulator ui logic
fredzqm 2e45fa6
nits
fredzqm 61abeb5
nits
fredzqm abb98ba
test
fredzqm 6ce63a9
fix-tests
fredzqm 31adc23
comment
fredzqm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- `firebase emulator:start` use a default project if no project can be found. (#9072) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
import { Constants, FIND_AVAILBLE_PORT_BY_DEFAULT } from "./constants"; | ||
import { EmulatableBackend, FunctionsEmulator } from "./functionsEmulator"; | ||
import { FirebaseError } from "../error"; | ||
import { getProjectId, needProjectId, getAliases, needProjectNumber } from "../projectUtils"; | ||
import { getProjectId, getAliases, needProjectNumber } from "../projectUtils"; | ||
import * as commandUtils from "./commandUtils"; | ||
import { EmulatorHub } from "./hub"; | ||
import { ExportMetadata, HubExport } from "./hubExport"; | ||
|
@@ -73,7 +73,7 @@ | |
|
||
/** | ||
* Exports emulator data on clean exit (SIGINT or process end) | ||
* @param options | ||
Check warning on line 76 in src/emulator/controller.ts
|
||
*/ | ||
export async function exportOnExit(options: Options): Promise<void> { | ||
// Note: options.exportOnExit is coerced to a string before this point in commandUtils.ts#setExportOnExitOptions | ||
|
@@ -86,7 +86,7 @@ | |
); | ||
await exportEmulatorData(exportOnExitDir, options, /* initiatedBy= */ "exit"); | ||
} catch (e: unknown) { | ||
utils.logWarning(`${e}`); | ||
utils.logWarning(`Automatic export to "${exportOnExitDir}" failed, going to exit now...`); | ||
} | ||
} | ||
|
@@ -94,7 +94,7 @@ | |
|
||
/** | ||
* Hook to do things when we're exiting cleanly (this does not include errors). Will be skipped on a second SIGINT | ||
* @param options | ||
Check warning on line 97 in src/emulator/controller.ts
|
||
*/ | ||
export async function onExit(options: any) { | ||
await exportOnExit(options); | ||
|
@@ -148,8 +148,8 @@ | |
*/ | ||
export function shouldStart(options: Options, name: Emulators): boolean { | ||
if (name === Emulators.HUB) { | ||
// The hub only starts if we know the project ID. | ||
return !!options.project; | ||
// The emulator hub always starts. | ||
return true; | ||
} | ||
const targets = filterEmulatorTargets(options); | ||
const emulatorInTargets = targets.includes(name); | ||
|
@@ -166,9 +166,7 @@ | |
} | ||
// Emulator UI only starts if we know the project ID AND at least one | ||
// emulator supported by Emulator UI is launching. | ||
return ( | ||
!!options.project && targets.some((target) => EMULATORS_SUPPORTED_BY_UI.includes(target)) | ||
); | ||
return targets.some((target) => EMULATORS_SUPPORTED_BY_UI.includes(target)); | ||
} | ||
|
||
// Don't start the functions emulator if we can't validate the functions config | ||
|
@@ -310,7 +308,7 @@ | |
const hubLogger = EmulatorLogger.forEmulator(Emulators.HUB); | ||
hubLogger.logLabeled("BULLET", "emulators", `Starting emulators: ${targets.join(", ")}`); | ||
|
||
const projectId: string = getProjectId(options) || ""; // TODO: Next breaking change, consider making this fall back to demo project. | ||
const projectId = getProjectId(options) || EmulatorHub.MISSING_PROJECT_PLACEHOLDER; | ||
const isDemoProject = Constants.isDemoProject(projectId); | ||
if (isDemoProject) { | ||
hubLogger.logLabeled( | ||
|
@@ -579,7 +577,6 @@ | |
} | ||
const functionsLogger = EmulatorLogger.forEmulator(Emulators.FUNCTIONS); | ||
const functionsAddr = legacyGetFirstAddr(Emulators.FUNCTIONS); | ||
const projectId = needProjectId(options); | ||
|
||
const inspectFunctions = commandUtils.parseInspectionPort(options); | ||
if (inspectFunctions) { | ||
|
@@ -723,16 +720,8 @@ | |
|
||
// undefined in the config defaults to setting single_project_mode. | ||
if (singleProjectModeEnabled) { | ||
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.", | ||
); | ||
} | ||
args.single_project_mode = true; | ||
args.single_project_mode_error = false; | ||
} | ||
|
||
const firestoreEmulator = new FirestoreEmulator(args); | ||
|
@@ -822,14 +811,6 @@ | |
} | ||
|
||
if (listenForEmulator.auth) { | ||
if (!projectId) { | ||
throw new FirebaseError( | ||
`Cannot start the ${Constants.description( | ||
Emulators.AUTH, | ||
)} without a project: run 'firebase init' or provide the --project flag`, | ||
); | ||
} | ||
|
||
const authAddr = legacyGetFirstAddr(Emulators.AUTH); | ||
const authEmulator = new AuthEmulator({ | ||
host: authAddr.host, | ||
|
@@ -851,12 +832,6 @@ | |
} | ||
|
||
if (listenForEmulator.pubsub) { | ||
if (!projectId) { | ||
throw new FirebaseError( | ||
"Cannot start the Pub/Sub emulator without a project: run 'firebase init' or provide the --project flag", | ||
); | ||
} | ||
|
||
const pubsubAddr = legacyGetFirstAddr(Emulators.PUBSUB); | ||
const pubsubEmulator = new PubsubEmulator({ | ||
host: pubsubAddr.host, | ||
|
@@ -882,7 +857,6 @@ | |
projectId, | ||
auto_download: true, | ||
configDir: config[0].source, | ||
rc: options.rc, | ||
config: options.config, | ||
autoconnectToPostgres: true, | ||
postgresListen: listenForEmulator["dataconnect.postgres"], | ||
|
@@ -941,7 +915,7 @@ | |
const storageEmulator = new StorageEmulator({ | ||
host: storageAddr.host, | ||
port: storageAddr.port, | ||
projectId: projectId, | ||
projectId, | ||
rules: getStorageRulesConfig(projectId, options), | ||
}); | ||
await startEmulator(storageEmulator); | ||
|
@@ -1030,15 +1004,14 @@ | |
hubLogger.logLabeled( | ||
"WARN", | ||
"emulators", | ||
"The Emulator UI is not starting, either because none of the running " + | ||
"emulators have a UI component or the Emulator UI cannot " + | ||
"determine the Project ID. Pass the --project flag to specify a project.", | ||
"The Emulator UI is not starting because none of the running " + | ||
"emulators have a UI component.", | ||
); | ||
} | ||
|
||
if (listenForEmulator.ui) { | ||
const ui = new EmulatorUI({ | ||
projectId: projectId, | ||
projectId, | ||
listen: listenForEmulator[Emulators.UI], | ||
}); | ||
await startEmulator(ui); | ||
|
@@ -1104,13 +1077,6 @@ | |
*/ | ||
export async function exportEmulatorData(exportPath: string, options: any, initiatedBy: string) { | ||
const projectId = options.project; | ||
if (!projectId) { | ||
throw new FirebaseError( | ||
"Could not determine project ID, make sure you're running in a Firebase project directory or add the --project flag.", | ||
{ exit: 1 }, | ||
); | ||
} | ||
|
||
const hubClient = new EmulatorHubClient(projectId); | ||
if (!hubClient.foundHub()) { | ||
throw new FirebaseError( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, my bad. Shouldn't have enable auto-merge.