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

Function implicitInit

src/hosting/implicitInit.ts:28–90  ·  view source on GitHub ↗
(options: any)

Source from the content-addressed store, hash-verified

26 */
27// eslint-disable-next-line @typescript-eslint/no-explicit-any
28export async function implicitInit(options: any): Promise<TemplateServerResponse> {
29 let config;
30 try {
31 config = await fetchWebSetup(options);
32 } catch (e: any) {
33 logger.debug("fetchWebSetup error: " + e);
34 const statusCode = _.get(e, "context.response.statusCode");
35 if (statusCode === 403) {
36 utils.logLabeledWarning(
37 "hosting",
38 `Authentication error when trying to fetch your current web app configuration, have you run ${clc.bold(
39 "firebase login",
40 )}?`,
41 );
42 }
43 }
44
45 if (!config) {
46 config = getCachedWebSetup(options);
47 if (config) {
48 utils.logLabeledWarning("hosting", "Using web app configuration from cache.");
49 }
50 }
51
52 if (!config) {
53 config = undefined;
54 utils.logLabeledWarning(
55 "hosting",
56 "Could not fetch web app configuration and there is no cached configuration on this machine. " +
57 "Check your internet connection and make sure you are authenticated. " +
58 "To continue, you must call firebase.initializeApp({...}) in your code before using Firebase.",
59 );
60 }
61
62 const configJson = JSON.stringify(config, null, 2);
63
64 const emulators: { [e in Emulators]?: { host: string; port: number; hostAndPort: string } } = {};
65 for (const e of EMULATORS_SUPPORTED_BY_USE_EMULATOR) {
66 const info = EmulatorRegistry.getInfo(e);
67
68 if (info) {
69 emulators[e] = {
70 host: info.host,
71 port: info.port,
72 hostAndPort: EmulatorRegistry.url(e).host,
73 };
74 }
75 }
76 const emulatorsJson = JSON.stringify(emulators, null, 2);
77
78 const initTemplate = readTemplateSync("hosting/init.js");
79 const js = initTemplate
80 .replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`)
81 .replace("/*--EMULATORS--*/", "var firebaseEmulators = undefined;");
82 const emulatorsJs = initTemplate
83 .replace("/*--CONFIG--*/", `var firebaseConfig = ${configJson};`)
84 .replace("/*--EMULATORS--*/", `var firebaseEmulators = ${emulatorsJson};`);
85 return {

Callers 2

startFunction · 0.90
prepareFrameworksFunction · 0.90

Calls 6

fetchWebSetupFunction · 0.90
getCachedWebSetupFunction · 0.90
readTemplateSyncFunction · 0.90
urlMethod · 0.80
getMethod · 0.65
getInfoMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…