Repository navigation
feat(hosting): ensure Firebase Hosting API is enabled before deploy and Hosting commands - #11296
Conversation
…nd Hosting commands ### Description Ensures that the Firebase Hosting API (`firebasehosting.googleapis.com`) is enabled on the target project(s) before deploying to Firebase Hosting or running `hosting:*` CLI commands (`hosting:channel:*`, `hosting:sites:*`, `hosting:clone`, `hosting:disable`). ### Scenarios Tested - Unit tests for `deploy` command `.before()` hook (`src/commands/deploy.spec.ts`) and Hosting `prepare` step (`src/deploy/hosting/prepare.spec.ts`) - Unit tests for `hosting:clone` same-project and cross-project API enablement (`src/commands/hosting-clone.spec.ts`) and `hosting:disable` (`src/commands/hosting-disable.spec.ts`) ### Sample Commands ```bash firebase deploy --only hosting firebase hosting:sites:list firebase hosting:channel:deploy preview firebase hosting:clone source-site:staging target-site:live firebase hosting:disable ```
There was a problem hiding this comment.
Code Review
This pull request ensures that the Firebase Hosting API is enabled before executing various Hosting commands (such as deploy, clone, disable, and channel/site management) by adding API enablement checks. The feedback suggests optimizing the hosting:clone command by running the API enablement checks concurrently using Promise.all, and refactoring the deploy command unit tests to dynamically locate the hosting hook rather than relying on a fragile hardcoded index.
| } | ||
|
|
||
| if (options.filteredTargets.includes("hosting")) { | ||
| await ensure(needProjectId(options), hostingApiOrigin(), "hosting", true); |
There was a problem hiding this comment.
Nit: Do this in the prepare step for hosting instead.
There was a problem hiding this comment.
I think I have to keep it here. With deferred Hosting, the site may not exist yet, and this is where we check for it. I could (in theory) move this check inside one of the calls here, but... that's fighting about where a single line should go, and this seems okay-ish to me.
Maybe we should push this deferred Hosting logic deeper, but there's dependencies between products I'm unable to think about I'm sure.
Description
Ensures that the Firebase Hosting API (
firebasehosting.googleapis.com) is enabled on the target project(s) before deploying to Firebase Hosting or runninghosting:*CLI commands (hosting:channel:*,hosting:sites:*,hosting:clone,hosting:disable).Scenarios Tested
deploycommand.before()hook (src/commands/deploy.spec.ts) and Hostingpreparestep (src/deploy/hosting/prepare.spec.ts)hosting:clonesame-project and cross-project API enablement (src/commands/hosting-clone.spec.ts) andhosting:disable(src/commands/hosting-disable.spec.ts)Sample Commands