Skip to content

Commit 596e208

Browse files
Fix(issue 3075): bundle includes optional app check (#3413)
* fix: Bundle includes optional `app-check` moving the `AppCheckInstances` to core file, so when other modules uses it, it doesn't load the whole package with it Fix #3075 * fix: make `AppCheckInstances` exported only from `@angular/fire/app-check` Fix #3075 --------- Co-authored-by: David East <[email protected]>
1 parent e04cd7f commit 596e208

File tree

10 files changed

+34
-32
lines changed

10 files changed

+34
-32
lines changed

Diff for: src/app-check/app-check.module.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders, PLATFORM_ID, isDevMode, Injector } from '@angular/core';
22
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
3-
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angular/fire';
4-
import { AppCheck, AppCheckInstances, APP_CHECK_PROVIDER_NAME } from './app-check';
3+
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, ɵAppCheckInstances, ɵAPP_CHECK_PROVIDER_NAME, VERSION } from '@angular/fire';
4+
import { AppCheck } from './app-check';
55
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
66
import { registerVersion } from 'firebase/app';
77
import { isPlatformServer } from '@angular/common';
88

99
export const PROVIDED_APP_CHECK_INSTANCES = new InjectionToken<AppCheck[]>('angularfire2.app-check-instances');
10-
export const APP_CHECK_NAMESPACE_SYMBOL = Symbol('angularfire2.app-check.namespace');
1110

1211
export function defaultAppCheckInstanceFactory(provided: FirebaseAppCheck[]|undefined, defaultApp: FirebaseApp) {
13-
const defaultAppCheck = ɵgetDefaultInstanceOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME, provided, defaultApp);
12+
const defaultAppCheck = ɵgetDefaultInstanceOf<FirebaseAppCheck>(ɵAPP_CHECK_PROVIDER_NAME, provided, defaultApp);
1413
return defaultAppCheck && new AppCheck(defaultAppCheck);
1514
}
1615

@@ -30,7 +29,7 @@ export function appCheckInstanceFactory(fn: (injector: Injector) => FirebaseAppC
3029
}
3130

3231
const APP_CHECK_INSTANCES_PROVIDER = {
33-
provide: AppCheckInstances,
32+
provide: ɵAppCheckInstances,
3433
deps: [
3534
[new Optional(), PROVIDED_APP_CHECK_INSTANCES ],
3635
]

Diff for: src/app-check/app-check.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
2-
import { ɵgetAllInstancesOf } from '@angular/fire';
2+
import { ɵgetAllInstancesOf, ɵAPP_CHECK_PROVIDER_NAME } from '@angular/fire';
33
import { from, timer } from 'rxjs';
44
import { concatMap, distinct } from 'rxjs/operators';
55

6-
export const APP_CHECK_PROVIDER_NAME = 'app-check';
7-
86
// see notes in core/firebase.app.module.ts for why we're building the class like this
97
// tslint:disable-next-line:no-empty-interface
108
export interface AppCheck extends FirebaseAppCheck {}
@@ -15,16 +13,7 @@ export class AppCheck {
1513
}
1614
}
1715

18-
// tslint:disable-next-line:no-empty-interface
19-
export interface AppCheckInstances extends Array<FirebaseAppCheck> {}
20-
21-
export class AppCheckInstances {
22-
constructor() {
23-
return ɵgetAllInstancesOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME);
24-
}
25-
}
26-
2716
export const appCheckInstance$ = timer(0, 300).pipe(
28-
concatMap(() => from(ɵgetAllInstancesOf<FirebaseAppCheck>(APP_CHECK_PROVIDER_NAME))),
17+
concatMap(() => from(ɵgetAllInstancesOf<FirebaseAppCheck>(ɵAPP_CHECK_PROVIDER_NAME))),
2918
distinct(),
3019
);

Diff for: src/app-check/public_api.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export { AppCheck, AppCheckInstances, appCheckInstance$ } from './app-check';
1+
export { AppCheck, appCheckInstance$ } from './app-check';
2+
export { ɵAppCheckInstances as AppCheckInstances } from '@angular/fire';
23
export { provideAppCheck, AppCheckModule } from './app-check.module';
34
export * from './firebase';

Diff for: src/auth/auth.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angul
44
import { Auth, AuthInstances, AUTH_PROVIDER_NAME } from './auth';
55
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
66
import { registerVersion } from 'firebase/app';
7-
import { AppCheckInstances } from '@angular/fire/app-check';
7+
import { ɵAppCheckInstances } from '@angular/fire';
88

99
export const PROVIDED_AUTH_INSTANCES = new InjectionToken<Auth[]>('angularfire2.auth-instances');
1010

@@ -60,7 +60,7 @@ export function provideAuth(fn: (injector: Injector) => FirebaseAuth, ...deps: a
6060
Injector,
6161
ɵAngularFireSchedulers,
6262
FirebaseApps,
63-
[new Optional(), AppCheckInstances ],
63+
[new Optional(), ɵAppCheckInstances ],
6464
...deps,
6565
]
6666
}]

Diff for: src/core.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Version } from '@angular/core';
22
import { FirebaseApp, getApps } from 'firebase/app';
33
import { ComponentContainer } from '@firebase/component';
4+
import type { AppCheck } from 'firebase/app-check';
45

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

