Skip to content

Commit af238cd

Browse files
fix(core): proxy-polyfill support and various other small fixes (#2633)
* Make PerformanceMonitoringService tree-shakable * Shouldn't need to but await AgnularFirePerformance/Analytics to make them eager * Support proxy-polyfill on the lazy classes by adding the methods to prototype at build-time (via `ts-transformer-keys`) * Use indexOf > -1 rather than includes, so another polyfill isnt needed * Adding logger/compat to the cloud function genreator * npx not needed in package.json Co-authored-by: Alex <[email protected]>
1 parent c29eb2d commit af238cd

25 files changed

+163
-133
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ test/ng-build/**/yarn.lock
1818
tools/build.js
1919
coverage
2020
*.log
21-
api-*.json
21+
api-*.json
22+
src/**/base.ts

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "@angular/fire",
3-
"version": "6.0.4",
3+
"version": "6.0.5",
44
"description": "The official library of Firebase and Angular.",
55
"private": true,
66
"scripts": {
77
"test": "npm run test:node",
8-
"test:watch": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=true --browsers=Chrome\"",
9-
"test:chrome": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=false --browsers=Chrome\"",
10-
"test:chrome-headless": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=false --browsers=ChromeHeadless\"",
11-
"lint": "npx ng lint",
12-
"test:node": "npx tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics && npx firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",
8+
"test:watch": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=true --browsers=Chrome\"",
9+
"test:chrome": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=Chrome\"",
10+
"test:chrome-headless": "firebase emulators:exec --project=angularfire2-test \"ng test --watch=false --browsers=ChromeHeadless\"",
11+
"lint": "ng lint",
12+
"test:node": "tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics && firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",
1313
"test:typings": "node ./tools/run-typings-test.js",
1414
"test:build": "bash ./test/ng-build/build.sh",
1515
"test:all": "npm run test:node && npm run test:chrome-headless && npm run test:typings && npm run test:build",
16-
"build": "tsc tools/build.ts; node ./tools/build.js",
16+
"build": "ttsc -p tsconfig.build.json; node ./tools/build.js",
1717
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
1818
},
1919
"husky": {
@@ -110,9 +110,11 @@
110110
"systemjs": "^0.19.16",
111111
"systemjs-builder": "^0.15.7",
112112
"traceur": "0.0.96",
113+
"ts-transformer-keys": "^0.4.2",
113114
"tsconfig-paths": "^3.8.0",
114115
"tsickle": "^0.39.1",
115116
"tslint": "~6.1.0",
117+
"ttypescript": "^1.5.12",
116118
"typedoc": "^0.16.4",
117119
"typescript": "~3.9.7"
118120
},

sample/.browserslistrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
last 2 versions
1010
Firefox ESR
1111
not dead
12-
not IE 9-11 # For IE 9-11 support, remove 'not'.
12+
not IE 9-10
13+
IE 11

sample/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"build": "ng build",
88
"test": "ng test",
99
"lint": "ng lint",
10+
"deploy": "ng deploy",
1011
"dev:ssr": "ng run sample:serve-ssr",
12+
"bust": "rm -rf node_modules/@angular/fire && yarn cache clean @angular/fire && yarn add ../dist/packages-dist",
1113
"serve:ssr": "node dist/sample/server/main.js",
1214
"build:ssr": "ng build --prod && ng run sample:server:production",
1315
"prerender": "ng run sample:prerender"
@@ -26,11 +28,13 @@
2628
"@angular/router": "~10.2.1",
2729
"@angular/service-worker": "^10.2.1",
2830
"@nguniversal/express-engine": "~10.1.0",
31+
"core-js": "^3.6.5",
2932
"firebase": "^8.0.0",
3033
"first-input-delay": "^0.1.3",
3134
"proxy-polyfill": "^0.3.2",
3235
"rxjs": "~6.6.3",
3336
"tslib": "^2.0.1",
37+
"whatwg-fetch": "^3.4.1",
3438
"zone.js": "0.10.3"
3539
},
3640
"devDependencies": {
@@ -65,4 +69,4 @@
6569
"tslint": "~6.1.3",
6670
"typescript": "~3.9.7"
6771
}
68-
}
72+
}

sample/src/app/app.module.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ServiceWorkerModule } from '@angular/service-worker';
77
import { environment } from '../environments/environment';
88

99
import { AngularFireModule } from '@angular/fire';
10-
import { AngularFireStorageModule } from '@angular/fire/storage';
1110

