Skip to content

update firebase init to accept multiple features#10762

Draft
aalej wants to merge 1 commit into
mainfrom
aalej_init-multi-feature
Draft

update firebase init to accept multiple features#10762
aalej wants to merge 1 commit into
mainfrom
aalej_init-multi-feature

Conversation

@aalej

@aalej aalej commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Description

Updates firebase init to accept multiple features. For example, firebase init hosting emulators

Scenarios Tested

firebase init hosting emulators - goes through the hosting + emulators set up
firebase init - verified that interactive feature selection still works

`firebase init`
$ firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  /Users/PATH/multi-product-init

Before we get started, keep in mind:

  * You are initializing within an existing Firebase project directory

? Which Firebase features do you want to set up for this directory? Press Space to select features, then Enter to confirm your choices.
❯◯ SQL Connect: Set up a Firebase SQL Connect service
 ◯ Firestore: Configure security rules and indexes files for Firestore
 ◯ Genkit: Setup a new Genkit project with Firebase
 ◯ Functions: Configure a Cloud Functions directory and its files
 ◯ App Hosting: Set up deployments for full-stack web apps (supports server-side rendering)
 ◯ Hosting: Set up deployments for static web apps
 ◯ Storage: Configure a security rules file for Cloud Storage

↑↓ navigate • space select • a all • i invert • ⏎ submit

invalid feature

$ firebase init hosting invalid_feature1 invalid_feature2

Error: Invalid features: invalid_feature1, invalid_feature2. Valid features are: dataconnect, firestore, genkit, functions, apphosting, hosting, storage, emulators, remoteconfig, extensions, database, hosting:github, dataconnect:sdk, auth, dataconnect:resolver, ailogic, aitools.

Sample Commands

firebase init hosting emulators

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the firebase init command to accept multiple features from the command line. However, a critical bug was identified where running the command interactively without arguments causes a TypeError because the argument is passed as an empty string instead of an array, causing .filter() to fail. A solution was suggested to normalize the input parameter to handle both strings and arrays.

Comment thread src/commands/init.ts
Comment on lines +168 to +170
export async function initAction(features: string[], options: Options): Promise<void> {
const invalidFeatures = features.filter((f) => !featureNames.includes(f));
if (invalidFeatures.length > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Critical Bug: Interactive firebase init crashes with TypeError

When running firebase init without any arguments (the default interactive mode), the command runner in src/command.ts pads missing positional arguments with an empty string "" to match the expected positional arguments length.

Because of this, features is passed to initAction as "" (a string) instead of an array of strings. Calling .filter() on a string throws a runtime TypeError: features.filter is not a function, completely blocking the interactive initialization flow.

Solution

We can resolve this by accepting string[] | string for the first parameter, and normalizing it to a string[] array at the very beginning of the function. By declaring a local const features, we ensure all subsequent references in the function work seamlessly without further changes.

export async function initAction(rawFeatures: string[] | string, options: Options): Promise<void> {
  const features = typeof rawFeatures === "string" ? (rawFeatures ? [rawFeatures] : []) : rawFeatures || [];
  const invalidFeatures = features.filter((f) => !featureNames.includes(f));
  if (invalidFeatures.length > 0) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong? Did a console log to check if features is an array or an empty string "", and it is an array not a string. With added logs

export async function initAction(features: string[], options: Options): Promise<void> {
  console.log(`Array.isArray(features): ${Array.isArray(features)}`)

firebase init outputs

$ firebase init
Array.isArray(features): true

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

Comment thread src/commands/init.ts
.join("")}`;

export const command = new Command("init [feature]")
export const command = new Command("init [features...]")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's swap this to comma separated values ie firebase init functions,hosting,thing3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify, checked our commands and found some that use variadic input firebase appdistribution:testers:add, these seem to expect space separated input.

$ firebase appdistribution:testers:add --help
Usage: firebase appdistribution:testers:add [options] [emails...]

Something like

firebase appdistribution:testers:add fake@fake.com fake2@fake.com --project aalej-6162-2
i  Adding 2 testers to project
✔  Testers created successfully

Given the above, I wanted to verify if we still want to do comma separated input firebase init functions,hosting,thing3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I think we can also make the firebase init command more lenient and support both comma and space separated. So something like below would still work

firebase init feature1,feature2 feature3

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after the slight args change

@aalej
aalej marked this pull request as draft July 8, 2026 17:01
@aalej

aalej commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Note: some work is being done to make the firebase init command more agent/non-interactive friendly. I'll mark this as a draft for now so we don't accidentally merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants