Skip to content

Roll bundle with prebuilt #4128

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

Merged
merged 18 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = {
},
resolve: {
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
mainFields: ['browser', 'module', 'main'],
mainFields: ['esm2017', 'browser', 'module', 'main'],
extensions: ['.js', '.ts'],
symlinks: false
},
Expand Down
1 change: 1 addition & 0 deletions integration/firestore/firebase_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import firebase from '@firebase/app';
import '@firebase/firestore';
import '@firebase/firestore/bundle';
import { FirebaseApp } from '@firebase/app-types';
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';

Expand Down
1 change: 1 addition & 0 deletions integration/firestore/firebase_export_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import firebase from '@firebase/app';
import '@firebase/firestore/memory';
import '@firebase/firestore/memory-bundle';
import { FirebaseApp } from '@firebase/app-types';
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';

Expand Down
2 changes: 1 addition & 1 deletion integration/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
"test:persistence": " yarn build:persistence; karma start --single-run",
"test:persistence:debug:": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
"test:memory": "yarn build:memory; karma start --single-run",
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
},
Expand Down
1 change: 1 addition & 0 deletions packages/firebase/firestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
*/

import '@firebase/firestore';
import '@firebase/firestore/bundle';
1 change: 1 addition & 0 deletions packages/firebase/firestore/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
*/

import '@firebase/firestore/memory';
import '@firebase/firestore/memory-bundle';
10 changes: 10 additions & 0 deletions packages/firestore/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@firebase/firestore/bundle",
"description": "Firestore bundle",
"main": "../dist/node-cjs/bundle.js",
"main-esm2017": "../dist/node-esm2017/bundle.js",
"react-native": "../dist/rn/bundle.js",
"browser": "../dist/esm5/bundle.js",
"module": "../dist/esm5/bundle.js",
"esm2017": "../dist/esm2017/bundle.js"
}
39 changes: 39 additions & 0 deletions packages/firestore/export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export { Blob } from './src/api/blob';
export {
CollectionReference,
DocumentReference,
DocumentSnapshot,
Firestore,
Query,
QueryDocumentSnapshot,
QuerySnapshot,
IndexedDbPersistenceProvider,
MemoryPersistenceProvider,
Transaction,
WriteBatch,
setLogLevel,
CACHE_SIZE_UNLIMITED
} from './src/api/database';
export { GeoPoint } from './src/api/geo_point';
export { FieldPath } from './src/api/field_path';
export { FieldValue } from './src/compat/field_value';
export { Timestamp } from './src/api/timestamp';
export { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
export { loadBundle, namedQuery } from './src/api/bundle';
1 change: 1 addition & 0 deletions packages/firestore/externs.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"packages/webchannel-wrapper/src/index.d.ts",
"packages/util/dist/src/crypt.d.ts",
"packages/util/dist/src/environment.d.ts",
"packages/firestore/export.ts",
"packages/firestore/src/protos/firestore_bundle_proto.ts",
"packages/firestore/src/protos/firestore_proto_api.ts",
"packages/firestore/src/util/error.ts",
Expand Down
5 changes: 2 additions & 3 deletions packages/firestore/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* limitations under the License.
*/

import { Firestore } from './src/api/database';
import { loadBundle, namedQuery } from './src/api/bundle';
import { Firestore, loadBundle, namedQuery } from './export';

/**
* Registers Firestore bundle loading features with the components framework.
* Prototype patches bundle loading to Firestore.
*/
export function registerBundle(instance: typeof Firestore): void {
instance.prototype.loadBundle = function (
Expand Down
9 changes: 6 additions & 3 deletions packages/firestore/index.memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import firebase from '@firebase/app';
import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore, MemoryPersistenceProvider } from './src/api/database';
import { FirebaseFirestore } from './exp/src/api/database';
import {
Firestore,
MemoryPersistenceProvider,
ExpFirebaseFirestore
} from './export';
import { configureForFirebase } from './src/config';

import './register-module';
Expand All @@ -35,7 +38,7 @@ export function registerFirestore(instance: FirebaseNamespace): void {
(app, auth) =>
new Firestore(
app,
new FirebaseFirestore(app, auth),
new ExpFirebaseFirestore(app, auth),
new MemoryPersistenceProvider()
)
);
Expand Down
7 changes: 5 additions & 2 deletions packages/firestore/index.rn.memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import firebase from '@firebase/app';
import { FirebaseNamespace } from '@firebase/app-types';

import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
import { Firestore, MemoryPersistenceProvider } from './src/api/database';
import {
Firestore,
MemoryPersistenceProvider,
ExpFirebaseFirestore
} from './export';
import { configureForFirebase } from './src/config';

import './register-module';
Expand Down
7 changes: 5 additions & 2 deletions packages/firestore/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import firebase from '@firebase/app';
import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore, IndexedDbPersistenceProvider } from './src/api/database';
import {
Firestore,
IndexedDbPersistenceProvider,
ExpFirebaseFirestore
} from './export';
import { configureForFirebase } from './src/config';
import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';

import './register-module';
import { name, version } from './package.json';
Expand Down
7 changes: 5 additions & 2 deletions packages/firestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
import firebase from '@firebase/app';
import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore, IndexedDbPersistenceProvider } from './src/api/database';
import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
import {
Firestore,
IndexedDbPersistenceProvider,
ExpFirebaseFirestore
} from './export';
import { configureForFirebase } from './src/config';
import { name, version } from './package.json';

