Skip to content

Commit a5b8d3a

Browse files
authored
Roll bundle with prebuilt (#4128)
Build firestore sdks with prebuilt to support bundle as a prototype patched feature.
1 parent cc8dd9c commit a5b8d3a

28 files changed

+603
-471
lines changed

config/webpack.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = {
9595
},
9696
resolve: {
9797
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
98-
mainFields: ['browser', 'module', 'main'],
98+
mainFields: ['esm2017', 'browser', 'module', 'main'],
9999
extensions: ['.js', '.ts'],
100100
symlinks: false
101101
},

integration/firestore/firebase_export.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore';
20+
import '@firebase/firestore/bundle';
2021
import { FirebaseApp } from '@firebase/app-types';
2122
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2223

integration/firestore/firebase_export_memory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore/memory';
20+
import '@firebase/firestore/memory-bundle';
2021
import { FirebaseApp } from '@firebase/app-types';
2122
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2223

integration/firestore/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
1010
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
1111
"test:persistence": " yarn build:persistence; karma start --single-run",
12-
"test:persistence:debug:": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
12+
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
1313
"test:memory": "yarn build:memory; karma start --single-run",
1414
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
1515
},

packages/firebase/firestore/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
*/
1717

1818
import '@firebase/firestore';
19+
import '@firebase/firestore/bundle';

packages/firebase/firestore/memory/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
*/
2222

2323
import '@firebase/firestore/memory';
24+
import '@firebase/firestore/memory-bundle';
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@firebase/firestore/bundle",
3+
"description": "Firestore bundle",
4+
"main": "../dist/node-cjs/bundle.js",
5+
"main-esm2017": "../dist/node-esm2017/bundle.js",
6+
"react-native": "../dist/rn/bundle.js",
7+
"browser": "../dist/esm5/bundle.js",
8+
"module": "../dist/esm5/bundle.js",
9+
"esm2017": "../dist/esm2017/bundle.js"
10+
}

