Skip to content

Commit

Permalink
feat(core): Register AngularFire and Angular versions with the JS SDK
Browse files Browse the repository at this point in the history
If the JS SDK has the `registerVersion` API, we should register the version of Angular and AngularFire.
  • Loading branch information
jamesdaniels committed Feb 2, 2020
1 parent 56df941 commit 6096c95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionToken, NgModule, Optional, NgZone } from '@angular/core';
import { InjectionToken, NgModule, Optional, NgZone, VERSION as NG_VERSION, Version, Inject, PLATFORM_ID } from '@angular/core';
import { auth, database, messaging, storage, firestore, functions } from 'firebase/app';
// @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
Expand Down Expand Up @@ -44,6 +44,8 @@ export class FirebaseApp {
remoteConfig: () => FirebaseRemoteConfig;
}

export const VERSION = new Version('ANGULARFIRE2_VERSION');

export function _firebaseAppFactory(options: FirebaseOptions, zone: NgZone, nameOrConfig?: string|FirebaseAppConfig|null) {
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
Expand Down Expand Up @@ -78,4 +80,10 @@ export class AngularFireModule {
]
}
}
constructor(@Inject(PLATFORM_ID) platformId:Object ) {
if (firebase.registerVersion) {
firebase.registerVersion('angularfire', VERSION.full, platformId.toString());
firebase.registerVersion('angular', NG_VERSION.full);
}
}
}
7 changes: 7 additions & 0 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ function replaceDynamicImportsForUMD() {
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>"));
}

function writeCoreVersion() {
writeFileSync('./dist/packages-dist/bundles/core.umd.js', readFileSync('./dist/packages-dist/bundles/core.umd.js', 'utf8').replace('ANGULARFIRE2_VERSION', VERSIONS.ANGULARFIRE2_VERSION));
writeFileSync('./dist/packages-dist/firebase.app.module.js', readFileSync('./dist/packages-dist/firebase.app.module.js', 'utf8').replace('ANGULARFIRE2_VERSION', VERSIONS.ANGULARFIRE2_VERSION));
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));
}

function measure(module) {
const path = `${process.cwd()}/dist/packages-dist/bundles/${module}.umd.js`;
const file = readFileSync(path);
Expand Down Expand Up @@ -408,6 +414,7 @@ function buildLibrary(globals) {
switchMap(() => from(createTestUmd(globals))),
tap(() => {
replaceDynamicImportsForUMD();
writeCoreVersion();
const coreStats = measure('core');
const analyticsStats = measure('analytics');
const authStats = measure('auth');
Expand Down

0 comments on commit 6096c95

Please sign in to comment.