Skip to content

Commit a66be53

Browse files
authored
Add compat packages to firebase-exp (#4648)
* save * build analytics-compat cdn script * add auth-compat to firebase-exp * add functions-compat to firebase-exp * add messaging-compat to firebase-exp * update imports * add performance-compat to firebase-exp * add remoteconfig-compat to firebase-exp * update var name * add firestore-compat to firebase-exp * fix builds * add storage-compat to firebase-exp * add firestore-compat and storage-compat to dependencies * address comments * update license * fix messaging and typings * update typings path * typings for compat packages * minify cdn scripts * use the right typings for dev * fix script * fix typing errors * fix lint errors
1 parent 0acc039 commit a66be53

File tree

79 files changed

+772
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+772
-173
lines changed

common/api-review/messaging-exp.api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export interface NotificationPayload {
6262
title?: string;
6363
}
6464

65+
// Warning: (ae-internal-missing-underscore) The name "onBackgroundMessage" should be prefixed with an underscore because the declaration is marked as @internal
66+
//
67+
// @internal
68+
export function onBackgroundMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
69+
6570
// @public
6671
export function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
6772

packages-exp/analytics-compat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"test:browser": "karma start --single-run",
4343
"test:browser:debug": "karma start --browsers=Chrome --auto-watch"
4444
},
45-
"typings": "dist/analytics-compat-public.d.ts",
45+
"typings": "dist/src/index.d.ts",
4646
"dependencies": {
4747
"@firebase/component": "0.2.1",
4848
"@firebase/analytics-exp": "0.0.900",

packages-exp/analytics-compat/src/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { firebase, _FirebaseNamespace } from '@firebase/app-compat';
18+
import firebase, { _FirebaseNamespace } from '@firebase/app-compat';
19+
import { FirebaseAnalytics } from '@firebase/analytics-types';
1920
import { name, version } from '../package.json';
2021
import { AnalyticsService } from './service';
2122
import {
@@ -26,17 +27,14 @@ import {
2627
} from '@firebase/component';
2728
import { FirebaseApp } from '@firebase/app-types';
2829
import {
29-
Analytics as AnalyticsServiceExp,
3030
settings as settingsExp,
3131
isSupported as isSupportedExp
3232
} from '@firebase/analytics-exp';
3333
import { EventName } from './constants';
3434

3535
declare module '@firebase/component' {
3636
interface NameServiceMapping {
37-
'app-compat': FirebaseApp;
3837
'analytics-compat': AnalyticsService;
39-
'analytics-exp': AnalyticsServiceExp;
4038
}
4139
}
4240

@@ -69,3 +67,15 @@ export function registerAnalytics(): void {
6967

7068
registerAnalytics();
7169
firebase.registerVersion(name, version);
70+
71+
/**
72+
* Define extension behavior of `registerAnalytics`
73+
*/
74+
declare module '@firebase/app-compat' {
75+
interface FirebaseNamespace {
76+
analytics(app?: FirebaseApp): FirebaseAnalytics;
77+
}
78+
interface FirebaseApp {
79+
analytics(): FirebaseAnalytics;
80+
}
81+
}

packages-exp/analytics-exp/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1616
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1717
"build": "rollup -c && yarn api-report",
18-
"build:release": "rollup -c rollup.config.release.js && yarn api-report",
18+
"build:release": "rollup -c rollup.config.release.js && yarn api-report && yarn typings:public",
1919
"build:deps": "lerna run --scope @firebase/analytics-exp --include-dependencies build",
2020
"dev": "rollup -c -w",
2121
"test": "run-p lint test:all",
@@ -26,7 +26,8 @@
2626
"api-report": "api-extractor run --local --verbose",
2727
"predoc": "node ../../scripts/exp/remove-exp.js temp",
2828
"doc": "api-documenter markdown --input temp --output docs",
29-
"build:doc": "yarn build && yarn doc"
29+
"build:doc": "yarn build && yarn doc",
30+
"typings:public": "node ../../scripts/exp/use_typings.js ./dist/analytics-exp-public.d.ts"
3031
},
3132
"peerDependencies": {
3233
"@firebase/app-exp": "0.x"
@@ -56,7 +57,7 @@
5657
"bugs": {
5758
"url": "https://github.com/firebase/firebase-js-sdk/issues"
5859
},
59-
"typings": "dist/analytics-exp-public.d.ts",
60+
"typings": "dist/src/index.d.ts",
6061
"nyc": {
6162
"extension": [
6263
".ts"

packages-exp/analytics-exp/rollup.shared.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
import pkg from './package.json';
1818

19-
const deps = Object.keys(
20-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
21-
);
19+
const deps = [
20+
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
21+
'@firebase/app'
22+
];
2223

2324
export const es5BuildsNoPlugin = [
2425
/**

packages-exp/app-compat/src/firebaseApp.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseApp, FirebaseOptions } from './public-types';
18+
import { FirebaseOptions } from './public-types';
1919
import {
2020
Component,
2121
ComponentContainer,
@@ -31,11 +31,34 @@ import {
3131
} from '@firebase/app-exp';
3232
import { _FirebaseService, _FirebaseNamespace } from './types';
3333

34+
// eslint-disable-next-line @typescript-eslint/naming-convention
35+
export interface _FirebaseApp {
36+
/**
37+
* The (read-only) name (identifier) for this App. '[DEFAULT]' is the default
38+
* App.
39+
*/
40+
name: string;
41+
42+
/**
43+
* The (read-only) configuration options from the app initialization.
44+
*/
45+
options: FirebaseOptions;
46+
47+
/**
48+
* The settable config flag for GDPR opt-in/opt-out
49+
*/
50+
automaticDataCollectionEnabled: boolean;
51+
52+
/**
53+
* Make the given App unusable and free resources.
54+
*/
55+
delete(): Promise<void>;
56+
}
3457
/**
3558
* Global context object for a collection of services using
3659
* a shared authentication state.
3760
*/
38-
export class FirebaseAppImpl implements FirebaseApp {
61+
export class FirebaseAppImpl implements _FirebaseApp {
3962
private container: ComponentContainer;
4063

4164
constructor(

packages-exp/app-compat/src/firebaseNamespaceCore.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function createFirebaseNamespaceCore(
135135
component: Component
136136
): FirebaseServiceNamespace<_FirebaseService> | null {
137137
const componentName = component.name;
138+
const componentNameWithoutCompat = componentName.replace('-compat', '');
138139
if (
139140
modularAPIs._registerComponent(component) &&
140141
component.type === ComponentType.PUBLIC
@@ -145,7 +146,7 @@ export function createFirebaseNamespaceCore(
145146
appArg: FirebaseApp = app()
146147
): _FirebaseService => {
147148
// eslint-disable-next-line @typescript-eslint/no-explicit-any
148-
if (typeof (appArg as any)[componentName] !== 'function') {
149+
if (typeof (appArg as any)[componentNameWithoutCompat] !== 'function') {
149150
// Invalid argument.
150151
// This happens in the following case: firebase.storage('gs:/')
151152
throw ERROR_FACTORY.create(AppError.INVALID_APP_ARGUMENT, {
@@ -155,7 +156,7 @@ export function createFirebaseNamespaceCore(
155156

156157
// Forward service instance lookup to the FirebaseApp.
157158
// eslint-disable-next-line @typescript-eslint/no-explicit-any
158-
return (appArg as any)[componentName]();
159+
return (appArg as any)[componentNameWithoutCompat]();
159160
};
160161

161162
// ... and a container for service-level properties.
@@ -164,11 +165,11 @@ export function createFirebaseNamespaceCore(
164165
}
165166

166167
// eslint-disable-next-line @typescript-eslint/no-explicit-any
167-
(namespace as any)[componentName] = serviceNamespace;
168+
(namespace as any)[componentNameWithoutCompat] = serviceNamespace;
168169

169170
// Patch the FirebaseAppImpl prototype
170171
// eslint-disable-next-line @typescript-eslint/no-explicit-any
171-
(firebaseAppImpl.prototype as any)[componentName] =
172+
(firebaseAppImpl.prototype as any)[componentNameWithoutCompat] =
172173
// TODO: The eslint disable can be removed and the 'ignoreRestArgs'
173174
// option added to the no-explicit-any rule when ESlint releases it.
174175
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -183,7 +184,7 @@ export function createFirebaseNamespaceCore(
183184

184185
return component.type === ComponentType.PUBLIC
185186
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
186-
(namespace as any)[componentName]
187+
(namespace as any)[componentNameWithoutCompat]
187188
: null;
188189
}
189190

packages-exp/app-compat/src/public-types.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
import { LogCallback, LogLevelString, LogOptions } from '@firebase/logger';
18-
import { FirebaseAppImpl } from './firebaseApp';
18+
import { FirebaseAppImpl, _FirebaseApp } from './firebaseApp';
1919

2020
export interface FirebaseOptions {
2121
apiKey?: string;
@@ -33,29 +33,17 @@ export interface FirebaseAppConfig {
3333
automaticDataCollectionEnabled?: boolean;
3434
}
3535

36-
// used as type only
37-
export interface FirebaseApp {
38-
/**
39-
* The (read-only) name (identifier) for this App. '[DEFAULT]' is the default
40-
* App.
41-
*/
42-
name: string;
43-
44-
/**
45-
* The (read-only) configuration options from the app initialization.
46-
*/
47-
options: FirebaseOptions;
48-
49-
/**
50-
* The settable config flag for GDPR opt-in/opt-out
51-
*/
52-
automaticDataCollectionEnabled: boolean;
53-
54-
/**
55-
* Make the given App unusable and free resources.
56-
*/
57-
delete(): Promise<void>;
58-
}
36+
/**
37+
* This interface will be enhanced by other products by adding e.g. firestore(), messaging() methods.
38+
* As a result, FirebaseAppImpl can't directly implement it, otherwise there will be typings errors:
39+
*
40+
* For example, "Class 'FirebaseAppImpl' incorrectly implements interface 'FirebaseApp'.
41+
* Property 'installations' is missing in type 'FirebaseAppImpl' but required in type 'FirebaseApp'"
42+
*
43+
* To workaround this issue, we defined a _FirebaseApp interface which is implemented by FirebaseAppImpl
44+
* and let FirebaseApp extends it.
45+
*/
46+
export interface FirebaseApp extends _FirebaseApp {}
5947

6048
export interface FirebaseNamespace {
6149
/**

packages-exp/app-exp/rollup.shared.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
import pkg from './package.json';
1818

19-
const deps = Object.keys(
20-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
21-
);
19+
const deps = [
20+
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
21+
'@firebase/app'
22+
];
2223

2324
export const es5BuildsNoPlugin = [
2425
/**

packages-exp/auth-compat-exp/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ import { version } from './package.json';
5050
import { Auth } from './src/auth';
5151
import { Persistence } from './src/persistence';
5252
import { PhoneAuthProvider as CompatAuthProvider } from './src/phone_auth_provider';
53-
import { _getClientPlatform } from './src/platform';
5453
import { RecaptchaVerifier as CompatRecaptchaVerifier } from './src/recaptcha_verifier';
5554

56-
const AUTH_TYPE = 'auth';
55+
const AUTH_TYPE = 'auth-compat';
5756

5857
declare module '@firebase/component' {
5958
interface NameServiceMapping {
@@ -140,5 +139,4 @@ function registerAuthCompat(instance: _FirebaseNamespace): void {
140139
instance.registerVersion('auth', version);
141140
}
142141

143-
impl.registerAuth(_getClientPlatform());
144142
registerAuthCompat(firebase as _FirebaseNamespace);

packages-exp/auth-compat-exp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"bugs": {
5656
"url": "https://github.com/firebase/firebase-js-sdk/issues"
5757
},
58-
"typings": "dist/index.d.ts",
58+
"typings": "dist/auth-compat-exp/index.d.ts",
5959
"nyc": {
6060
"extension": [
6161
".ts"

packages-exp/auth-compat-exp/rollup.config.shared.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
5151
input: 'index.ts',
5252
output: [{ file: pkg.module, format: 'esm', sourcemap: true }],
5353
plugins: es5BuildPlugins,
54-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
54+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
55+
treeshake: {
56+
moduleSideEffects: false
57+
}
5558
},
5659
/**
5760
* Node.js Build
@@ -60,7 +63,10 @@ export function getEs5Builds(additionalTypescriptPlugins = {}) {
6063
input: 'index.node.ts',
6164
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
6265
plugins: es5BuildPlugins,
63-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
66+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
67+
treeshake: {
68+
moduleSideEffects: false
69+
}
6470
},
6571
/**
6672
* UMD build
@@ -131,7 +137,10 @@ export function getEs2017Builds(additionalTypescriptPlugins = {}) {
131137
sourcemap: true
132138
},
133139
plugins: es2017BuildPlugins,
134-
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
140+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
141+
treeshake: {
142+
moduleSideEffects: false
143+
}
135144
}
136145
];
137146
}

packages-exp/auth-compat-exp/src/persistence.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { AuthInternal } from '@firebase/auth-exp/dist/esm5/src/model/auth';
1918
import * as exp from '@firebase/auth-exp/internal';
2019
import { isIndexedDBAvailable, isNode, isReactNative } from '@firebase/util';
2120
import { _isWebStorageSupported, _isWorker } from './platform';
@@ -82,7 +81,7 @@ export function _validatePersistenceArgument(
8281
}
8382

8483
export async function _savePersistenceForRedirect(
85-
auth: AuthInternal
84+
auth: exp.AuthInternal
8685
): Promise<void> {
8786
await auth._initializationPromise;
8887

@@ -98,7 +97,7 @@ export async function _savePersistenceForRedirect(
9897
}
9998

10099
export function _getPersistenceFromRedirect(
101-
auth: AuthInternal
100+
auth: exp.AuthInternal
102101
): exp.Persistence | null {
103102
const win = getSelfWindow();
104103
if (!win?.sessionStorage) {

packages-exp/auth-compat-exp/src/platform.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,6 @@ export function _isPopupRedirectSupported(): boolean {
149149
);
150150
}
151151

152-
export function _getClientPlatform(): impl.ClientPlatform {
153-
if (isNode()) {
154-
return impl.ClientPlatform.NODE;
155-
}
156-
if (isReactNative()) {
157-
return impl.ClientPlatform.REACT_NATIVE;
158-
}
159-
if (_isWorker()) {
160-
return impl.ClientPlatform.WORKER;
161-
}
162-
return impl.ClientPlatform.BROWSER;
163-
}
164-
165152
/** Quick check that indicates the platform *may* be Cordova */
166153
export function _isLikelyCordova(): boolean {
167154
return _isAndroidOrIosCordovaScheme() && typeof document !== 'undefined';

packages-exp/auth-exp/internal/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export {
3232
AuthEventType
3333
} from '../src/model/popup_redirect';
3434
export { UserCredentialInternal, UserParameters } from '../src/model/user';
35-
export { registerAuth } from '../src/core/auth/register';
35+
export { AuthInternal } from '../src/model/auth';
3636
export { DefaultConfig, AuthImpl, _castAuth } from '../src/core/auth/auth_impl';
3737

3838
export { ClientPlatform, _getClientVersion } from '../src/core/util/version';

packages-exp/auth-exp/rollup.config.shared.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import typescript from 'typescript';
2222
import pkg from './package.json';
2323
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
2424

25-
const deps = Object.keys(
26-
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
27-
);
25+
const deps = [
26+
...Object.keys(Object.assign({}, pkg.peerDependencies, pkg.dependencies)),
27+
'@firebase/app'
28+
];
2829

2930
/**
3031
* Common plugins for all builds

0 commit comments

Comments
 (0)