Skip to content

Commit

Permalink
Point browser field to esm build (#3932)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Feiyang1 committed Oct 20, 2020
1 parent eded218 commit a5768b0
Show file tree
Hide file tree
Showing 45 changed files with 294 additions and 197 deletions.
25 changes: 25 additions & 0 deletions .changeset/funny-ties-ring.md
@@ -0,0 +1,25 @@
---
"@firebase/app": patch
"@firebase/auth": patch
"@firebase/component": patch
"@firebase/database": patch
"firebase": major
"@firebase/firestore": patch
"@firebase/functions": patch
"@firebase/performance": patch
"@firebase/remote-config": patch
"rxfire": patch
"@firebase/util": patch
---

Point browser field to esm build. Now you need to use default import instead of namespace import to import firebase.

Before this change
```
import * as firebase from 'firebase/app';
```

After this change
```
import firebase from 'firebase/app';
```
21 changes: 19 additions & 2 deletions config/webpack.test.js
Expand Up @@ -74,13 +74,30 @@ module.exports = {
]
}
}
},
{
test: /\.js$/,
include: function (modulePath) {
const match = /node_modules\/@firebase.*/.test(modulePath);
if (match) {
console.log('modulePath', modulePath, match);
}
return match;
},
use: {
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-transform-modules-commonjs']
}
}
}
]
},
resolve: {
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
mainFields: ['browser', 'main', 'module'],
extensions: ['.js', '.ts']
mainFields: ['browser', 'module', 'main'],
extensions: ['.js', '.ts'],
symlinks: false
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
Expand Down
2 changes: 0 additions & 2 deletions integration/firebase/package.json
Expand Up @@ -8,8 +8,6 @@
},
"devDependencies": {
"firebase": "7.24.0",
"@babel/core": "7.11.6",
"@babel/preset-env": "7.11.5",
"@types/chai": "4.2.13",
"@types/mocha": "7.0.2",
"chai": "4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/firebase/test/namespace.test.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import * as firebase from 'firebase';
import firebase from 'firebase';
import * as namespaceDefinition from './namespaceDefinition.json';
import validateNamespace from './validator';

Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -87,6 +87,9 @@
"@typescript-eslint/eslint-plugin-tslint": "4.4.1",
"@typescript-eslint/parser": "4.4.1",
"babel-loader": "8.1.0",
"@babel/core": "7.11.6",
"@babel/preset-env": "7.11.5",
"@babel/plugin-transform-modules-commonjs": "7.12.1",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "The primary entrypoint to the Firebase JS SDK",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.node.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"react-native": "dist/index.rn.cjs.js",
"esm2017": "dist/index.esm2017.js",
Expand Down
5 changes: 1 addition & 4 deletions packages/app/rollup.config.js
Expand Up @@ -37,10 +37,7 @@ const es5BuildPlugins = [
const es5Builds = [
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@firebase/auth",
"version": "0.15.0",
"main": "dist/auth.js",
"browser": "dist/auth.js",
"browser": "dist/auth.esm.js",
"module": "dist/auth.esm.js",
"description": "Javascript library for Firebase Auth SDK",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
Expand Down
2 changes: 1 addition & 1 deletion packages/component/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Firebase Component Platform",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
Expand Down
4 changes: 2 additions & 2 deletions packages/component/rollup.config.js
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2018 Google Inc.
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ const es5Builds = [
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
Expand Down
2 changes: 1 addition & 1 deletion packages/database/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.node.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
Expand Down
5 changes: 1 addition & 4 deletions packages/database/rollup.config.js
Expand Up @@ -49,10 +49,7 @@ const es5Builds = [
*/
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase/app/package.json
@@ -1,7 +1,7 @@
{
"name": "firebase/app",
"main": "dist/index.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"typings": "../index.d.ts"
}
2 changes: 1 addition & 1 deletion packages/firebase/index.d.ts
Expand Up @@ -9684,5 +9684,5 @@ declare namespace firebase.firestore {
}
}

export = firebase;
export default firebase;
export as namespace firebase;
2 changes: 1 addition & 1 deletion packages/firebase/package.json
Expand Up @@ -41,7 +41,7 @@
"test:ci": "echo 'No test suite for firebase wrapper'"
},
"main": "dist/index.node.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"react-native": "dist/index.rn.cjs.js",
"dependencies": {
Expand Down
5 changes: 1 addition & 4 deletions packages/firebase/rollup.config.js
Expand Up @@ -184,10 +184,7 @@ const completeBuilds = [
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins,
external
},
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/memory/package.json
Expand Up @@ -4,7 +4,7 @@
"main": "../dist/index.memory.node.cjs.js",
"main-esm2017": "../dist/index.memory.node.esm2017.js",
"react-native": "../dist/index.memory.rn.esm2017.js",
"browser": "../dist/index.memory.cjs.js",
"browser": "../dist/index.memory.esm.js",
"module": "../dist/index.memory.esm.js",
"esm2017": "../dist/index.memory.esm2017.js",
"typings": "../dist/index.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/package.json
Expand Up @@ -51,7 +51,7 @@
"main": "dist/index.node.cjs.js",
"main-esm2017": "dist/index.node.esm2017.js",
"react-native": "dist/index.rn.esm2017.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"license": "Apache-2.0",
Expand Down
9 changes: 0 additions & 9 deletions packages/firestore/rollup.config.browser.js
Expand Up @@ -41,14 +41,5 @@ export default [
treeshake: {
moduleSideEffects: false
}
},
{
input: pkg.esm2017,
output: { file: pkg.browser, format: 'cjs', sourcemap: true },
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
external: util.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
}
];
13 changes: 0 additions & 13 deletions packages/firestore/rollup.config.browser.memory.js
Expand Up @@ -46,18 +46,5 @@ export default [
treeshake: {
moduleSideEffects: false
}
},
{
input: path.resolve('./memory', memoryPkg['esm2017']),
output: {
file: path.resolve('./memory', memoryPkg.browser),
format: 'cjs',
sourcemap: true
},
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
external: util.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
}
];
2 changes: 1 addition & 1 deletion packages/functions/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.node.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
Expand Down
5 changes: 1 addition & 4 deletions packages/functions/rollup.config.js
Expand Up @@ -40,10 +40,7 @@ const es5Builds = [
*/
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
Expand Down
2 changes: 1 addition & 1 deletion packages/performance/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Firebase performance for web",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
Expand Down
2 changes: 1 addition & 1 deletion packages/remote-config/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "The Remote Config package of the Firebase JS SDK",
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": ["dist"],
Expand Down
2 changes: 1 addition & 1 deletion packages/remote-config/rollup.config.js
Expand Up @@ -41,7 +41,7 @@ const es5Builds = [
{
input: 'index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
Expand Down
5 changes: 3 additions & 2 deletions packages/rules-unit-testing/src/api/index.ts
Expand Up @@ -15,15 +15,16 @@
* limitations under the License.
*/

import * as firebase from 'firebase';
import firebase from 'firebase';
import { _FirebaseApp } from '@firebase/app-types/private';
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
import * as request from 'request';
import { base64 } from '@firebase/util';
import { setLogLevel, LogLevel } from '@firebase/logger';
import { Component, ComponentType } from '@firebase/component';

export { database, firestore } from 'firebase';
const { firestore, database } = firebase;
export { firestore, database };

/** If this environment variable is set, use it for the database emulator's address. */
const DATABASE_ADDRESS_ENV: string = 'FIREBASE_DATABASE_EMULATOR_HOST';
Expand Down
11 changes: 7 additions & 4 deletions packages/rxfire/auth/index.ts
Expand Up @@ -17,16 +17,19 @@

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

type Auth = firebase.auth.Auth;
type User = firebase.User;

/**
* Create an observable of authentication state. The observer is only
* triggered on sign-in or sign-out.
* @param auth firebase.auth.Auth
*/
export function authState(auth: auth.Auth): Observable<User> {
export function authState(auth: Auth): Observable<User> {
return new Observable(subscriber => {
const unsubscribe = auth.onAuthStateChanged(subscriber);
return { unsubscribe };
Expand All @@ -38,7 +41,7 @@ export function authState(auth: auth.Auth): Observable<User> {
* sign-out, and token refresh events
* @param auth firebase.auth.Auth
*/
export function user(auth: auth.Auth): Observable<User> {
export function user(auth: Auth): Observable<User> {
return new Observable(subscriber => {
const unsubscribe = auth.onIdTokenChanged(subscriber);
return { unsubscribe };
Expand All @@ -50,7 +53,7 @@ export function user(auth: auth.Auth): Observable<User> {
* sign-out, and token refresh events
* @param auth firebase.auth.Auth
*/
export function idToken(auth: auth.Auth): Observable<string | null> {
export function idToken(auth: Auth): Observable<string | null> {
return user(auth).pipe(
switchMap(user => (user ? from(user.getIdToken()) : of(null)))
);
Expand Down
4 changes: 2 additions & 2 deletions packages/rxfire/database/fromRef.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { database } from 'firebase';
import firebase from 'firebase';
import { Observable } from 'rxjs';
import { delay } from 'rxjs/operators';
import { ListenEvent, QueryChange } from './interfaces';
Expand All @@ -26,7 +26,7 @@ import { ListenEvent, QueryChange } from './interfaces';
* @param event Listen event type ('value', 'added', 'changed', 'removed', 'moved')
*/
export function fromRef(
ref: database.Query,
ref: firebase.database.Query,
event: ListenEvent
): Observable<QueryChange> {
return new Observable<QueryChange>(subscriber => {
Expand Down
4 changes: 2 additions & 2 deletions packages/rxfire/database/interfaces.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { database } from 'firebase';
import firebase from 'firebase';

export enum ListenEvent {
added = 'child_added',
Expand All @@ -26,7 +26,7 @@ export enum ListenEvent {
}

export interface QueryChange {
snapshot: database.DataSnapshot;
snapshot: firebase.database.DataSnapshot;
prevKey: string | null | undefined;
event: ListenEvent;
}

0 comments on commit a5768b0

Please sign in to comment.