(options: Options)
| 21 | const serveFunctions = new FunctionsServer(); |
| 22 | |
| 23 | export 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…