1211
import {
1312
AngularFireAnalyticsModule,
@@ -17,13 +16,13 @@ import {
1716
} from '@angular/fire/analytics';
1817

1918
import { FirestoreComponent } from './firestore/firestore.component';
20-
2119
import { AngularFireDatabaseModule, URL as DATABASE_URL } from '@angular/fire/database';
22-
import { AngularFireAuthModule } from '@angular/fire/auth';
2320
import { AngularFirestoreModule, SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';
21+
import { AngularFireStorageModule } from '@angular/fire/storage';
22+
import { AngularFireAuthModule } from '@angular/fire/auth';
2423
import { AngularFireMessagingModule } from '@angular/fire/messaging';
2524
import { AngularFireFunctionsModule, ORIGIN as FUNCTIONS_ORIGIN } from '@angular/fire/functions';
26-
import { AngularFireRemoteConfigModule, SETTINGS as REMOTE_CONFIG_SETTINGS } from '@angular/fire/remote-config';
25+
import { AngularFireRemoteConfigModule, SETTINGS as REMOTE_CONFIG_SETTINGS, DEFAULTS as REMOTE_CONFIG_DEFAULTS } from '@angular/fire/remote-config';
2726
import { AngularFirePerformanceModule, PerformanceMonitoringService } from '@angular/fire/performance';
2827
import { AngularFireAuthGuardModule } from '@angular/fire/auth-guard';
2928
import { DatabaseComponent } from './database/database.component';
@@ -53,31 +52,35 @@ const shouldUseEmulator = () => false;
5352
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }),
5453
AngularFireModule.initializeApp(environment.firebase),
5554
AngularFireStorageModule,
56-
AngularFireAnalyticsModule,
57-
AngularFireAuthModule,
5855
AngularFireDatabaseModule,
5956
AngularFirestoreModule.enablePersistence({ synchronizeTabs: true }),
57+
AngularFireAuthModule,
58+
AngularFireRemoteConfigModule,
6059
AngularFireMessagingModule,
60+
// AngularFireAnalyticsModule, // TODO having trouble getting this to work in IE
6161
AngularFireFunctionsModule,
62-
AngularFireRemoteConfigModule,
63-
AngularFirePerformanceModule,
62+
// AngularFirePerformanceModule, // TODO having trouble getting this to work in IE
6463
AngularFireAuthGuardModule
6564
],
6665
providers: [
67-
UserTrackingService,
68-
ScreenTrackingService,
69-
PerformanceMonitoringService,
70-
{
71-
provide: ANALYTICS_DEBUG_MODE,
72-
useFactory: () => isDevMode()
73-
},
66+
/*
67+
TODO Analytics and Performance monitoring aren't working in IE, sort this out
68+
UserTrackingService,
69+
ScreenTrackingService,
70+
PerformanceMonitoringService,
71+
{
72+
provide: ANALYTICS_DEBUG_MODE,
73+
useFactory: () => isDevMode()
74+
},
75+
*/
7476
{
7577
provide: DATABASE_URL,
7678
useFactory: () => shouldUseEmulator() ? `http://localhost:9000?ns=${environment.firebase.projectId}` : undefined
7779
},
7880
{ provide: FIRESTORE_SETTINGS, useFactory: () => shouldUseEmulator() ? { host: 'localhost:8080', ssl: false } : {} },
7981
{ provide: FUNCTIONS_ORIGIN, useFactory: () => shouldUseEmulator() ? 'http://localhost:9999' : undefined },
80-
{ provide: REMOTE_CONFIG_SETTINGS, useFactory: () => isDevMode() ? { minimumFetchIntervalMillis: 10_000 } : {} }
82+
{ provide: REMOTE_CONFIG_SETTINGS, useFactory: () => isDevMode() ? { minimumFetchIntervalMillis: 10_000 } : {} },
83+
{ provide: REMOTE_CONFIG_DEFAULTS, useValue: { background_color: 'red' } },
8184
],
8285
bootstrap: [AppComponent]
8386
})

sample/src/app/database/database.component.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
22
import { AngularFireDatabase } from '@angular/fire/database';
3-
import { Observable } from 'rxjs';
3+
import { EMPTY, Observable } from 'rxjs';
44
import { makeStateKey, TransferState } from '@angular/platform-browser';
55
import { startWith, tap } from 'rxjs/operators';
66
import { trace } from '@angular/fire/performance';
7+
import { isPlatformServer } from '@angular/common';
78

