Skip to content

Commit 6096c95

Browse files
committed
feat(core): Register AngularFire and Angular versions with the JS SDK
If the JS SDK has the `registerVersion` API, we should register the version of Angular and AngularFire.
1 parent 56df941 commit 6096c95

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/core/firebase.app.module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionToken, NgModule, Optional, NgZone } from '@angular/core';
1+
import { InjectionToken, NgModule, Optional, NgZone, VERSION as NG_VERSION, Version, Inject, PLATFORM_ID } from '@angular/core';
22
import { auth, database, messaging, storage, firestore, functions } from 'firebase/app';
33
// @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
44
import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
@@ -44,6 +44,8 @@ export class FirebaseApp {
4444
remoteConfig: () => FirebaseRemoteConfig;
4545
}
4646

47+
export const VERSION = new Version('ANGULARFIRE2_VERSION');
48+
4749
export function _firebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) {
4850
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
4951
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
@@ -78,4 +80,10 @@ export class AngularFireModule {
7880
]
7981
}
8082
}
83+
constructor(@Inject(PLATFORM_ID) platformId:Object ) {
84+
if (firebase.registerVersion) {
85+
firebase.registerVersion('angularfire', VERSION.full, platformId.toString());
86+
firebase.registerVersion('angular', NG_VERSION.full);
87+
}
88+
}
8189
}

tools/build.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ function replaceDynamicImportsForUMD() {
307307
writeFileSync('./dist/packages-dist/remote-config/remote-config.d.ts', readFileSync('./dist/packages-dist/remote-config/remote-config.d.ts', 'utf8').replace("implements remoteConfig.Value", "implements Partial<remoteConfig.Value>"));
308308
}
309309

310+
function writeCoreVersion() {
311+
writeFileSync('./dist/packages-dist/bundles/core.umd.js', readFileSync('./dist/packages-dist/bundles/core.umd.js', 'utf8').replace('ANGULARFIRE2_VERSION', VERSIONS.ANGULARFIRE2_VERSION));
312+
writeFileSync('./dist/packages-dist/firebase.app.module.js', readFileSync('./dist/packages-dist/firebase.app.module.js', 'utf8').replace('ANGULARFIRE2_VERSION', VERSIONS.ANGULARFIRE2_VERSION));
313+
writeFileSync('./dist/packages-dist/es2015/firebase.app.module.js', readFileSync('./dist/packages-dist/es2015/firebase.app.module.js', 'utf8').replace('ANGULARFIRE2_VERSION', VERSIONS.ANGULARFIRE2_VERSION));
314+
}
315+
310316
function measure(module) {
311317
const path = `${process.cwd()}/dist/packages-dist/bundles/${module}.umd.js`;
312318
const file = readFileSync(path);
@@ -408,6 +414,7 @@ function buildLibrary(globals) {
408414
switchMap(() => from(createTestUmd(globals))),
409415
tap(() => {
410416
replaceDynamicImportsForUMD();
417+
writeCoreVersion();
411418
const coreStats = measure('core');
412419
const analyticsStats = measure('analytics');
413420
const authStats = measure('auth');

0 commit comments

Comments
 (0)