Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point browser field to esm build #3932

Merged
merged 13 commits into from
Oct 20, 2020
25 changes: 25 additions & 0 deletions .changeset/funny-ties-ring.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 },
Feiyang1 marked this conversation as resolved.
Show resolved Hide resolved
{ 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}
}
];
5 changes: 1 addition & 4 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ import {
valueDescription,
validateIsNotUsedTogether
} from '../util/input_validation';
import {
setLogLevel as setClientLogLevel,
logWarn
} from '../util/log';
import { setLogLevel as setClientLogLevel, logWarn } from '../util/log';
import { AutoId } from '../util/misc';
import { Deferred } from '../util/promise';
import { FieldPath as ExternalFieldPath } from './field_path';
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samtstern @yuchenshi
Meant to ask you before merging the PR - How does developer use these two exports? Do they use the typings from them?
They won't get typings after this change because firestore and database are not namespaces anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they're used to provide access to Firestore / RTDB classes like this:
https://github.com/firebase/firebase-js-sdk/blob/master/packages/rules-unit-testing/test/database.test.ts#L313

If those tests still pass I think we're fine? To be honest I don't quite understand namespaces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that will continue to work. We are good. Thanks for confirming.


/** 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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