@@ -41,3 +42,16 @@ export const ɵgetAllInstancesOf = <T= unknown>(identifier: string, app?: Fireba
4142
});
4243
return instances;
4344
};
45+
46+
// tslint:disable-next-line:no-empty-interface class-name
47+
export interface ɵAppCheckInstances extends Array<AppCheck> {}
48+
49+
// tslint:disable-next-line:class-name
50+
export class ɵAppCheckInstances {
51+
constructor() {
52+
return ɵgetAllInstancesOf<AppCheck>(ɵAPP_CHECK_PROVIDER_NAME);
53+
}
54+
}
55+
56+
// tslint:disable-next-line:variable-name
57+
export const ɵAPP_CHECK_PROVIDER_NAME = 'app-check';

Diff for: src/database/database.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angul
55
import { Database, DatabaseInstances, DATABASE_PROVIDER_NAME } from './database';
66
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
77
import { registerVersion } from 'firebase/app';
8-
import { AppCheckInstances } from '@angular/fire/app-check';
8+
import { ɵAppCheckInstances } from '@angular/fire';
99

1010
export const PROVIDED_DATABASE_INSTANCES = new InjectionToken<Database[]>('angularfire2.database-instances');
1111

@@ -63,7 +63,7 @@ export function provideDatabase(fn: (injector: Injector) => FirebaseDatabase, ..
6363
FirebaseApps,
6464
// Database+Auth work better if Auth is loaded first
6565
[new Optional(), AuthInstances ],
66-
[new Optional(), AppCheckInstances ],
66+
[new Optional(), ɵAppCheckInstances ],
6767
...deps,
6868
]
6969
}]

Diff for: src/firestore/firestore.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angul
55
import { Firestore, FirestoreInstances, FIRESTORE_PROVIDER_NAME } from './firestore';
66
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
77
import { registerVersion } from 'firebase/app';
8-
import { AppCheckInstances } from '@angular/fire/app-check';
8+
import { ɵAppCheckInstances } from '@angular/fire';
99

1010
export const PROVIDED_FIRESTORE_INSTANCES = new InjectionToken<Firestore[]>('angularfire2.firestore-instances');
1111

@@ -63,7 +63,7 @@ export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore,
6363
FirebaseApps,
6464
// Firestore+Auth work better if Auth is loaded first
6565
[new Optional(), AuthInstances ],
66-
[new Optional(), AppCheckInstances ],
66+
[new Optional(), ɵAppCheckInstances ],
6767
...deps,
6868
]
6969
}]

Diff for: src/firestore/lite/lite.module.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders, Injector } from '@angular/core';
22
import { Firestore as FirebaseFirestore } from 'firebase/firestore/lite';
33
import { AuthInstances } from '@angular/fire/auth';
4-
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angular/fire';
4+
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, ɵAppCheckInstances, VERSION } from '@angular/fire';
55
import { Firestore, FirestoreInstances, FIRESTORE_PROVIDER_NAME } from './lite';
66
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
77
import { registerVersion } from 'firebase/app';
8-
import { AppCheckInstances } from '@angular/fire/app-check';
98

109
export const PROVIDED_FIRESTORE_INSTANCES = new InjectionToken<Firestore[]>('angularfire2.firestore-lite-instances');
1110

@@ -63,7 +62,7 @@ export function provideFirestore(fn: (injector: Injector) => FirebaseFirestore,
6362
FirebaseApps,
6463
// Firestore+Auth work better if Auth is loaded first
6564
[new Optional(), AuthInstances ],
66-
[new Optional(), AppCheckInstances ],
65+
[new Optional(), ɵAppCheckInstances ],
6766
...deps,
6867
]
6968
}]

Diff for: src/functions/functions.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Functions, FunctionsInstances, FUNCTIONS_PROVIDER_NAME } from './functi
55
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
66
import { AuthInstances } from '@angular/fire/auth';
77
import { registerVersion } from 'firebase/app';
8-
import { AppCheckInstances } from '@angular/fire/app-check';
8+
import { ɵAppCheckInstances } from '@angular/fire';
99

1010
export const PROVIDED_FUNCTIONS_INSTANCES = new InjectionToken<Functions[]>('angularfire2.functions-instances');
1111

@@ -63,7 +63,7 @@ export function provideFunctions(fn: (injector: Injector) => FirebaseFunctions,
6363
FirebaseApps,
6464
// Defensively load Auth first, if provided
6565
[new Optional(), AuthInstances ],
66-
[new Optional(), AppCheckInstances ],
66+
[new Optional(), ɵAppCheckInstances ],
6767
...deps,
6868
]
6969
}]

Diff for: src/storage/storage.module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Storage, StorageInstances, STORAGE_PROVIDER_NAME } from './storage';
55
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
66
import { AuthInstances } from '@angular/fire/auth';
77
import { registerVersion } from 'firebase/app';
8-
import { AppCheckInstances } from '@angular/fire/app-check';
8+
import { ɵAppCheckInstances } from '@angular/fire';
99

1010
export const PROVIDED_STORAGE_INSTANCES = new InjectionToken<Storage[]>('angularfire2.storage-instances');
1111

@@ -63,7 +63,7 @@ export function provideStorage(fn: (injector: Injector) => FirebaseStorage, ...d
6363
FirebaseApps,
6464
// Defensively load Auth first, if provided
6565
[new Optional(), AuthInstances ],
66-
[new Optional(), AppCheckInstances ],
66+
[new Optional(), ɵAppCheckInstances ],
6767
...deps,
6868
]
6969
}]

0 commit comments

Comments
 (0)