From 4d322f9e6681a5c8a84558684d4f9b1d565d96ae Mon Sep 17 00:00:00 2001 From: robertIsaac Date: Tue, 14 May 2024 18:34:38 +0300 Subject: [PATCH] feat: provide real standalone providers (#3503) * feat: provide real standalone providers usage before `importProvidersFrom(provideFirebaseApp(() => initializeApp(...)))` usage now `provideFirebaseApp(() => initializeApp(...))` * test: fixed failed tests * fix: update the missed lite.module.ts --- src/analytics/analytics.module.ts | 33 +++++++++++++++++------ src/analytics/analytics.spec.ts | 2 +- src/app-check/app-check.module.ts | 26 +++++++++++++----- src/app-check/app-check.spec.ts | 2 +- src/app/app.module.ts | 22 ++++++++++----- src/app/app.spec.ts | 2 +- src/auth-guard/auth-guard.spec.ts | 12 ++++----- src/auth/auth.module.ts | 24 ++++++++++++----- src/auth/auth.spec.ts | 2 +- src/database/database.module.ts | 24 ++++++++++++----- src/database/database.spec.ts | 2 +- src/firestore/firestore.module.ts | 25 ++++++++++++----- src/firestore/firestore.spec.ts | 2 +- src/firestore/lite/lite.module.ts | 25 ++++++++++++----- src/firestore/lite/lite.spec.ts | 2 +- src/functions/functions.module.ts | 25 ++++++++++++----- src/functions/functions.spec.ts | 2 +- src/messaging/messaging.module.ts | 30 ++++++++++++++++----- src/messaging/messaging.spec.ts | 2 +- src/performance/performance.module.ts | 26 +++++++++++++----- src/performance/performance.spec.ts | 2 +- src/remote-config/remote-config.module.ts | 31 ++++++++++++++++----- src/remote-config/remote-config.spec.ts | 2 +- src/storage/storage.module.ts | 25 ++++++++++++----- src/storage/storage.spec.ts | 2 +- 25 files changed, 249 insertions(+), 103 deletions(-) diff --git a/src/analytics/analytics.module.ts b/src/analytics/analytics.module.ts index d688a44b5..52249a40c 100644 --- a/src/analytics/analytics.module.ts +++ b/src/analytics/analytics.module.ts @@ -1,4 +1,13 @@ -import { APP_INITIALIZER, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + APP_INITIALIZER, + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { Analytics as FirebaseAnalytics } from 'firebase/analytics'; @@ -60,10 +69,18 @@ export class AnalyticsModule { } } -export function provideAnalytics(fn: (injector: Injector) => FirebaseAnalytics, ...deps: any[]): ModuleWithProviders { - return { - ngModule: AnalyticsModule, - providers: [{ +export function provideAnalytics(fn: (injector: Injector) => FirebaseAnalytics, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'analytics'); + + return makeEnvironmentProviders([ + DEFAULT_ANALYTICS_INSTANCE_PROVIDER, + ANALYTICS_INSTANCES_PROVIDER, + { + provide: APP_INITIALIZER, + useValue: isAnalyticsSupportedFactory.async, + multi: true, + }, + { provide: PROVIDED_ANALYTICS_INSTANCES, useFactory: analyticsInstanceFactory(fn), multi: true, @@ -73,7 +90,7 @@ export function provideAnalytics(fn: (injector: Injector) => FirebaseAnalytics, ɵAngularFireSchedulers, FirebaseApps, ...deps, - ] - }] - }; + ], + }, + ]); } diff --git a/src/analytics/analytics.spec.ts b/src/analytics/analytics.spec.ts index d27f9886e..9101059ca 100644 --- a/src/analytics/analytics.spec.ts +++ b/src/analytics/analytics.spec.ts @@ -23,7 +23,7 @@ describe('Analytics', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG_TOO, appName)), provideAnalytics(() => { providedAnalytics = getAnalytics(getApp(appName)); diff --git a/src/app-check/app-check.module.ts b/src/app-check/app-check.module.ts index a09b99607..324d7f821 100644 --- a/src/app-check/app-check.module.ts +++ b/src/app-check/app-check.module.ts @@ -1,5 +1,15 @@ import { isPlatformServer } from '@angular/common'; -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional, PLATFORM_ID, isDevMode } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + PLATFORM_ID, + isDevMode, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAPP_CHECK_PROVIDER_NAME, ɵAngularFireSchedulers, ɵAppCheckInstances, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { registerVersion } from 'firebase/app'; @@ -56,10 +66,12 @@ export class AppCheckModule { } } -export function provideAppCheck(fn: (injector: Injector) => FirebaseAppCheck, ...deps: any[]): ModuleWithProviders { - return { - ngModule: AppCheckModule, - providers: [{ +export function provideAppCheck(fn: (injector: Injector) => FirebaseAppCheck, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'app-check'); + return makeEnvironmentProviders([ + DEFAULT_APP_CHECK_INSTANCE_PROVIDER, + APP_CHECK_INSTANCES_PROVIDER, + { provide: PROVIDED_APP_CHECK_INSTANCES, useFactory: appCheckInstanceFactory(fn), multi: true, @@ -71,6 +83,6 @@ export function provideAppCheck(fn: (injector: Injector) => FirebaseAppCheck, .. FirebaseApps, ...deps, ] - }] - }; + } + ]); } diff --git a/src/app-check/app-check.spec.ts b/src/app-check/app-check.spec.ts index 80aab5e63..b51e91e0e 100644 --- a/src/app-check/app-check.spec.ts +++ b/src/app-check/app-check.spec.ts @@ -15,7 +15,7 @@ describe('Auth', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideAuth(() => { providedAuth = getAuth(getApp(appName)); diff --git a/src/app/app.module.ts b/src/app/app.module.ts index aca94cea4..c7b402c10 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,13 +1,14 @@ import { + EnvironmentProviders, Inject, InjectionToken, Injector, - ModuleWithProviders, VERSION as NG_VERSION, NgModule, NgZone, Optional, PLATFORM_ID, + makeEnvironmentProviders, } from '@angular/core'; import { VERSION, ɵAngularFireSchedulers } from '@angular/fire'; import { FirebaseApp as IFirebaseApp, getApp, registerVersion } from 'firebase/app'; @@ -44,6 +45,12 @@ const FIREBASE_APPS_PROVIDER = { export function firebaseAppFactory(fn: (injector: Injector) => IFirebaseApp) { return (zone: NgZone, injector: Injector) => { + const platformId = injector.get(PLATFORM_ID); + registerVersion('angularfire', VERSION.full, 'core'); + registerVersion('angularfire', VERSION.full, 'app'); + // eslint-disable-next-line @typescript-eslint/no-base-to-string + registerVersion('angular', NG_VERSION.full, platformId.toString()); + const app = zone.runOutsideAngular(() => fn(injector)); return new FirebaseApp(app); }; @@ -68,10 +75,11 @@ export class FirebaseAppModule { // Calling initializeApp({ ... }, 'name') multiple times will add more FirebaseApps into the FIREBASE_APPS // injection scope. This allows developers to more easily work with multiple Firebase Applications. Downside // is that DI for app name and options doesn't really make sense anymore. -export function provideFirebaseApp(fn: (injector: Injector) => IFirebaseApp, ...deps: any[]): ModuleWithProviders { - return { - ngModule: FirebaseAppModule, - providers: [{ +export function provideFirebaseApp(fn: (injector: Injector) => IFirebaseApp, ...deps: any[]): EnvironmentProviders { + return makeEnvironmentProviders([ + DEFAULT_FIREBASE_APP_PROVIDER, + FIREBASE_APPS_PROVIDER, + { provide: PROVIDED_FIREBASE_APPS, useFactory: firebaseAppFactory(fn), multi: true, @@ -81,6 +89,6 @@ export function provideFirebaseApp(fn: (injector: Injector) => IFirebaseApp, ... ɵAngularFireSchedulers, ...deps, ], - }], - }; + } + ]) } diff --git a/src/app/app.spec.ts b/src/app/app.spec.ts index d600032ed..62af613f8 100644 --- a/src/app/app.spec.ts +++ b/src/app/app.spec.ts @@ -13,7 +13,7 @@ describe('FirebaseApp', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => { providedApp = initializeApp(COMMON_CONFIG, appName); return providedApp; diff --git a/src/auth-guard/auth-guard.spec.ts b/src/auth-guard/auth-guard.spec.ts index b26203e29..9c87a3fd3 100644 --- a/src/auth-guard/auth-guard.spec.ts +++ b/src/auth-guard/auth-guard.spec.ts @@ -17,18 +17,18 @@ describe('AuthGuard', () => { appName = rando(); TestBed.configureTestingModule({ imports: [ - provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), - provideAuth(() => { - const auth = getAuth(getApp(appName)); - connectAuthEmulator(auth, 'http://localhost:9098'); - return auth; - }), AuthGuardModule, RouterModule.forRoot([ { path: 'a', component: TestComponent, canActivate: [AuthGuard] } ]) ], providers: [ + provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), + provideAuth(() => { + const auth = getAuth(getApp(appName)); + connectAuthEmulator(auth, 'http://localhost:9098'); + return auth; + }), { provide: APP_BASE_HREF, useValue: 'http://localhost:4200/' } ] }); diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 6c07b32e6..5951a823c 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { ɵAppCheckInstances } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; @@ -48,10 +56,12 @@ export class AuthModule { } } -export function provideAuth(fn: (injector: Injector) => FirebaseAuth, ...deps: any[]): ModuleWithProviders { - return { - ngModule: AuthModule, - providers: [{ +export function provideAuth(fn: (injector: Injector) => FirebaseAuth, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'auth'); + return makeEnvironmentProviders([ + DEFAULT_AUTH_INSTANCE_PROVIDER, + AUTH_INSTANCES_PROVIDER, + { provide: PROVIDED_AUTH_INSTANCES, useFactory: authInstanceFactory(fn), multi: true, @@ -63,6 +73,6 @@ export function provideAuth(fn: (injector: Injector) => FirebaseAuth, ...deps: a [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/auth/auth.spec.ts b/src/auth/auth.spec.ts index 29d8c5749..83a4dd23a 100644 --- a/src/auth/auth.spec.ts +++ b/src/auth/auth.spec.ts @@ -15,7 +15,7 @@ describe('Auth', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideAuth(() => { providedAuth = getAuth(getApp(appName)); diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 4a372a890..7de415c38 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { ɵAppCheckInstances } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; @@ -49,10 +57,12 @@ export class DatabaseModule { } } -export function provideDatabase(fn: (injector: Injector) => FirebaseDatabase, ...deps: any[]): ModuleWithProviders { - return { - ngModule: DatabaseModule, - providers: [{ +export function provideDatabase(fn: (injector: Injector) => FirebaseDatabase, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'rtdb'); + return makeEnvironmentProviders([ + DEFAULT_DATABASE_INSTANCE_PROVIDER, + DATABASE_INSTANCES_PROVIDER, + { provide: PROVIDED_DATABASE_INSTANCES, useFactory: databaseInstanceFactory(fn), multi: true, @@ -66,6 +76,6 @@ export function provideDatabase(fn: (injector: Injector) => FirebaseDatabase, .. [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/database/database.spec.ts b/src/database/database.spec.ts index 85c1d0360..8c2575d05 100644 --- a/src/database/database.spec.ts +++ b/src/database/database.spec.ts @@ -15,7 +15,7 @@ describe('Database', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideDatabase(() => { providedDatabase = getDatabase(getApp(appName)); diff --git a/src/firestore/firestore.module.ts b/src/firestore/firestore.module.ts index 4eccebf2a..567f329bb 100644 --- a/src/firestore/firestore.module.ts +++ b/src/firestore/firestore.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { ɵAppCheckInstances } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; @@ -49,10 +57,13 @@ export class FirestoreModule { } } -export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, ...deps: any[]): ModuleWithProviders { - return { - ngModule: FirestoreModule, - providers: [{ +export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'fst'); + + return makeEnvironmentProviders([ + DEFAULT_FIRESTORE_INSTANCE_PROVIDER, + FIRESTORE_INSTANCES_PROVIDER, + { provide: PROVIDED_FIRESTORE_INSTANCES, useFactory: firestoreInstanceFactory(fn), multi: true, @@ -66,6 +77,6 @@ export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/firestore/firestore.spec.ts b/src/firestore/firestore.spec.ts index 063f36a49..0a720d364 100644 --- a/src/firestore/firestore.spec.ts +++ b/src/firestore/firestore.spec.ts @@ -15,7 +15,7 @@ describe('Firestore', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideFirestore(() => { providedFirestore = getFirestore(getApp(appName)); diff --git a/src/firestore/lite/lite.module.ts b/src/firestore/lite/lite.module.ts index 3923b3e25..f191cbcef 100644 --- a/src/firestore/lite/lite.module.ts +++ b/src/firestore/lite/lite.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵAppCheckInstances, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { AuthInstances } from '@angular/fire/auth'; @@ -48,10 +56,13 @@ export class FirestoreModule { } } -export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, ...deps: any[]): ModuleWithProviders { - return { - ngModule: FirestoreModule, - providers: [{ +export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'lite'); + + return makeEnvironmentProviders([ + DEFAULT_FIRESTORE_INSTANCE_PROVIDER, + FIRESTORE_INSTANCES_PROVIDER, + { provide: PROVIDED_FIRESTORE_INSTANCES, useFactory: firestoreInstanceFactory(fn), multi: true, @@ -65,6 +76,6 @@ export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore, [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/firestore/lite/lite.spec.ts b/src/firestore/lite/lite.spec.ts index c69c819c8..8d27add24 100644 --- a/src/firestore/lite/lite.spec.ts +++ b/src/firestore/lite/lite.spec.ts @@ -15,7 +15,7 @@ describe('Firestore-lite', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideFirestore(() => { providedFirestore = getFirestore(getApp(appName)); diff --git a/src/functions/functions.module.ts b/src/functions/functions.module.ts index cad0fe5cc..044a65dc7 100644 --- a/src/functions/functions.module.ts +++ b/src/functions/functions.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { ɵAppCheckInstances } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; @@ -49,10 +57,13 @@ export class FunctionsModule { } } -export function provideFunctions(fn: (injector: Injector) => FirebaseFunctions, ...deps: any[]): ModuleWithProviders { - return { - ngModule: FunctionsModule, - providers: [{ +export function provideFunctions(fn: (injector: Injector) => FirebaseFunctions, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'fn'); + + return makeEnvironmentProviders([ + DEFAULT_FUNCTIONS_INSTANCE_PROVIDER, + FUNCTIONS_INSTANCES_PROVIDER, + { provide: PROVIDED_FUNCTIONS_INSTANCES, useFactory: functionsInstanceFactory(fn), multi: true, @@ -66,6 +77,6 @@ export function provideFunctions(fn: (injector: Injector) => FirebaseFunctions, [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/functions/functions.spec.ts b/src/functions/functions.spec.ts index 17fffbcbc..7bc802b55 100644 --- a/src/functions/functions.spec.ts +++ b/src/functions/functions.spec.ts @@ -15,7 +15,7 @@ describe('Functions', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideFunctions(() => { providedFunctions = getFunctions(getApp(appName)); diff --git a/src/messaging/messaging.module.ts b/src/messaging/messaging.module.ts index dc001bb99..619542160 100644 --- a/src/messaging/messaging.module.ts +++ b/src/messaging/messaging.module.ts @@ -1,4 +1,12 @@ -import { APP_INITIALIZER, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + APP_INITIALIZER, EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { registerVersion } from 'firebase/app'; @@ -55,10 +63,18 @@ export class MessagingModule { } } -export function provideMessaging(fn: (injector: Injector) => FirebaseMessaging, ...deps: any[]): ModuleWithProviders { - return { - ngModule: MessagingModule, - providers: [{ +export function provideMessaging(fn: (injector: Injector) => FirebaseMessaging, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'fcm'); + + return makeEnvironmentProviders([ + DEFAULT_MESSAGING_INSTANCE_PROVIDER, + MESSAGING_INSTANCES_PROVIDER, + { + provide: APP_INITIALIZER, + useValue: isMessagingSupportedFactory.async, + multi: true, + }, + { provide: PROVIDED_MESSAGING_INSTANCES, useFactory: messagingInstanceFactory(fn), multi: true, @@ -69,6 +85,6 @@ export function provideMessaging(fn: (injector: Injector) => FirebaseMessaging, FirebaseApps, ...deps, ], - }] - }; + } + ]); } diff --git a/src/messaging/messaging.spec.ts b/src/messaging/messaging.spec.ts index 5561a7006..e10972630 100644 --- a/src/messaging/messaging.spec.ts +++ b/src/messaging/messaging.spec.ts @@ -22,7 +22,7 @@ describe('Messaging', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideMessaging(() => { providedMessaging = getMessaging(getApp(appName)); diff --git a/src/performance/performance.module.ts b/src/performance/performance.module.ts index be6eeeefe..9a08c520f 100644 --- a/src/performance/performance.module.ts +++ b/src/performance/performance.module.ts @@ -1,5 +1,14 @@ import { isPlatformBrowser } from '@angular/common'; -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional, PLATFORM_ID } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + PLATFORM_ID, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { registerVersion } from 'firebase/app'; @@ -59,10 +68,13 @@ export class PerformanceModule { export function providePerformance( fn: (injector: Injector) => FirebasePerformance, ...deps: any[] -): ModuleWithProviders { - return { - ngModule: PerformanceModule, - providers: [{ +): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'perf'); + + return makeEnvironmentProviders([ + DEFAULT_PERFORMANCE_INSTANCE_PROVIDER, + PERFORMANCE_INSTANCES_PROVIDER, + { provide: PROVIDED_PERFORMANCE_INSTANCES, useFactory: performanceInstanceFactory(fn), multi: true, @@ -74,6 +86,6 @@ export function providePerformance( FirebaseApps, ...deps, ] - }] - }; + } + ]); } diff --git a/src/performance/performance.spec.ts b/src/performance/performance.spec.ts index 54b4cf45d..e8264d941 100644 --- a/src/performance/performance.spec.ts +++ b/src/performance/performance.spec.ts @@ -12,7 +12,7 @@ describe('Performance', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG)), providePerformance(() => { providedPerformance = getPerformance(); diff --git a/src/remote-config/remote-config.module.ts b/src/remote-config/remote-config.module.ts index 702b666cb..d4b5514cb 100644 --- a/src/remote-config/remote-config.module.ts +++ b/src/remote-config/remote-config.module.ts @@ -1,4 +1,13 @@ -import { APP_INITIALIZER, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + APP_INITIALIZER, + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; import { registerVersion } from 'firebase/app'; @@ -60,10 +69,18 @@ export class RemoteConfigModule { export function provideRemoteConfig( fn: (injector: Injector) => FirebaseRemoteConfig, ...deps: any[] -): ModuleWithProviders { - return { - ngModule: RemoteConfigModule, - providers: [{ +): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'rc'); + + return makeEnvironmentProviders([ + DEFAULT_REMOTE_CONFIG_INSTANCE_PROVIDER, + REMOTE_CONFIG_INSTANCES_PROVIDER, + { + provide: APP_INITIALIZER, + useValue: isRemoteConfigSupportedFactory.async, + multi: true, + }, + { provide: PROVIDED_REMOTE_CONFIG_INSTANCES, useFactory: remoteConfigInstanceFactory(fn), multi: true, @@ -74,6 +91,6 @@ export function provideRemoteConfig( FirebaseApps, ...deps, ] - }] - }; + } + ]); } diff --git a/src/remote-config/remote-config.spec.ts b/src/remote-config/remote-config.spec.ts index 6912544f8..fd119e189 100644 --- a/src/remote-config/remote-config.spec.ts +++ b/src/remote-config/remote-config.spec.ts @@ -23,7 +23,7 @@ describe('RemoteConfig', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideRemoteConfig(() => { providedRemoteConfig = getRemoteConfig(getApp(appName)); diff --git a/src/storage/storage.module.ts b/src/storage/storage.module.ts index cc903a58f..0cc062f41 100644 --- a/src/storage/storage.module.ts +++ b/src/storage/storage.module.ts @@ -1,4 +1,12 @@ -import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core'; +import { + EnvironmentProviders, + InjectionToken, + Injector, + NgModule, + NgZone, + Optional, + makeEnvironmentProviders, +} from '@angular/core'; import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire'; import { ɵAppCheckInstances } from '@angular/fire'; import { FirebaseApp, FirebaseApps } from '@angular/fire/app'; @@ -49,10 +57,13 @@ export class StorageModule { } } -export function provideStorage(fn: (injector: Injector) => FirebaseStorage, ...deps: any[]): ModuleWithProviders { - return { - ngModule: StorageModule, - providers: [{ +export function provideStorage(fn: (injector: Injector) => FirebaseStorage, ...deps: any[]): EnvironmentProviders { + registerVersion('angularfire', VERSION.full, 'gcs'); + + return makeEnvironmentProviders([ + DEFAULT_STORAGE_INSTANCE_PROVIDER, + STORAGE_INSTANCES_PROVIDER, + { provide: PROVIDED_STORAGE_INSTANCES, useFactory: storageInstanceFactory(fn), multi: true, @@ -66,6 +77,6 @@ export function provideStorage(fn: (injector: Injector) => FirebaseStorage, ...d [new Optional(), ɵAppCheckInstances ], ...deps, ] - }] - }; + } + ]); } diff --git a/src/storage/storage.spec.ts b/src/storage/storage.spec.ts index 9d403b7df..b60331e8a 100644 --- a/src/storage/storage.spec.ts +++ b/src/storage/storage.spec.ts @@ -15,7 +15,7 @@ describe('Storage', () => { beforeEach(() => { appName = rando(); TestBed.configureTestingModule({ - imports: [ + providers: [ provideFirebaseApp(() => initializeApp(COMMON_CONFIG, appName)), provideStorage(() => { providedStorage = getStorage(getApp(appName));