Skip to content

add validation for the app directory prompt#10618

Merged
joehan merged 5 commits into
mainfrom
aalej_ah-app-dir-validate
Jun 17, 2026
Merged

add validation for the app directory prompt#10618
joehan merged 5 commits into
mainfrom
aalej_ah-app-dir-validate

Conversation

@aalej

@aalej aalej commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

When prompted for the app hosting app directory and you provide a non-existent path the CLI will error out:

=== App Hosting Setup
i  This command links your local project to Firebase App Hosting. You will be able to deploy your web app with `firebase deploy` after setup.
✔ Please select an option Link to an existing backend
✔ Which backend would you like to link? BACKEND_ID
i  === Deploy local source setup
✔ Specify your app's root directory relative to your firebase.json directory /non-existent
✔  Wrote configuration info to firebase.json
i  Writing default settings to apphosting.yaml...

Error: Failed to write apphosting.yaml file because app root directory /Users/PATH/apphosting-folder-setup/non-existent does not exist. Please try again with a valid directory.

Updated the behavior to validate the path during prompting:

=== App Hosting Setup
i  This command links your local project to Firebase App Hosting. You will be able to deploy your web app with `firebase deploy` after setup.
✔ Please select an option Link to an existing backend
✔ Which backend would you like to link? BACKEND_ID
i  === Deploy local source setup
? Specify your app's root directory relative to your firebase.json directory /non-existent
> Directory /Users/PATH/apphosting-folder-setup/non-existent does not exist. Please enter a valid directory.

Scenarios Tested

$ firebase init apphosting 

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

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

  /Users/PATH/apphosting-folder-setup

Before we get started, keep in mind:

  * You are initializing within an existing Firebase project directory


=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add, 

i  Using project PROJECT_ID (PROJECT_NAME) .

=== App Hosting Setup
i  This command links your local project to Firebase App Hosting. You will be able to deploy your web app with `firebase deploy` after setup.
✔ Please select an option Link to an existing backend
✔ Which backend would you like to link? BACKEND_ID
i  === Deploy local source setup
? Specify your app's root directory relative to your firebase.json directory /non-existent
> Directory /Users/PATH/apphosting-folder-setup/non-existent does not exist. Please enter a valid directory.

Sample Commands

@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 adds input validation to ensure the specified App Hosting root directory exists. The reviewer noted that the path resolution should use config.path(input) instead of process.cwd() to correctly resolve relative to the firebase.json directory, and suggested removing the unnecessary async keyword.

Comment thread src/init/features/apphosting.ts Outdated
Comment on lines +116 to +122
validate: async (input: string) => {
const absPath = path.join(process.cwd(), input);
if (!existsSync(absPath)) {
return `Directory ${absPath} does not exist. Please enter a valid directory.`;
}
return true;
},

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.

medium

The prompt asks for the app's root directory relative to the firebase.json directory. However, the validation logic resolves the path using process.cwd(), which may differ from the directory containing firebase.json (e.g., if the CLI is run from a subdirectory).

To ensure correctness, resolve the path using config.path(input) instead of path.join(process.cwd(), input). Additionally, since the validation function does not perform any asynchronous operations, the async keyword can be removed.

Suggested change
validate: async (input: string) => {
const absPath = path.join(process.cwd(), input);
if (!existsSync(absPath)) {
return `Directory ${absPath} does not exist. Please enter a valid directory.`;
}
return true;
},
validate: (input: string) => {
const absPath = config.path(input);
if (!existsSync(absPath)) {
return `Directory ${absPath} does not exist. Please enter a valid directory.`;
}
return true;
},

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.

the absPath code was copied from over

const absRootDir = path.join(process.cwd(), backendConfig.rootDir);

Although, aynsc should be removed since there are no promises or awaits inside the function. Good call out!

Comment thread src/init/features/apphosting.ts Outdated
default: "/",
message: "Specify your app's root directory relative to your firebase.json directory",
validate: (input: string) => {
const absPath = path.join(process.cwd(), input);

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.

This logic assumes that process.cwd() == the firebase directory. However, if you run init from a child of the firebase directory, that will not be true. We've got some utils that resolve the firebase project dir - lets use those instead here.

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.

Good catch! Running the init command on a sub-directory does break the prompt. We do set a config early on in

this.projectDir = this.options.projectDir || detectProjectRoot(this.options);

switching process.cwd() to config.projectDir

@aalej aalej requested a review from joehan June 12, 2026 11:05
@joehan joehan enabled auto-merge (squash) June 16, 2026 16:42
@wiz-9635d3485b

wiz-9635d3485b Bot commented Jun 16, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 3 Medium
Software Management Finding Software Management Findings -
Total 3 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@joehan joehan merged commit 33ff901 into main Jun 17, 2026
51 of 52 checks passed
@joehan joehan deleted the aalej_ah-app-dir-validate branch June 17, 2026 11:47
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