Skip to content

Commit ab0090c

Browse files
inlinedjoehan
authored andcommitted
Re-allow users to not select an emulator UI port. (firebase#8626)
* Re-allow users to not select an emulator UI port. Fixes firebase#8621 Sorry; somehow I missed that there was a case where numbers are not required. Keeps the library's behavior of assuming that numbers are required, but allows explicitly overwriting this with a "reququired: false". This is the only value that can be provided to "required". Using type magic, the return type of number can only be defined if "required: false" is passed in. * Format & changelog --------- Co-authored-by: joehan <[email protected]>
1 parent 7afe1bd commit ab0090c

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Fixed issue in `init` where users were forced to specify emulator UI port (#8626)
12
- Adds MCP tools for App Hosting (#8605)
23
- Fixed crash when starting the App Hosting emulator in certain applications (#8624)
34
- Fixed issue where, with `webframeworks` enabled, `firebase init hosting` re-prompts users for source. (#8587)

src/init/features/emulators.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ export async function doSetup(setup: Setup, config: Config) {
8181
});
8282

8383
if (ui.enabled) {
84-
ui.port = await number(
85-
`Which port do you want to use for the ${clc.underline(uiDesc)} (leave empty to use any available port)?`,
86-
);
87-
88-
// Parse the input as a number
89-
const portNum = Number.parseInt(ui.port as any);
90-
ui.port = isNaN(portNum) ? undefined : portNum;
84+
ui.port = await number({
85+
message: `Which port do you want to use for the ${clc.underline(uiDesc)} (leave empty to use any available port)?`,
86+
required: false,
87+
});
9188
}
9289
}
9390

src/prompt.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,14 @@ export async function number(message: string): Promise<number>;
214214
*/
215215
export async function number(opts: NumberOptions): Promise<number>;
216216

217-
export async function number(opts: string | NumberOptions): Promise<number> {
217+
/**
218+
* Prompt a user for an optional number.
219+
*/
220+
export async function number(
221+
opts: NumberOptions & { required: false },
222+
): Promise<number | undefined>;
223+
224+
export async function number(opts: string | NumberOptions): Promise<number | undefined> {
218225
if (typeof opts === "string") {
219226
opts = { message: opts };
220227
} else {
@@ -224,7 +231,7 @@ export async function number(opts: string | NumberOptions): Promise<number> {
224231
}
225232
}
226233

227-
return (await inquirer.number({ ...opts, required: true }))!;
234+
return await inquirer.number({ required: true, ...opts });
228235
}
229236

230237
/**

0 commit comments

Comments
 (0)