89
@Component({
910
selector: 'app-database',
@@ -19,14 +20,19 @@ export class DatabaseComponent implements OnInit {
1920

2021
public readonly testObjectValue$: Observable<any>;
2122

22-
constructor(state: TransferState, database: AngularFireDatabase) {
23-
const doc = database.object('test');
24-
const key = makeStateKey(doc.query.toString());
25-
const existing = state.get(key, undefined);
26-
this.testObjectValue$ = doc.valueChanges().pipe(
27-
trace('database'),
28-
existing ? startWith(existing) : tap(it => state.set(key, it))
29-
);
23+
constructor(state: TransferState, database: AngularFireDatabase, @Inject(PLATFORM_ID) platformId: object) {
24+
// TODO fix the Zone.js issue with AngularFireDatabase
25+
if (isPlatformServer(platformId)) {
26+
this.testObjectValue$ = EMPTY;
27+
} else {
28+
const doc = database.object('test');
29+
const key = makeStateKey(doc.query.toString());
30+
const existing = state.get(key, undefined);
31+
this.testObjectValue$ = doc.valueChanges().pipe(
32+
trace('database'),
33+
existing ? startWith(existing) : tap(it => state.set(key, it))
34+
);
35+
}
3036
}
3137

3238
ngOnInit(): void {

sample/src/app/home/home.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { FirebaseApp } from '@angular/fire';
88
{{ firebaseApp.name }}
99
<app-database></app-database>
1010
<app-firestore></app-firestore>
11-
<app-remote-config></app-remote-config>
1211
<app-storage></app-storage>
1312
<app-auth></app-auth>
14-
<app-messaging></app-messaging>
13+
<app-remote-config></app-remote-config>
14+
<!-- TODO get working with Firebase 8 <app-messaging></app-messaging>-->
1515
`,
1616
styles: [``]
1717
})

sample/src/app/messaging/messaging.component.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class MessagingComponent implements OnInit {
2626

2727
constructor(public readonly messaging: AngularFireMessaging, readonly swpush: SwPush) {
2828
swpush.messages.subscribe(it => console.log('swpush', it));
29+
/*
30+
TODO get this sorted back out with Firebase 8
2931
messaging.usePublicVapidKey(environment.vapidKey).then(async () => {
3032
if (navigator && navigator.serviceWorker) {
3133
const registration = await navigator.serviceWorker.getRegistration();
@@ -38,7 +40,7 @@ export class MessagingComponent implements OnInit {
3840
trace('token'),
3941
tap(token => this.showRequest = !token)
4042
);
41-
});
43+
});*/
4244
}
4345

4446
ngOnInit(): void {

sample/src/polyfills.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
2222
// import 'classlist.js'; // Run `npm install --save classlist.js`.
2323

24+
import 'proxy-polyfill/proxy.min.js';
25+
import 'core-js/stable';
26+
import 'whatwg-fetch';
27+
2428
/**
2529
* Web Animations `@angular/platform-browser/animations`
2630
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
@@ -61,5 +65,3 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
6165
/***************************************************************************************************
6266
* APPLICATION IMPORTS
6367
*/
64-
65-
import 'proxy-polyfill/proxy.min.js';

sample/yarn.lock

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
tslib "^2.0.0"
225225

226226
"@angular/fire@../dist/packages-dist":
227-
version "6.0.3"
227+
version "6.0.5"
228228
dependencies:
229229
tslib "^2.0.0"
230230

@@ -3954,7 +3954,7 @@ [email protected]:
39543954
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.4.tgz#440a83536b458114b9cb2ac1580ba377dc470647"
39553955
integrity sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw==
39563956

3957-
3957+
[email protected], core-js@^3.6.5:
39583958
version "3.6.5"
39593959
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
39603960
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
@@ -12577,6 +12577,11 @@ [email protected]:
1257712577
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
1257812578
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==
1257912579

12580+
whatwg-fetch@^3.4.1:
12581+
version "3.4.1"
12582+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.4.1.tgz#e5f871572d6879663fa5674c8f833f15a8425ab3"
12583+
integrity sha512-sofZVzE1wKwO+EYPbWfiwzaKovWiZXf4coEzjGP9b2GBVgQRLQUZ2QcuPpQExGDAW5GItpEm6Tl4OU5mywnAoQ==
12584+
1258012585
whatwg-mimetype@^2.3.0:
1258112586
version "2.3.0"
1258212587
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"

sample/~ngcc.config.js

-76
This file was deleted.

src/analytics/analytics.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export class AngularFireAnalyticsModule {
1313
) {
1414
// calling anything on analytics will eagerly load the SDK
1515
// tslint:disable-next-line:no-unused-expression
16-
analytics.app;
16+
analytics.app.then(() => {});
1717
}
1818
}

src/analytics/analytics.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import {
1010
FIREBASE_OPTIONS,
1111
FIREBASE_APP_NAME,
1212
ɵfirebaseAppFactory,
13-
ɵPromiseProxy
13+
ɵPromiseProxy,
14+
ɵapplyMixins
1415
} from '@angular/fire';
1516
import firebase from 'firebase/app';
17+
import { proxyPolyfillCompat } from './base';
1618

1719
export interface Config {
1820
[key: string]: any;
@@ -127,3 +129,5 @@ export class AngularFireAnalytics {
127129
}
128130

129131
}
132+
133+
ɵapplyMixins(AngularFireAnalytics, [proxyPolyfillCompat]);

0 commit comments

Comments
 (0)