Skip to content

Commit b34b218

Browse files
authored
feat(core): Upgrade to Firebase v9 & more (#2770)
* Support Firebase v9 * New API that Zone wraps Firebase JS SDK and rxfire * AngularFire v6 API lives on at `@angular/fire/compat/*` * Drop Angular versions less than 12 * Require Ivy
1 parent 3e991a6 commit b34b218

File tree

306 files changed

+22063
-8214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+22063
-8214
lines changed

.github/workflows/test.yml

+61-10
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
id: node_modules_cache
3030
with:
3131
path: ./node_modules
32-
key: ${{ runner.os }}-14-8-node_modules-${{ hashFiles('yarn.lock') }}
32+
key: ${{ runner.os }}-14-beta-node_modules-${{ hashFiles('yarn.lock') }}
3333
restore-keys: |
34-
${{ runner.os }}-14-8-node_modules-
34+
${{ runner.os }}-14-beta-node_modules-
3535
${{ runner.os }}-14-node_modules-
3636
- name: Yarn offline cache
3737
if: steps.node_modules_cache.outputs.cache-hit != 'true'
@@ -62,9 +62,9 @@ jobs:
6262
strategy:
6363
matrix:
6464
node: ["12", "14", "16"]
65-
firebase: ["7", "8"]
65+
firebase: ["beta"]
6666
fail-fast: false
67-
name: Test Firebase v${{ matrix.firebase }} on Node.js ${{ matrix.node }}
67+
name: Test firebase@${{ matrix.firebase }} on Node.js ${{ matrix.node }}
6868
steps:
6969
- name: Checkout
7070
uses: actions/checkout@v2
@@ -94,7 +94,7 @@ jobs:
9494
run: |
9595
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
9696
yarn install --frozen-lockfile --prefer-offline --ignore-engines
97-
yarn add firebase@^${{ matrix.firebase }}.0 --prefer-offline --ignore-engines
97+
yarn add firebase@${{ matrix.firebase }} --prefer-offline --ignore-engines
9898
- name: Firebase emulator cache
9999
uses: actions/cache@v2
100100
with:
@@ -110,10 +110,11 @@ jobs:
110110
headless:
111111
runs-on: ubuntu-latest
112112
needs: build
113-
name: Test Firebase v${{ matrix.firebase }} on Headless Chrome
113+
name: Test firebase@${{ matrix.firebase }} on ${{ matrix.browser }}
114114
strategy:
115115
matrix:
116-
firebase: ["7", "8"]
116+
firebase: ["beta"]
117+
browser: ["chrome", "firefox"]
117118
fail-fast: false
118119
steps:
119120
- name: Checkout
@@ -144,7 +145,7 @@ jobs:
144145
run: |
145146
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
146147
yarn install --frozen-lockfile --prefer-offline
147-
yarn add firebase@^${{ matrix.firebase }}.0 --prefer-offline
148+
yarn add firebase@${{ matrix.firebase }} --prefer-offline
148149
- name: Firebase emulator cache
149150
uses: actions/cache@v2
150151
with:
@@ -155,12 +156,62 @@ jobs:
155156
- name: Run tests
156157
run: |
157158
mv angularfire-${{ github.run_id }} dist
158-
yarn test:chrome-headless
159+
yarn test:${{ matrix.browser }}-headless
160+
161+
# safari:
162+
# runs-on: macos-latest
163+
# needs: build
164+
# name: Test firebase@${{ matrix.firebase }} on safari
165+
# strategy:
166+
# matrix:
167+
# firebase: ["beta"]
168+
# fail-fast: false
169+
# steps:
170+
# - name: Checkout
171+
# uses: actions/checkout@v2
172+
# - name: Setup node
173+
# uses: actions/setup-node@v2-beta
174+
# with:
175+
# node-version: '14'
176+
# check-latest: true
177+
# - name: node_modules cache
178+
# id: node_modules_cache
179+
# uses: actions/cache@v2
180+
# with:
181+
# path: ./node_modules
182+
# key: ${{ runner.os }}-14-${{ matrix.firebase }}-node_modules-${{ hashFiles('yarn.lock') }}
183+
# restore-keys: |
184+
# ${{ runner.os }}-14-${{ matrix.firebase }}-node_modules-
185+
# ${{ runner.os }}-14-node_modules-
186+
# - name: Yarn offline cache
187+
# if: steps.node_modules_cache.outputs.cache-hit != 'true'
188+
# uses: actions/cache@v2
189+
# with:
190+
# path: ~/.npm-packages-offline-cache
191+
# key: yarn-offline-${{ hashFiles('**/yarn.lock') }}
192+
# restore-keys: yarn-offline
193+
# - name: Install deps
194+
# if: steps.node_modules_cache.outputs.cache-hit != 'true'
195+
# run: |
196+
# yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
197+
# yarn install --frozen-lockfile --prefer-offline
198+
# yarn add firebase@${{ matrix.firebase }} --prefer-offline
199+
# - name: Firebase emulator cache
200+
# uses: actions/cache@v2
201+
# with:
202+
# path: ~/.cache/firebase/emulators
203+
# key: firebase_emulators
204+
# - name: 'Download Artifacts'
205+
# uses: actions/download-artifact@v2
206+
# - name: Run tests
207+
# run: |
208+
# mv angularfire-${{ github.run_id }} dist
209+
# yarn test:safari
159210

160211
publish:
161212
runs-on: ubuntu-latest
162213
name: Publish (NPM)
163-
needs: ['test', 'headless']
214+
needs: ['build', 'test', 'headless']
164215
if: ${{ github.ref == 'refs/heads/master' || github.event_name == 'release' }}
165216
steps:
166217
- name: Setup node

.gitignore

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ tools/build.js
1919
coverage
2020
*.log
2121
api-*.json
22-
src/**/base.ts
2322
angularfire.tgz
2423
unpack.sh
25-
publish.sh
24+
publish.sh
25+
26+
# auto-gen files
27+
src/compat/**/base.ts
28+
src/**/rxfire.ts
29+
src/**/firebase.ts

.npmignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
*.spec.*
22
test-config.*
3-
publish.sh
3+
publish.sh
4+
__ivy_ngcc__/
5+
*.min.js
6+
*.min.js.map
7+
*.__ivy_ngcc_bak

README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AngularFire
22
The official [Angular](https://angular.io/) library for [Firebase](https://firebase.google.com/).
33

4-
<strong><pre>ng add @angular/fire</pre></strong>
4+
<strong><pre>ng add @angular/fire@next</pre></strong>
55

66
AngularFire smooths over the rough edges an Angular developer might encounter when implementing the framework-agnostic [Firebase JS SDK](https://github.com/firebase/firebase-js-sdk) & aims to provide a more natural developer experience by conforming to Angular conventions.
77

@@ -14,13 +14,25 @@ AngularFire smooths over the rough edges an Angular developer might encounter wh
1414
- **Google Analytics** - Zero-effort Angular Router awareness in Google Analytics
1515
- **Router Guards** - Guard your Angular routes with built-in Firebase Authentication checks
1616

17+
---
18+
19+
> **WARNING**: This branch is the work in progress for version 7 of AngularFire. [You can find version 6 here](https://github.com/angular/angularfire/tree/v6), if you're looking for documentation or to contribute to stable.
20+
21+
---
22+
1723
## Example use
1824

1925
```ts
2026
import { Component } from '@angular/core';
21-
import { AngularFirestore } from '@angular/fire/firestore';
27+
import { Firestore, collectionData, collection } from '@angular/fire/firestore';
2228
import { Observable } from 'rxjs';
2329

30+
interface Item {
31+
id: string,
32+
name: string,
33+
...
34+
};
35+
2436
@Component({
2537
selector: 'app-root',
2638
template: `
@@ -32,9 +44,10 @@ import { Observable } from 'rxjs';
3244
`
3345
})
3446
export class MyApp {
35-
item$: Observable<any[]>;
36-
constructor(firestore: AngularFirestore) {
37-
this.item$ = firestore.collection('items').valueChanges();
47+
item$: Observable<Item[]>;
48+
constructor(firestore: Firestore) {
49+
const collection = collection(firestore, 'items');
50+
this.item$ = collectionData(collection, 'id');
3851
}
3952
}
4053
```
@@ -47,7 +60,7 @@ AngularFire doesn't follow Angular's versioning as Firebase also has breaking ch
4760

4861
| Angular | Firebase | AngularFire |
4962
| --------|----------|--------------|
50-
| 12 | [9 <sup>beta</sup>](https://firebase.google.com/docs/web/learn-more#modular-version) | [^7.0 <sup>beta</sup>](https://github.com/angular/angularfire/tree/exp) |
63+
| 12 | [9 <sup>beta</sup>](https://firebase.google.com/docs/web/learn-more#modular-version) | ^7.0 <sup>beta</sup> |
5164
| 12 | 7,8 | ^6.1.5 |
5265
| 11 | 7,8 | ^6.1 |
5366
| 10 | 8 | ^6.0.4 |
@@ -79,7 +92,7 @@ Neither AngularFire or Firebase ship with polyfills. To have compatability acros
7992

8093
[Stackblitz Template](https://stackblitz.com/edit/angular-fire-start) - Remember to set your Firebase configuration in `app/app.module.ts`.
8194

82-
[Upgrading to v6.0? Check out our guide.](docs/version-6-upgrade.md)
95+
[Upgrading to v7.0? Check out our guide.](docs/version-7-upgrade.md)
8396

8497
**Having troubles?** Get help on our [Q&A board](https://github.com/angular/angularfire/discussions?discussions_q=category%3AQ%26A), the official [Firebase Mailing List](https://groups.google.com/forum/#!forum/firebase-talk), the [Firebase Community Slack](https://firebase.community/) (`#angularfire2`), the [Angular Community Discord](http://discord.gg/angular) (`#firebase`), [Gitter](https://gitter.im/angular/angularfire2), the [Firebase subreddit](https://www.reddit.com/r/firebase), or [Stack Overflow](https://stackoverflow.com/questions/tagged/angularfire2).
8598

angular.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prefix": "angularfire",
1111
"architect": {
1212
"build": {
13-
"builder": "@angular-devkit/build-ng-packagr:build",
13+
"builder": "@angular-devkit/build-angular:ng-packagr",
1414
"options": {
1515
"tsConfig": "tsconfig.json",
1616
"project": "src/package.json"
@@ -41,6 +41,7 @@
4141
},
4242
"defaultProject": "angularfire",
4343
"cli": {
44+
"packageManager": "yarn",
4445
"analytics": "86795b8f-9036-4a53-929c-a7303453d677"
4546
}
4647
}

docs/analytics/getting-started.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CONFIG = InjectionToken<Config>;
2727
### Usage:
2828

2929
```ts
30-
import { AngularFireAnalyticsModule } from '@angular/fire/analytics';
30+
import { AngularFireAnalyticsModule } from '@angular/fire/compat/analytics';
3131

3232
@NgModule({
3333
imports: [
@@ -43,7 +43,7 @@ export class AppModule { }
4343
In your component you can then dependency inject `AngularFireAnalytics` and make calls against the SDK:
4444

4545
```ts
46-
import { AngularFireAnalytics } from '@angular/fire/analytics';
46+
import { AngularFireAnalytics } from '@angular/fire/compat/analytics';
4747

4848
constructor(analytics: AngularFireAnalytics) {
4949
analytics.logEvent('custom_event', { ... });
@@ -55,7 +55,7 @@ constructor(analytics: AngularFireAnalytics) {
5555
You can log [`screen_view` events](https://firebase.google.com/docs/reference/js/firebase.analytics.Analytics.html#parameters_10) yourself of course, but AngularFire provides the `ScreenTrackingService` which automatically integrates with the Angular Router to provide Firebase with screen view tracking. You simply can integrate like so:
5656

5757
```ts
58-
import { AngularFireAnalyticsModule, ScreenTrackingService } from '@angular/fire/analytics';
58+
import { AngularFireAnalyticsModule, ScreenTrackingService } from '@angular/fire/compat/analytics';
5959

6060
@NgModule({
6161
imports: [
@@ -77,7 +77,7 @@ To enrich your Analytics data you can track the currently signed in user by sett
7777

7878

7979
```ts
80-
import { AngularFireAnalyticsModule, UserTrackingService } from '@angular/fire/analytics';
80+
import { AngularFireAnalyticsModule, UserTrackingService } from '@angular/fire/compat/analytics';
8181

8282
@NgModule({
8383
imports: [
@@ -100,7 +100,7 @@ export class AppModule { }
100100
Using the `CONFIG` DI Token (*default: {}*) will allow you to configure Google Analytics. E.g, you could skip sending the initial `page_view` event, anonymize IP addresses, and disallow ads personalization signals for all events like so:
101101

102102
```ts
103-
import { AngularFireAnalyticsModule, CONFIG } from '@angular/fire/analytics';
103+
import { AngularFireAnalyticsModule, CONFIG } from '@angular/fire/compat/analytics';
104104

105105
@NgModule({
106106
imports: [

docs/auth/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the Firebase docs for more information on what methods are available.](https://f
1010

1111
```ts
1212
import { Component } from '@angular/core';
13-
import { AngularFireAuth } from '@angular/fire/auth';
13+
import { AngularFireAuth } from '@angular/fire/compat/auth';
1414
import firebase from 'firebase/app';
1515

1616
@Component({

docs/auth/router-guards.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
`AngularFireAuthGuard` provides a prebuilt [`canActivate` Router Guard](https://angular.io/api/router/CanActivate) using `AngularFireAuth`. By default unauthenticated users are not permitted to navigate to protected routes:
44

55
```ts
6-
import { AngularFireAuthGuard } from '@angular/fire/auth-guard';
6+
import { AngularFireAuthGuard } from '@angular/fire/compat/auth-guard';
77

88
export const routes: Routes = [
99
{ path: '', component: AppComponent },
@@ -29,7 +29,7 @@ The `auth-guard` module provides the following pre-built pipes:
2929
Example use:
3030

3131
```ts
32-
import { AngularFireAuthGuard, hasCustomClaim, redirectUnauthorizedTo, redirectLoggedInTo } from '@angular/fire/auth-guard';
32+
import { AngularFireAuthGuard, hasCustomClaim, redirectUnauthorizedTo, redirectLoggedInTo } from '@angular/fire/compat/auth-guard';
3333

3434
const adminOnly = () => hasCustomClaim('admin');
3535
const redirectUnauthorizedToLogin = () => redirectUnauthorizedTo(['login']);
@@ -48,7 +48,7 @@ export const routes: Routes = [
4848
Use the provided `canActivate` helper and spread syntax to make your routes more readable:
4949

5050
```ts
51-
import { canActivate } from '@angular/fire/auth-guard';
51+
import { canActivate } from '@angular/fire/compat/auth-guard';
5252

5353
export const routes: Routes = [
5454
{ path: '', component: AppComponent },
@@ -76,7 +76,7 @@ The `auth-guard` modules provides a `customClaims` operator to reduce boiler pla
7676
```ts
7777
import { pipe } from 'rxjs';
7878
import { map } from 'rxjs/operators';
79-
import { customClaims } from '@angular/fire/auth-guard';
79+
import { customClaims } from '@angular/fire/compat/auth-guard';
8080

8181
// This pipe will only allow users with the editor role to access the route
8282
// { path: 'articles/:id/edit', component: ArticleEditComponent, ...canActivate(editorOnly) }
@@ -90,7 +90,7 @@ const editorOnly = () => pipe(customClaims, map(claims => claims.role === 'edito
9090
```ts
9191
import { pipe } from 'rxjs';
9292
import { map } from 'rxjs/operators';
93-
import { customClaims } from '@angular/fire/auth-guard';
93+
import { customClaims } from '@angular/fire/compat/auth-guard';
9494

9595
// Only allow navigation to the route if :userId matches the authenticated user's uid
9696
// { path: 'user/:userId/edit', component: ProfileEditComponent, ...canActivate(onlyAllowSelf) }

docs/deploy/getting-started.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this guide, we'll look at how to use `@angular/fire` to automatically deploy
1111
First, you need to add the `@angular/fire` package to your project. In your Angular CLI project run:
1212

1313
```shell
14-
ng add @angular/fire
14+
ng add @angular/fire@next
1515
```
1616

1717
*Note that the command above assumes you have global Angular CLI installed. To install Angular CLI globally run `npm i -g @angular/cli`.*
@@ -53,7 +53,7 @@ In the end, your `angular.json` project will look like below:
5353
If you want to add deployment capabilities to a different project in your workspace, you can run:
5454

5555
```
56-
ng add @angular/fire --project=[PROJECT_NAME]
56+
ng add @angular/fire@next --project=[PROJECT_NAME]
5757
```
5858

5959
## Step 2: deploying the project

docs/emulators/emulators.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ Each module (database, firestore, auth, function) provides `USE_EMULATOR` token
6969
Import these tokens at your `app.module.ts` as follow:
7070

7171
```ts
72-
import { USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/auth';
73-
import { USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/database';
74-
import { USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/firestore';
75-
import { USE_EMULATOR as USE_FUNCTIONS_EMULATOR } from '@angular/fire/functions';
72+
import { USE_EMULATOR as USE_AUTH_EMULATOR } from '@angular/fire/compat/auth';
73+
import { USE_EMULATOR as USE_DATABASE_EMULATOR } from '@angular/fire/compat/database';
74+
import { USE_EMULATOR as USE_FIRESTORE_EMULATOR } from '@angular/fire/compat/firestore';
75+
import { USE_EMULATOR as USE_FUNCTIONS_EMULATOR } from '@angular/fire/compat/functions';
7676

7777
@NgModule({
7878
// ... Existing configuration
@@ -93,7 +93,7 @@ Also you can opt-in the new way of setting the Cloud Functions [origin](https://
9393

9494
```ts
9595
import { isDevMode, NgModule } from '@angular/core';
96-
import { ORIGIN as FUNCTIONS_ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angular/fire/functions';
96+
import { ORIGIN as FUNCTIONS_ORIGIN, NEW_ORIGIN_BEHAVIOR } from '@angular/fire/compat/functions';
9797

9898
@NgModule({
9999
// ... Existing configuration
@@ -111,9 +111,9 @@ export class AppModule { }
111111
With the exception of the Auth Emulator, the old way of setting the `host` and `port` for each emulator was done using a different set of tokens by passing the entire url path as string.
112112

113113
```ts
114-
import { URL as DATABASE_URL } from '@angular/fire/database';
115-
import { ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/functions';
116-
import { SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';
114+
import { URL as DATABASE_URL } from '@angular/fire/compat/database';
115+
import { ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/compat/functions';
116+
import { SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/compat/firestore';
117117

118118
@NgModule({
119119
// ... Existing configuration

0 commit comments

Comments
 (0)