MCPcopy Create free account
hub / github.com/firebase/firebase-tools / needProjectId

Function needProjectId

src/projectUtils.ts:30–75  ·  view source on GitHub ↗
({
  projectId,
  project,
  rc,
}: {
  projectId?: string;
  project?: string;
  rc?: RC;
})

Source from the content-addressed store, hash-verified

28 * @returns The projectId
29 */
30export function needProjectId({
31 projectId,
32 project,
33 rc,
34}: {
35 projectId?: string;
36 project?: string;
37 rc?: RC;
38}): string {
39 if (projectId || project) {
40 return projectId || project!;
41 }
42
43 const aliases = rc?.projects || {};
44 const aliasCount = Object.keys(aliases).length;
45
46 if (aliasCount === 0) {
47 throw new FirebaseError(
48 "No currently active project.\n" +
49 "To run this command, you need to specify a project. You have two options:\n" +
50 "- Run this command with " +
51 clc.bold("--project <alias_or_project_id>") +
52 ".\n" +
53 "- Set an active project by running " +
54 clc.bold("firebase use --add") +
55 ", then rerun this command.\n" +
56 "To list all the Firebase projects to which you have access, run " +
57 clc.bold("firebase projects:list") +
58 ".\n" +
59 marked(
60 "To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases",
61 ),
62 );
63 }
64
65 const aliasList = Object.entries(aliases)
66 .map(([aname, projectId]) => ` ${aname} (${projectId})`)
67 .join("\n");
68
69 throw new FirebaseError(
70 "No project active, but project aliases are available.\n\nRun " +
71 clc.bold("firebase use <alias>") +
72 " with one of these options:\n\n" +
73 aliasList,
74 );
75}
76
77/**
78 * Fetches the project number, throwing an error if unable to resolve the

Callers 15

getCachedWebSetupFunction · 0.90
fetchWebSetupFunction · 0.90
getDefaultHostingSiteFunction · 0.90
getProjectNumberFunction · 0.90
actionFunctionFunction · 0.90
ensureApiFunction · 0.90
getFirebaseConfigFunction · 0.90
deployFunction · 0.90
deployFunction · 0.90
prepareFunction · 0.90
prepareFunction · 0.90

Calls 1

markedFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…