Skip to content

feat(schematics): set up ng deploy in ng add for Hosting or App Hosting - #3851

Open
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:ng-add-deploy-setup
Open

armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:ng-add-deploy-setup

Conversation

@armando-navarro

Copy link
Copy Markdown
Collaborator

Checklist

  • Issue number for this PR: ng deploy infinite setup loop #3546, ng deploy still doesn't work #3676
  • Docs included?: no. The deploy guide and the Quickstart describe the released behavior, so their update goes in the docs pull request of the release that ships this.
  • Test units included?: yes, 212 new specs
  • Breaking change?: no. "Behavior to know" below lists what ng deploy does differently.
  • In a clean directory, yarn install, yarn test run successfully?: node specs yes (npm run build, then npm run build:jasmine && npm run test:node, 652 specs, 0 failures). The browser suite is left to CI.

Description

Fixes #3546
Fixes #3676

ng add @angular/fire has written no deploy target since 17.1.0 (#3524). On a new app, ng deploy finds no target, offers to run ng add @angular/fire, and exits without deploying. With this change ng add asks how to deploy and writes the target, so ng deploy works after it.

The new question in ng add

  • After the features question, ng add asks "How do you want to deploy this app?" with three answers: Firebase App Hosting, Firebase Hosting, or no deploy setup. --deploy=apphosting, --deploy=hosting or --deploy=none answers it without a prompt.
  • The question starts on App Hosting when the app uses server-side rendering, and on Hosting otherwise. On a later run it starts on what the app already deploys with.
  • Deployment can be set up with no feature selected. Before, ng add stopped when no feature was selected.
  • A deploy target that belongs to another builder is replaced only after the user agrees.

Firebase Hosting

  • ng add asks which Hosting site to use, or creates one.
  • It writes the deploy target with "version": 2 in angular.json, a hosting entry in firebase.json, and the site under targets in .firebaserc.
  • The hosting entry uploads the build's browser folder and serves the client-side page for every other URL, so the Angular router handles it. That page is index.html, or index.csr.html when the build prerenders or renders on a server.
  • An app that uses server-side rendering gets a warning from ng add and from ng deploy, because Hosting cannot run a server.
  • A build with localize set gets a warning from ng add, because it has no single index page.

Firebase App Hosting

  • ng add states what App Hosting needs (the Blaze pricing plan, its Terms of Service accepted, and the Owner or IAM Admin role for the first deploy to a region), then asks which backend to use, or creates one from an id and a region.
  • It writes the deploy target with "version": 2 and appHostingBackend in angular.json, and an apphosting entry in firebase.json.
  • ng deploy uploads the workspace to that backend, and App Hosting builds it in Google Cloud. Nothing is built locally, so --preview stops with an error.
  • A backend connected to a GitHub repository is used only after the user agrees, because uploading local files replaces what GitHub last rolled out.
  • App Hosting needs firebase-tools 15.9.0 or newer, the oldest version that reports a failed rollout as a failure. The minimum for everything else stays 14.0.0.
  • The regions offered for a new backend are a list in src/schematics/setup/appHostingRegions.ts, plus an entry for typing another one. npm run update-regions rewrites the list from the App Hosting API.

Behavior to know

  • When .firebaserc has the app's Hosting target under more than one Firebase project, ng deploy used to deploy to the first one listed, and a firebaseProject option that pointed at another one stopped with "in conflict". Now ng deploy deploys to firebaseProject when it is set, asks at a terminal, and with no terminal stops with an error that says how to set the option. An automated job with such a .firebaserc and no firebaseProject fails until the option is added.
  • ng deploy stops when a build fails. It used to go on to the deploy step.
  • ng deploy --preview prints a line that says to press Ctrl+C to stop the preview and choose whether to deploy.

Tests

  • 212 new specs cover the build option and .firebaserc readers, what ng add writes to angular.json, firebase.json and .firebaserc, the project choice in ng deploy, the App Hosting deploy, and whole ng add runs against a stand-in for firebase-tools with scripted answers.
  • I mutation-tested each new spec file and added specs for the surviving faults that an ordinary project can reach.
  • I ran the main paths for real against a Firebase project, with firebase-tools 15.28.1 and new Angular 22.3 apps: --deploy=none, Hosting with a new site and ng deploy, a second ng add that changed no file, App Hosting with a new backend and ng deploy, and a server-rendered app on Hosting with its warnings.
  • So that specs can load the code that asks questions, inquirer, fuzzy and jsonc-parser are imported in a form that also loads as an ES module, which is how the spec runner loads the schematics. The published schematics are bundled as CommonJS, as before.

Not in this pull request

  • A localized build on Hosting gets the warning only. Rewrites per locale are not written.
  • The firebaseProject option still does not accept a project alias, although its description says it does.
  • The Hosting site check in ng deploy is unchanged.

Refs #3077. Of the two things that issue reports, choosing between Firebase projects with firebaseProject works with this change when .firebaserc has the app's target under each project. A firebaseHostingSite that differs from .firebaserc still stops with "in conflict".

Planned for 22.1.0, with a cherry-pick onto 21.1.x. 22.0.0 will be released from a 22.0.x branch that does not include this change.

ng add has written no deploy target since 17.1.0, so ng deploy had
nothing to run until the user wrote the target by hand. ng add now asks
how to deploy, or takes --deploy, and writes the deploy entry in
angular.json with the matching entries in firebase.json and .firebaserc.

Firebase Hosting: pick or create a site. The entry serves the build's
client-side page. A server-rendered build gets a warning, since Hosting
cannot run a server, and so does a localized build, which has no single
index page.

Firebase App Hosting: pick or create a backend. ng deploy uploads the
workspace and App Hosting builds it. It needs firebase-tools 15.9.0, the
oldest version that reports a failed rollout as a failure.

When .firebaserc has the app's Hosting target under several Firebase
projects, ng deploy took the first one listed. It now uses the
firebaseProject option, asks at a terminal, or stops with instructions
when there is no terminal.

ng deploy now stops when the build fails. It used to go on and deploy.

inquirer, fuzzy and jsonc-parser are imported in a form that also loads
as an ES module, which is how the spec runner loads the schematics, so
specs can cover the code that asks questions.

Fixes angular#3546
Fixes angular#3676
@armando-navarro armando-navarro added backport: 21.1.x Cherry-pick onto the 21.1.x branch for a 21.1 minor release bump: minor Size of the change: a new capability with no breaking change comp: schematics ng add / deploy schematics (src/schematics). type: feature New capability or enhancement. labels Nov 25, 2026
@armando-navarro armando-navarro added this to the 22.1.0 milestone Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: 21.1.x Cherry-pick onto the 21.1.x branch for a 21.1 minor release bump: minor Size of the change: a new capability with no breaking change comp: schematics ng add / deploy schematics (src/schematics). type: feature New capability or enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng deploy still doesn't work ng deploy infinite setup loop

1 participant