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

Function actionFunction

src/functionsShellCommandAction.ts:23–150  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

21const serveFunctions = new FunctionsServer();
22
23export const actionFunction = async (options: Options) => {
24 if (typeof options.port === "string") {
25 options.port = parseInt(options.port, 10);
26 }
27
28 let debugPort = undefined;
29 if (options.inspectFunctions) {
30 debugPort = commandUtils.parseInspectionPort(options);
31 }
32
33 needProjectId(options);
34 const hubClient = new EmulatorHubClient(options.project);
35
36 let remoteEmulators: Record<string, EmulatorInfo> = {};
37 if (hubClient.foundHub()) {
38 remoteEmulators = await hubClient.getEmulators();
39 logger.debug("Running emulators: ", remoteEmulators);
40 }
41
42 const runningEmulators = EMULATORS_SUPPORTED_BY_FUNCTIONS.filter(
43 (e) => remoteEmulators[e] !== undefined,
44 );
45 const otherEmulators = EMULATORS_SUPPORTED_BY_FUNCTIONS.filter(
46 (e) => remoteEmulators[e] === undefined,
47 );
48
49 let host = Constants.getDefaultHost();
50 // If the port was not set by the --port flag or determined from 'firebase.json', just scan
51 // up from 5000
52 let port = 5000;
53 if (typeof options.port === "number") {
54 port = options.port;
55 }
56
57 const functionsInfo = remoteEmulators[Emulators.FUNCTIONS];
58 if (functionsInfo) {
59 utils.logLabeledWarning(
60 "functions",
61 `You are already running the Cloud Functions emulator on port ${functionsInfo.port}. Running the emulator and the Functions shell simultaenously can result in unexpected behavior.`,
62 );
63 } else if (!options.port) {
64 // If the user did not pass in any port and the functions emulator is not already running, we can
65 // use the port defined for the Functions emulator in their firebase.json
66 port = options.config.src.emulators?.functions?.port ?? port;
67 host = options.config.src.emulators?.functions?.host ?? host;
68 options.host = host;
69 }
70
71 const listen = (
72 await resolveHostAndAssignPorts({
73 [Emulators.FUNCTIONS]: { host, port },
74 })
75 ).functions;
76 // TODO: Listen on secondary addresses.
77 options.host = listen[0].address;
78 options.port = listen[0].port;
79
80 return serveFunctions

Callers

nothing calls this directly

Calls 12

foundHubMethod · 0.95
getEmulatorsMethod · 0.95
needProjectIdFunction · 0.90
getDefaultHostMethod · 0.80
onMethod · 0.80
initializeContextFunction · 0.70
startMethod · 0.65
connectMethod · 0.65
getMethod · 0.65
stopMethod · 0.65
exitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…