Expand Down
10 changes: 10 additions & 0 deletions packages/firestore/memory-bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@firebase/firestore/memory-bundle",
"description": "Firestore bundle",
"main": "../dist/memory/node-cjs/bundle.js",
"main-esm2017": "../dist/memory/node-esm2017/bundle.js",
"react-native": "../dist/memory/rn/bundle.js",
"browser": "../dist/memory/esm5/bundle.js",
"module": "../dist/memory/esm5/bundle.js",
"esm2017": "../dist/memory/esm2017/bundle.js"
}
12 changes: 6 additions & 6 deletions packages/firestore/memory/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@firebase/firestore/memory",
"description": "A memory-only build of the Cloud Firestore JS SDK.",
"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.esm.js",
"module": "../dist/index.memory.esm.js",
"esm2017": "../dist/index.memory.esm2017.js",
"main": "../dist/memory/node-cjs/index.js",
"main-esm2017": "../dist/memory/node-esm2017/index.js",
"react-native": "../dist/memory/rn/index.js",
"browser": "../dist/memory/esm5/index.js",
"module": "../dist/memory/esm5/index.js",
"esm2017": "../dist/memory/esm2017/index.js",
"typings": "../dist/index.d.ts"
}
24 changes: 14 additions & 10 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"scripts": {
"bundle": "rollup -c",
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.browser.memory.js' 'bundle rollup.config.node.js' 'bundle rollup.config.node.memory.js' 'bundle rollup.config.rn.js' 'bundle rollup.config.rn.memory.js' build:lite build:exp",
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js' build:lite build:exp",
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.browser.memory.js' 'bundle rollup.config.node.js' 'bundle rollup.config.node.memory.js' 'bundle rollup.config.rn.js' 'bundle rollup.config.rn.memory.js'",
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js'",
"build:deps": "lerna run --scope @firebase/firestore --include-dependencies build",
"build:console": "node tools/console.build.js",
"build:exp": "rollup -c rollup.config.exp.js",
"build:lite": "rollup -c rollup.config.lite.js",
"build:exp:release": "yarn build:exp && yarn build:lite",
"build:browser": "rollup -c rollup.config.browser.js",
"predev": "yarn prebuild",
"dev": "rollup -c -w",
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
Expand Down Expand Up @@ -45,16 +46,18 @@
"predoc": "node ../../scripts/exp/remove-exp.js temp",
"doc": "api-documenter markdown --input temp --output docs"
},
"main": "dist/index.node.cjs.js",
"main-esm2017": "dist/index.node.esm2017.js",
"react-native": "dist/index.rn.esm2017.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"main": "dist/node-cjs/index.js",
"main-esm2017": "dist/node-esm2017/index.js",
"react-native": "dist/rn/index.js",
"browser": "dist/esm5/index.js",
"module": "dist/esm5/index.js",
"esm2017": "dist/esm2017/index.js",
"license": "Apache-2.0",
"files": [
"dist",
"memory/package.json"
"memory/package.json",
"bundle/package.json",
"memory-bundle/package.json"
],
"dependencies": {
"@firebase/component": "0.1.21",
Expand All @@ -80,7 +83,8 @@
"json-stable-stringify": "1.0.1",
"protobufjs": "6.10.2",
"rollup": "2.33.2",
"rollup-plugin-copy-assets": "1.1.0",
"rollup-plugin-copy": "3.3.0",
"rollup-plugin-copy-assets": "2.0.3",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-sourcemaps": "0.6.3",
"rollup-plugin-terser": "7.0.2",
Expand Down
86 changes: 80 additions & 6 deletions packages/firestore/rollup.config.browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import pkg from './package.json';
import path from 'path';
import memoryPkg from './memory/package.json';
import bundlePkg from './bundle/package.json';
import memoryBundlePkg from './memory-bundle/package.json';

/**
* @license
* Copyright 2020 Google LLC
Expand All @@ -15,15 +21,14 @@
* limitations under the License.
*/

import pkg from './package.json';

const util = require('./rollup.shared');

export default [
// Create a temporary build that includes the mangled classes for all exports
{
input: 'index.ts',
input: 'export.ts',
output: {
file: pkg.esm2017,
file: 'dist/prebuilt.js',
format: 'es',
sourcemap: true
},
Expand All @@ -33,9 +38,78 @@ export default [
moduleSideEffects: false
}
},
// Create main build
{
input: {
index: 'index.ts',
bundle: 'index.bundle.ts'
},
output: {
dir: 'dist/esm2017',
format: 'es',
sourcemap: true
},
plugins: [
util.applyPrebuilt(),
...util.es2017Plugins('browser', /* mangled= */ false)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be mangled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline, this should be false.

],
external: util.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
},
// Convert main build to ES5
{
input: pkg.esm2017,
output: { file: pkg.module, format: 'es', sourcemap: true },
input: {
index: pkg['esm2017'],
bundle: path.resolve('./bundle', bundlePkg['esm2017'])
},
output: [
{
dir: 'dist/esm5',
format: 'es',
sourcemap: true
}
],
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
external: util.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
},
// Create memory build
{
input: {
index: 'index.memory.ts',
bundle: 'index.bundle.ts'
},
output: {
dir: 'dist/memory/esm2017',
format: 'es',
sourcemap: true
},
plugins: [
util.applyPrebuilt(),
...util.es2017Plugins('browser', /* mangled= */ false)
],
external: util.resolveBrowserExterns,
treeshake: {
moduleSideEffects: false
}
},
// Convert memory build to ES5
{
input: {
index: path.resolve('./memory', memoryPkg['esm2017']),
bundle: path.resolve('./bundle', memoryBundlePkg['esm2017'])
},
output: [
{
dir: 'dist/memory/esm5',
format: 'es',
sourcemap: true
}
],
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
external: util.resolveBrowserExterns,
treeshake: {
Expand Down
Loading