Skip to content

Commit a5768b0

Browse files
authored
Point browser field to esm build (#3932)
* point browser field to esm build * address comments * Create funny-ties-ring.md * fix build error in component * change from namespace export to default export * update changeset * fix firebase imports in rxfire * fix import for rules-unit-testing * fix testing * compile firebase pkgs to cjs so they can be stubbed in tests
1 parent eded218 commit a5768b0

Some content is hidden

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

45 files changed

+294
-197
lines changed

.changeset/funny-ties-ring.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
"@firebase/app": patch
3+
"@firebase/auth": patch
4+
"@firebase/component": patch
5+
"@firebase/database": patch
6+
"firebase": major
7+
"@firebase/firestore": patch
8+
"@firebase/functions": patch
9+
"@firebase/performance": patch
10+
"@firebase/remote-config": patch
11+
"rxfire": patch
12+
"@firebase/util": patch
13+
---
14+
15+
Point browser field to esm build. Now you need to use default import instead of namespace import to import firebase.
16+
17+
Before this change
18+
```
19+
import * as firebase from 'firebase/app';
20+
```
21+
22+
After this change
23+
```
24+
import firebase from 'firebase/app';
25+
```

config/webpack.test.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,30 @@ module.exports = {
7474
]
7575
}
7676
}
77+
},
78+
{
79+
test: /\.js$/,
80+
include: function (modulePath) {
81+
const match = /node_modules\/@firebase.*/.test(modulePath);
82+
if (match) {
83+
console.log('modulePath', modulePath, match);
84+
}
85+
return match;
86+
},
87+
use: {
88+
loader: 'babel-loader',
89+
options: {
90+
plugins: ['@babel/plugin-transform-modules-commonjs']
91+
}
92+
}
7793
}
7894
]
7995
},
8096
resolve: {
8197
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
82-
mainFields: ['browser', 'main', 'module'],
83-
extensions: ['.js', '.ts']
98+
mainFields: ['browser', 'module', 'main'],
99+
extensions: ['.js', '.ts'],
100+
symlinks: false
84101
},
85102
plugins: [
86103
new webpack.NormalModuleReplacementPlugin(

integration/firebase/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
},
99
"devDependencies": {
1010
"firebase": "7.24.0",
11-
"@babel/core": "7.11.6",
12-
"@babel/preset-env": "7.11.5",
1311
"@types/chai": "4.2.13",
1412
"@types/mocha": "7.0.2",
1513
"chai": "4.2.0",

integration/firebase/test/namespace.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firebase from 'firebase';
18+
import firebase from 'firebase';
1919
import * as namespaceDefinition from './namespaceDefinition.json';
2020
import validateNamespace from './validator';
2121

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
"@typescript-eslint/eslint-plugin-tslint": "4.4.1",
8888
"@typescript-eslint/parser": "4.4.1",
8989
"babel-loader": "8.1.0",
90+
"@babel/core": "7.11.6",
91+
"@babel/preset-env": "7.11.5",
92+
"@babel/plugin-transform-modules-commonjs": "7.12.1",
9093
"chai": "4.2.0",
9194
"chai-as-promised": "7.1.1",
9295
"chalk": "4.1.0",

packages/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "The primary entrypoint to the Firebase JS SDK",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.node.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"react-native": "dist/index.rn.cjs.js",
1010
"esm2017": "dist/index.esm2017.js",

packages/app/rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ const es5BuildPlugins = [
3737
const es5Builds = [
3838
{
3939
input: 'index.ts',
40-
output: [
41-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
42-
{ file: pkg.module, format: 'es', sourcemap: true }
43-
],
40+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
4441
plugins: es5BuildPlugins,
4542
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
4643
},

packages/auth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@firebase/auth",
33
"version": "0.15.0",
44
"main": "dist/auth.js",
5-
"browser": "dist/auth.js",
5+
"browser": "dist/auth.esm.js",
66
"module": "dist/auth.esm.js",
77
"description": "Javascript library for Firebase Auth SDK",
88
"author": "Firebase <[email protected]> (https://firebase.google.com/)",

packages/component/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Firebase Component Platform",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"esm2017": "dist/index.esm2017.js",
1010
"files": ["dist"],

packages/component/rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2018 Google Inc.
3+
* Copyright 2018 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ const es5Builds = [
3939
{
4040
input: 'index.ts',
4141
output: [
42-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
42+
{ file: pkg.main, format: 'cjs', sourcemap: true },
4343
{ file: pkg.module, format: 'es', sourcemap: true }
4444
],
4545
plugins: es5BuildPlugins,

packages/database/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.node.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"esm2017": "dist/index.esm2017.js",
1010
"files": ["dist"],

packages/database/rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ const es5Builds = [
4949
*/
5050
{
5151
input: 'index.ts',
52-
output: [
53-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
54-
{ file: pkg.module, format: 'es', sourcemap: true }
55-
],
52+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
5653
plugins: es5BuildPlugins,
5754
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
5855
}

packages/firebase/app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "firebase/app",
33
"main": "dist/index.cjs.js",
4-
"browser": "dist/index.cjs.js",
4+
"browser": "dist/index.esm.js",
55
"module": "dist/index.esm.js",
66
"typings": "../index.d.ts"
77
}

packages/firebase/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9684,5 +9684,5 @@ declare namespace firebase.firestore {
96849684
}
96859685
}
96869686

9687-
export = firebase;
9687+
export default firebase;
96889688
export as namespace firebase;

packages/firebase/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"test:ci": "echo 'No test suite for firebase wrapper'"
4242
},
4343
"main": "dist/index.node.cjs.js",
44-
"browser": "dist/index.cjs.js",
44+
"browser": "dist/index.esm.js",
4545
"module": "dist/index.esm.js",
4646
"react-native": "dist/index.rn.cjs.js",
4747
"dependencies": {

packages/firebase/rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,7 @@ const completeBuilds = [
184184
*/
185185
{
186186
input: 'src/index.ts',
187-
output: [
188-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
189-
{ file: pkg.module, format: 'es', sourcemap: true }
190-
],
187+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
191188
plugins,
192189
external
193190
},

packages/firestore/memory/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "../dist/index.memory.node.cjs.js",
55
"main-esm2017": "../dist/index.memory.node.esm2017.js",
66
"react-native": "../dist/index.memory.rn.esm2017.js",
7-
"browser": "../dist/index.memory.cjs.js",
7+
"browser": "../dist/index.memory.esm.js",
88
"module": "../dist/index.memory.esm.js",
99
"esm2017": "../dist/index.memory.esm2017.js",
1010
"typings": "../dist/index.d.ts"

packages/firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"main": "dist/index.node.cjs.js",
5252
"main-esm2017": "dist/index.node.esm2017.js",
5353
"react-native": "dist/index.rn.esm2017.js",
54-
"browser": "dist/index.cjs.js",
54+
"browser": "dist/index.esm.js",
5555
"module": "dist/index.esm.js",
5656
"esm2017": "dist/index.esm2017.js",
5757
"license": "Apache-2.0",

packages/firestore/rollup.config.browser.js

-9
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,5 @@ export default [
4141
treeshake: {
4242
moduleSideEffects: false
4343
}
44-
},
45-
{
46-
input: pkg.esm2017,
47-
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
48-
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
49-
external: util.resolveBrowserExterns,
50-
treeshake: {
51-
moduleSideEffects: false
52-
}
5344
}
5445
];

packages/firestore/rollup.config.browser.memory.js

-13
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,5 @@ export default [
4646
treeshake: {
4747
moduleSideEffects: false
4848
}
49-
},
50-
{
51-
input: path.resolve('./memory', memoryPkg['esm2017']),
52-
output: {
53-
file: path.resolve('./memory', memoryPkg.browser),
54-
format: 'cjs',
55-
sourcemap: true
56-
},
57-
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
58-
external: util.resolveBrowserExterns,
59-
treeshake: {
60-
moduleSideEffects: false
61-
}
6249
}
6350
];

packages/functions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.node.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"esm2017": "dist/index.esm2017.js",
1010
"files": ["dist"],

packages/functions/rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ const es5Builds = [
4040
*/
4141
{
4242
input: 'index.ts',
43-
output: [
44-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
45-
{ file: pkg.module, format: 'es', sourcemap: true }
46-
],
43+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
4744
plugins: es5BuildPlugins,
4845
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
4946
},

packages/performance/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Firebase performance for web",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"esm2017": "dist/index.esm2017.js",
1010
"files": ["dist"],

packages/remote-config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "The Remote Config package of the Firebase JS SDK",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
7-
"browser": "dist/index.cjs.js",
7+
"browser": "dist/index.esm.js",
88
"module": "dist/index.esm.js",
99
"esm2017": "dist/index.esm2017.js",
1010
"files": ["dist"],

packages/remote-config/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const es5Builds = [
4141
{
4242
input: 'index.ts',
4343
output: [
44-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
44+
{ file: pkg.main, format: 'cjs', sourcemap: true },
4545
{ file: pkg.module, format: 'es', sourcemap: true }
4646
],
4747
plugins: es5BuildPlugins,

packages/rules-unit-testing/src/api/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firebase from 'firebase';
18+
import firebase from 'firebase';
1919
import { _FirebaseApp } from '@firebase/app-types/private';
2020
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
2121
import * as request from 'request';
2222
import { base64 } from '@firebase/util';
2323
import { setLogLevel, LogLevel } from '@firebase/logger';
2424
import { Component, ComponentType } from '@firebase/component';
2525

26-
export { database, firestore } from 'firebase';
26+
const { firestore, database } = firebase;
27+
export { firestore, database };
2728

2829
/** If this environment variable is set, use it for the database emulator's address. */
2930
const DATABASE_ADDRESS_ENV: string = 'FIREBASE_DATABASE_EMULATOR_HOST';

packages/rxfire/auth/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717

1818
// auth is used as a namespace to access types
1919
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20-
import { auth, User } from 'firebase';
20+
import firebase from 'firebase';
2121
import { Observable, from, of } from 'rxjs';
2222
import { switchMap } from 'rxjs/operators';
2323

24+
type Auth = firebase.auth.Auth;
25+
type User = firebase.User;
26+
2427
/**
2528
* Create an observable of authentication state. The observer is only
2629
* triggered on sign-in or sign-out.
2730
* @param auth firebase.auth.Auth
2831
*/
29-
export function authState(auth: auth.Auth): Observable<User> {
32+
export function authState(auth: Auth): Observable<User> {
3033
return new Observable(subscriber => {
3134
const unsubscribe = auth.onAuthStateChanged(subscriber);
3235
return { unsubscribe };
@@ -38,7 +41,7 @@ export function authState(auth: auth.Auth): Observable<User> {
3841
* sign-out, and token refresh events
3942
* @param auth firebase.auth.Auth
4043
*/
41-
export function user(auth: auth.Auth): Observable<User> {
44+
export function user(auth: Auth): Observable<User> {
4245
return new Observable(subscriber => {
4346
const unsubscribe = auth.onIdTokenChanged(subscriber);
4447
return { unsubscribe };
@@ -50,7 +53,7 @@ export function user(auth: auth.Auth): Observable<User> {
5053
* sign-out, and token refresh events
5154
* @param auth firebase.auth.Auth
5255
*/
53-
export function idToken(auth: auth.Auth): Observable<string | null> {
56+
export function idToken(auth: Auth): Observable<string | null> {
5457
return user(auth).pipe(
5558
switchMap(user => (user ? from(user.getIdToken()) : of(null)))
5659
);

packages/rxfire/database/fromRef.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { database } from 'firebase';
18+
import firebase from 'firebase';
1919
import { Observable } from 'rxjs';
2020
import { delay } from 'rxjs/operators';
2121
import { ListenEvent, QueryChange } from './interfaces';
@@ -26,7 +26,7 @@ import { ListenEvent, QueryChange } from './interfaces';
2626
* @param event Listen event type ('value', 'added', 'changed', 'removed', 'moved')
2727
*/
2828
export function fromRef(
29-
ref: database.Query,
29+
ref: firebase.database.Query,
3030
event: ListenEvent
3131
): Observable<QueryChange> {
3232
return new Observable<QueryChange>(subscriber => {

packages/rxfire/database/interfaces.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { database } from 'firebase';
18+
import firebase from 'firebase';
1919

2020
export enum ListenEvent {
2121
added = 'child_added',
@@ -26,7 +26,7 @@ export enum ListenEvent {
2626
}
2727

2828
export interface QueryChange {
29-
snapshot: database.DataSnapshot;
29+
snapshot: firebase.database.DataSnapshot;
3030
prevKey: string | null | undefined;
3131
event: ListenEvent;
3232
}

0 commit comments

Comments
 (0)