Skip to content

A few fixes for Firestore bundle sdk builds #4177

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 8 commits into from
Dec 7, 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
18 changes: 18 additions & 0 deletions packages/firebase/firestore/bundle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @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.
*/

import '@firebase/firestore/bundle';
7 changes: 7 additions & 0 deletions packages/firebase/firestore/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "firebase/firestore/bundle",
"description": "The bundle loading feature of the Cloud Firestore component.",
"main": "dist/index.node.cjs.js",
"module": "dist/index.esm.js",
"typings": "../empty-import.d.ts"
}
19 changes: 19 additions & 0 deletions packages/firebase/firestore/index.cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @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.
*/

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

import '@firebase/firestore';
import '@firebase/firestore/bundle';
23 changes: 23 additions & 0 deletions packages/firebase/firestore/memory/bundle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @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.
*/

/**
* This file serves as the public entrypoint for users that import
* `firebase/firestore/memory`.
*/

import '@firebase/firestore/memory-bundle';
7 changes: 7 additions & 0 deletions packages/firebase/firestore/memory/bundle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "firebase/firestore/memory",
"description": "The bundle loading feature for the memory-only build of the Cloud Firestore JS SDK.",
"main": "dist/index.node.cjs.js",
"module": "dist/index.esm.js",
"typings": "../../empty-import.d.ts"
}
24 changes: 24 additions & 0 deletions packages/firebase/firestore/memory/index.cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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.
*/

/**
* This file serves as the public entrypoint for users that import
* `firebase/firestore/memory`.
*/

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

import '@firebase/firestore/memory';
import '@firebase/firestore/memory-bundle';
2 changes: 1 addition & 1 deletion packages/firebase/firestore/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "firebase/firestore",
"description": "The Cloud Firestore component of the Firebase JS SDK.",
"main": "dist/index.cjs.js",
"main": "dist/index.node.cjs.js",
"module": "dist/index.esm.js",
"typings": "../empty-import.d.ts"
}
87 changes: 83 additions & 4 deletions packages/firebase/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import pkg from './package.json';

import appPkg from './app/package.json';

import firestorePkg from './firestore/package.json';
import firestoreBundlePkg from './firestore/bundle/package.json';

import firestoreMemoryPkg from './firestore/memory/package.json';
import firestoreMemoryBundlePkg from './firestore/memory/bundle/package.json';

function createUmdOutputConfig(output) {
return {
file: output,
Expand Down Expand Up @@ -111,7 +117,9 @@ const appBuilds = [

const componentBuilds = pkg.components
// The "app" component is treated differently because it doesn't depend on itself.
.filter(component => component !== 'app')
// The "firestore" component is treated differently because it contains multiple
// sub components for different builds.
.filter(component => component !== 'app' && component !== 'firestore')
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update comment.

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.

.map(component => {
const pkg = require(`./${component}/package.json`);
return [
Expand Down Expand Up @@ -149,17 +157,67 @@ const componentBuilds = pkg.components
})
.reduce((a, b) => a.concat(b), []);

const firestoreBuilds = [
{
input: `firestore/index.ts`,
output: [
{
file: resolve('firestore', firestorePkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve('firestore', firestorePkg.module),
format: 'es',
sourcemap: true
}
],
plugins,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not need

uglify({
           output: {
             ascii_only: true // escape unicode chars
            }	               
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The index.ts is just import '@firebase/firestore'; (so is the output), I think we can skip it here.

external
},
{
input: `firestore/bundle/index.ts`,
output: [
{
file: resolve('firestore/bundle', firestoreBundlePkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve('firestore/bundle', firestoreBundlePkg.module),
format: 'es',
sourcemap: true
}
],
plugins,
external
},
{
input: `firestore/index.cdn.ts`,
output: createUmdOutputConfig(`firebase-firestore.js`),
plugins: [
...plugins,
uglify({
output: {
ascii_only: true // escape unicode chars
}
})
],
external: ['@firebase/app']
}
];

const firestoreMemoryBuilds = [
{
input: `firestore/memory/index.ts`,
output: [
{
file: resolve('firestore/memory', pkg.main),
file: resolve('firestore/memory', firestoreMemoryPkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve('firestore/memory', pkg.module),
file: resolve('firestore/memory', firestoreMemoryPkg.module),
format: 'es',
sourcemap: true
}
Expand All @@ -168,7 +226,27 @@ const firestoreMemoryBuilds = [
external
},
{
input: `firestore/memory/index.ts`,
input: `firestore/memory/bundle/index.ts`,
output: [
{
file: resolve('firestore/memory/bundle', firestoreMemoryBundlePkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve(
'firestore/memory/bundle',
firestoreMemoryBundlePkg.module
),
format: 'es',
sourcemap: true
}
],
plugins,
external
},
{
input: `firestore/memory/index.cdn.ts`,
output: createUmdOutputConfig(`firebase-firestore.memory.js`),
plugins: [...plugins, uglify()],
external: ['@firebase/app']
Expand Down Expand Up @@ -276,6 +354,7 @@ const completeBuilds = [
export default [
...appBuilds,
...componentBuilds,
...firestoreBuilds,
...firestoreMemoryBuilds,
...completeBuilds
];
1 change: 1 addition & 0 deletions packages/firebase/src/index.cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { name, version } from '../package.json';
import '../auth';
import '../database';
import '../firestore';
import '../firestore/bundle';
import '../functions';
import '../messaging';
import '../storage';
Expand Down
1 change: 1 addition & 0 deletions packages/firebase/src/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { name, version } from '../package.json';
import '../auth';
import '../database';
import '../firestore';
import '../firestore/bundle';
import '../functions';

firebase.registerVersion(name, version, 'node');
Expand Down
1 change: 1 addition & 0 deletions packages/firebase/src/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../database';
// `atob`). We should provide a RN build that works out of the box.
import '../storage';
import '../firestore';
import '../firestore/bundle';
Copy link
Contributor

Choose a reason for hiding this comment

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

The React Nativce build of the main Firestore package splits up bundles and non-bundled code. I think we should do the same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for "complete" build, which include everything (except memory only builds) on other platforms.


firebase.registerVersion(name, version, 'rn');

Expand Down
1 change: 1 addition & 0 deletions packages/firebase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { name, version } from '../package.json';
import '../auth';
import '../database';
import '../firestore';
import '../firestore/bundle';
import '../functions';
import '../messaging';
import '../storage';
Expand Down
3 changes: 3 additions & 0 deletions packages/firestore/rollup.config.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export default [
...util.es2017Plugins('node'),
replace({
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('../protos')
}),
copy({
targets: [{ src: 'src/protos', dest: 'dist/memory' }]
})
],
external: util.resolveNodeExterns,
Expand Down