packages/firestore/export.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
export { Blob } from './src/api/blob';
19+
export {
20+
CollectionReference,
21+
DocumentReference,
22+
DocumentSnapshot,
23+
Firestore,
24+
Query,
25+
QueryDocumentSnapshot,
26+
QuerySnapshot,
27+
IndexedDbPersistenceProvider,
28+
MemoryPersistenceProvider,
29+
Transaction,
30+
WriteBatch,
31+
setLogLevel,
32+
CACHE_SIZE_UNLIMITED
33+
} from './src/api/database';
34+
export { GeoPoint } from './src/api/geo_point';
35+
export { FieldPath } from './src/api/field_path';
36+
export { FieldValue } from './src/compat/field_value';
37+
export { Timestamp } from './src/api/timestamp';
38+
export { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
39+
export { loadBundle, namedQuery } from './src/api/bundle';

packages/firestore/externs.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"packages/webchannel-wrapper/src/index.d.ts",
2929
"packages/util/dist/src/crypt.d.ts",
3030
"packages/util/dist/src/environment.d.ts",
31+
"packages/firestore/export.ts",
3132
"packages/firestore/src/protos/firestore_bundle_proto.ts",
3233
"packages/firestore/src/protos/firestore_proto_api.ts",
3334
"packages/firestore/src/util/error.ts",

packages/firestore/index.bundle.ts

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

18-
import { Firestore } from './src/api/database';
19-
import { loadBundle, namedQuery } from './src/api/bundle';
18+
import { Firestore, loadBundle, namedQuery } from './export';
2019

2120
/**
22-
* Registers Firestore bundle loading features with the components framework.
21+
* Prototype patches bundle loading to Firestore.
2322
*/
2423
export function registerBundle(instance: typeof Firestore): void {
2524
instance.prototype.loadBundle = function (

packages/firestore/index.memory.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import firebase from '@firebase/app';
1919
import { FirebaseNamespace } from '@firebase/app-types';
2020

21-
import { Firestore, MemoryPersistenceProvider } from './src/api/database';
22-
import { FirebaseFirestore } from './exp/src/api/database';
21+
import {
22+
Firestore,
23+
MemoryPersistenceProvider,
24+
ExpFirebaseFirestore
25+
} from './export';
2326
import { configureForFirebase } from './src/config';
2427

2528
import './register-module';
@@ -35,7 +38,7 @@ export function registerFirestore(instance: FirebaseNamespace): void {
3538
(app, auth) =>
3639
new Firestore(
3740
app,
38-
new FirebaseFirestore(app, auth),
41+
new ExpFirebaseFirestore(app, auth),
3942
new MemoryPersistenceProvider()
4043
)
4144
);

packages/firestore/index.rn.memory.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import firebase from '@firebase/app';
1919
import { FirebaseNamespace } from '@firebase/app-types';
2020

21-
import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
22-
import { Firestore, MemoryPersistenceProvider } from './src/api/database';
21+
import {
22+
Firestore,
23+
MemoryPersistenceProvider,
24+
ExpFirebaseFirestore
25+
} from './export';
2326
import { configureForFirebase } from './src/config';
2427

2528
import './register-module';

packages/firestore/index.rn.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
import firebase from '@firebase/app';
1818
import { FirebaseNamespace } from '@firebase/app-types';
1919

20-
import { Firestore, IndexedDbPersistenceProvider } from './src/api/database';
20+
import {
21+
Firestore,
22+
IndexedDbPersistenceProvider,
23+
ExpFirebaseFirestore
24+
} from './export';
2125
import { configureForFirebase } from './src/config';
22-
import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
2326

2427
import './register-module';
2528
import { name, version } from './package.json';

packages/firestore/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
import firebase from '@firebase/app';
1919
import { FirebaseNamespace } from '@firebase/app-types';
2020

21-
import { Firestore, IndexedDbPersistenceProvider } from './src/api/database';
22-
import { FirebaseFirestore as ExpFirebaseFirestore } from './exp/src/api/database';
21+
import {
22+
Firestore,
23+
IndexedDbPersistenceProvider,
24+
ExpFirebaseFirestore
25+
} from './export';
2326
import { configureForFirebase } from './src/config';
2427
import { name, version } from './package.json';
2528

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@firebase/firestore/memory-bundle",
3+
"description": "Firestore bundle",
4+
"main": "../dist/memory/node-cjs/bundle.js",
5+
"main-esm2017": "../dist/memory/node-esm2017/bundle.js",
6+
"react-native": "../dist/memory/rn/bundle.js",
7+
"browser": "../dist/memory/esm5/bundle.js",
8+
"module": "../dist/memory/esm5/bundle.js",
9+
"esm2017": "../dist/memory/esm2017/bundle.js"
10+
}
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@firebase/firestore/memory",
33
"description": "A memory-only build of the Cloud Firestore JS SDK.",
4-
"main": "../dist/index.memory.node.cjs.js",
5-
"main-esm2017": "../dist/index.memory.node.esm2017.js",
6-
"react-native": "../dist/index.memory.rn.esm2017.js",
7-
"browser": "../dist/index.memory.esm.js",
8-
"module": "../dist/index.memory.esm.js",
9-
"esm2017": "../dist/index.memory.esm2017.js",
4+
"main": "../dist/memory/node-cjs/index.js",
5+
"main-esm2017": "../dist/memory/node-esm2017/index.js",
6+
"react-native": "../dist/memory/rn/index.js",
7+
"browser": "../dist/memory/esm5/index.js",
8+
"module": "../dist/memory/esm5/index.js",
9+
"esm2017": "../dist/memory/esm2017/index.js",
1010
"typings": "../dist/index.d.ts"
1111
}

packages/firestore/package.json

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
99
"scripts": {
1010
"bundle": "rollup -c",
11-
"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",
11+
"build": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js' build:lite build:exp",
1212
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
13-
"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'",
13+
"build:release": "run-p 'bundle rollup.config.browser.js' 'bundle rollup.config.node.js' 'bundle rollup.config.rn.js'",
1414
"build:deps": "lerna run --scope @firebase/firestore --include-dependencies build",
1515
"build:console": "node tools/console.build.js",
1616
"build:exp": "rollup -c rollup.config.exp.js",
1717
"build:lite": "rollup -c rollup.config.lite.js",
1818
"build:exp:release": "yarn build:exp && yarn build:lite",
19+
"build:browser": "rollup -c rollup.config.browser.js",
1920
"predev": "yarn prebuild",
2021
"dev": "rollup -c -w",
2122
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
@@ -45,16 +46,18 @@
4546
"predoc": "node ../../scripts/exp/remove-exp.js temp",
4647
"doc": "api-documenter markdown --input temp --output docs"
4748
},
48-
"main": "dist/index.node.cjs.js",
49-
"main-esm2017": "dist/index.node.esm2017.js",
50-
"react-native": "dist/index.rn.esm2017.js",
51-
"browser": "dist/index.esm.js",
52-
"module": "dist/index.esm.js",
53-
"esm2017": "dist/index.esm2017.js",
49+
"main": "dist/node-cjs/index.js",
50+
"main-esm2017": "dist/node-esm2017/index.js",
51+
"react-native": "dist/rn/index.js",
52+
"browser": "dist/esm5/index.js",
53+
"module": "dist/esm5/index.js",
54+
"esm2017": "dist/esm2017/index.js",
5455
"license": "Apache-2.0",
5556
"files": [
5657
"dist",
57-
"memory/package.json"
58+
"memory/package.json",
59+
"bundle/package.json",
60+
"memory-bundle/package.json"
5861
],
5962
"dependencies": {
6063
"@firebase/component": "0.1.21",
@@ -80,7 +83,8 @@
8083
"json-stable-stringify": "1.0.1",
8184
"protobufjs": "6.10.2",
8285
"rollup": "2.33.2",
83-
"rollup-plugin-copy-assets": "1.1.0",
86+
"rollup-plugin-copy": "3.3.0",
87+
"rollup-plugin-copy-assets": "2.0.3",
8488
"rollup-plugin-replace": "2.2.0",
8589
"rollup-plugin-sourcemaps": "0.6.3",
8690
"rollup-plugin-terser": "7.0.2",

packages/firestore/rollup.config.browser.js

+80-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import pkg from './package.json';
2+
import path from 'path';
3+
import memoryPkg from './memory/package.json';
4+
import bundlePkg from './bundle/package.json';
5+
import memoryBundlePkg from './memory-bundle/package.json';
6+
17
/**
28
* @license
39
* Copyright 2020 Google LLC
@@ -15,15 +21,14 @@
1521
* limitations under the License.
1622
*/
1723

18-
import pkg from './package.json';
19-
2024
const util = require('./rollup.shared');
2125

2226
export default [
27+
// Create a temporary build that includes the mangled classes for all exports
2328
{
24-
input: 'index.ts',
29+
input: 'export.ts',
2530
output: {
26-
file: pkg.esm2017,
31+
file: 'dist/prebuilt.js',
2732
format: 'es',
2833
sourcemap: true
2934
},
@@ -33,9 +38,78 @@ export default [
3338
moduleSideEffects: false
3439
}
3540
},
41+
// Create main build
42+
{
43+
input: {
44+
index: 'index.ts',
45+
bundle: 'index.bundle.ts'
46+
},
47+
output: {
48+
dir: 'dist/esm2017',
49+
format: 'es',
50+
sourcemap: true
51+
},
52+
plugins: [
53+
util.applyPrebuilt(),
54+
...util.es2017Plugins('browser', /* mangled= */ false)
55+
],
56+
external: util.resolveBrowserExterns,
57+
treeshake: {
58+
moduleSideEffects: false
59+
}
60+
},
61+
// Convert main build to ES5
3662
{
37-
input: pkg.esm2017,
38-
output: { file: pkg.module, format: 'es', sourcemap: true },
63+
input: {
64+
index: pkg['esm2017'],
65+
bundle: path.resolve('./bundle', bundlePkg['esm2017'])
66+
},
67+
output: [
68+
{
69+
dir: 'dist/esm5',
70+
format: 'es',
71+
sourcemap: true
72+
}
73+
],
74+
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
75+
external: util.resolveBrowserExterns,
76+
treeshake: {
77+
moduleSideEffects: false
78+
}
79+
},
80+
// Create memory build
81+
{
82+
input: {
83+
index: 'index.memory.ts',
84+
bundle: 'index.bundle.ts'
85+
},
86+
output: {
87+
dir: 'dist/memory/esm2017',
88+
format: 'es',
89+
sourcemap: true
90+
},
91+
plugins: [
92+
util.applyPrebuilt(),
93+
...util.es2017Plugins('browser', /* mangled= */ false)
94+
],
95+
external: util.resolveBrowserExterns,
96+
treeshake: {
97+
moduleSideEffects: false
98+
}
99+
},
100+
// Convert memory build to ES5
101+
{
102+
input: {
103+
index: path.resolve('./memory', memoryPkg['esm2017']),
104+
bundle: path.resolve('./bundle', memoryBundlePkg['esm2017'])
105+
},
106+
output: [
107+
{
108+
dir: 'dist/memory/esm5',
109+
format: 'es',
110+
sourcemap: true
111+
}
112+
],
39113
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
40114
external: util.resolveBrowserExterns,
41115
treeshake: {

0 commit comments

Comments
 (0)