Skip to content

Commit 68f162a

Browse files
Separate memory build further. (#4143)
* Split up firestore and firestore-memory build We need to verify that the Node build still works * Fix sebstian's memory build my separating it further.. * To mangle or not to mangle. * Add the missing return! Co-authored-by: Sebastian Schmidt <[email protected]>
1 parent 26c021d commit 68f162a

File tree

11 files changed

+184
-53
lines changed

11 files changed

+184
-53
lines changed

integration/firestore/firebase_export_memory.ts

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

1818
import firebase from '@firebase/app';
1919
import '@firebase/firestore/memory';
20-
import '@firebase/firestore/bundle';
20+
import '@firebase/firestore/memory-bundle';
2121
import { FirebaseApp } from '@firebase/app-types';
2222
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
2323

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/memory/index.ts

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

2323
import '@firebase/firestore/memory';
24-
import '@firebase/firestore/bundle';
24+
import '@firebase/firestore/memory-bundle';
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/node-cjs/memory.js",
5-
"main-esm2017": "../dist/node-esm2017/memory.js",
6-
"react-native": "../dist/rn/memory.js",
7-
"browser": "../dist/esm5/memory.js",
8-
"module": "../dist/esm5/memory.js",
9-
"esm2017": "../dist/esm2017/memory.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

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"json-stable-stringify": "1.0.1",
8383
"protobufjs": "6.10.2",
8484
"rollup": "2.33.2",
85+
"rollup-plugin-copy": "3.3.0",
8586
"rollup-plugin-copy-assets": "2.0.3",
8687
"rollup-plugin-replace": "2.2.0",
8788
"rollup-plugin-sourcemaps": "0.6.3",

packages/firestore/rollup.config.browser.js

+47-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import pkg from './package.json';
22
import path from 'path';
33
import memoryPkg from './memory/package.json';
44
import bundlePkg from './bundle/package.json';
5+
import memoryBundlePkg from './memory-bundle/package.json';
56

67
/**
78
* @license
@@ -20,14 +21,14 @@ import bundlePkg from './bundle/package.json';
2021
* limitations under the License.
2122
*/
2223

23-
const alias = require('@rollup/plugin-alias');
2424
const util = require('./rollup.shared');
2525

2626
export default [
27+
// Create a temporary build that includes the mangled classes for all exports
2728
{
2829
input: 'export.ts',
2930
output: {
30-
file: 'dist/prebuild.js',
31+
file: 'dist/prebuilt.js',
3132
format: 'es',
3233
sourcemap: true
3334
},
@@ -37,10 +38,10 @@ export default [
3738
moduleSideEffects: false
3839
}
3940
},
41+
// Create main build
4042
{
4143
input: {
4244
index: 'index.ts',
43-
memory: 'index.memory.ts',
4445
bundle: 'index.bundle.ts'
4546
},
4647
output: {
@@ -49,25 +50,18 @@ export default [
4950
sourcemap: true
5051
},
5152
plugins: [
52-
alias({
53-
entries: [
54-
{
55-
find: /^(.*)\/export$/,
56-
replacement: `$1\/dist/prebuild.js`
57-
}
58-
]
59-
}),
60-
...util.es2017Plugins('browser', /* mangled= */ true)
53+
util.applyPrebuilt(),
54+
...util.es2017Plugins('browser', /* mangled= */ false)
6155
],
6256
external: util.resolveBrowserExterns,
6357
treeshake: {
6458
moduleSideEffects: false
6559
}
6660
},
61+
// Convert main build to ES5
6762
{
6863
input: {
6964
index: pkg['esm2017'],
70-
memory: path.resolve('./memory', memoryPkg['esm2017']),
7165
bundle: path.resolve('./bundle', bundlePkg['esm2017'])
7266
},
7367
output: [
@@ -77,7 +71,46 @@ export default [
7771
sourcemap: true
7872
}
7973
],
80-
plugins: util.es2017ToEs5Plugins(),
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+
],
113+
plugins: util.es2017ToEs5Plugins(/* mangled= */ true),
81114
external: util.resolveBrowserExterns,
82115
treeshake: {
83116
moduleSideEffects: false

packages/firestore/rollup.config.node.js

+42-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
*/
1717

1818
import replace from 'rollup-plugin-replace';
19-
import copy from 'rollup-plugin-copy-assets';
19+
import copy from 'rollup-plugin-copy';
2020
import pkg from './package.json';
2121
import bundlePkg from './bundle/package.json';
2222
import memoryPkg from './memory/package.json';
23+
import memoryBundlePkg from './memory-bundle/package.json';
2324
import path from 'path';
2425

2526
const util = require('./rollup.shared');
@@ -28,7 +29,6 @@ export default [
2829
{
2930
input: {
3031
index: 'index.node.ts',
31-
memory: 'index.node.memory.ts',
3232
bundle: 'index.bundle.ts'
3333
},
3434
output: {
@@ -39,10 +39,10 @@ export default [
3939
plugins: [
4040
...util.es2017Plugins('node'),
4141
replace({
42-
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos')
42+
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('../protos')
4343
}),
4444
copy({
45-
assets: ['./src/protos']
45+
targets: [{ src: 'src/protos', dest: 'dist' }]
4646
})
4747
],
4848
external: util.resolveNodeExterns,
@@ -53,7 +53,6 @@ export default [
5353
{
5454
input: {
5555
index: pkg['main-esm2017'],
56-
memory: path.resolve('./memory', memoryPkg['main-esm2017']),
5756
bundle: path.resolve('./bundle', bundlePkg['main-esm2017'])
5857
},
5958
output: [
@@ -68,5 +67,43 @@ export default [
6867
treeshake: {
6968
moduleSideEffects: false
7069
}
70+
},
71+
{
72+
input: {
73+
index: 'index.node.memory.ts',
74+
bundle: 'index.bundle.ts'
75+
},
76+
output: {
77+
dir: 'dist/memory/node-esm2017',
78+
format: 'es',
79+
sourcemap: true
80+
},
81+
plugins: [
82+
...util.es2017Plugins('node'),
83+
replace({
84+
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('../protos')
85+
})
86+
],
87+
external: util.resolveNodeExterns,
88+
treeshake: {
89+
moduleSideEffects: false
90+
}
91+
},
92+
{
93+
input: {
94+
index: path.resolve('./memory', memoryPkg['main-esm2017']),
95+
bundle: path.resolve('./bundle', memoryBundlePkg['main-esm2017'])
96+
},
97+
output: [
98+
{
99+
dir: 'dist/memory/node-cjs',
100+
format: 'cjs',
101+
sourcemap: true
102+
}
103+
],
104+
external: util.resolveNodeExterns,
105+
treeshake: {
106+
moduleSideEffects: false
107+
}
71108
}
72109
];

packages/firestore/rollup.config.rn.js

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

18-
const alias = require('@rollup/plugin-alias');
1918
const util = require('./rollup.shared');
2019

2120
export default [
21+
// Create a temporary build that includes the mangled classes for all exports
2222
{
2323
input: 'export.ts',
2424
output: {
25-
file: 'dist/prebuild.rn.js',
25+
file: 'dist/prebuilt.rn.js',
2626
format: 'es',
2727
sourcemap: true
2828
},
@@ -32,10 +32,10 @@ export default [
3232
moduleSideEffects: false
3333
}
3434
},
35+
// Create main build
3536
{
3637
input: {
3738
index: 'index.ts',
38-
memory: 'index.memory.ts',
3939
bundle: 'index.bundle.ts'
4040
},
4141
output: {
@@ -44,14 +44,27 @@ export default [
4444
sourcemap: true
4545
},
4646
plugins: [
47-
alias({
48-
entries: [
49-
{
50-
find: /^(.*)\/export$/,
51-
replacement: `$1\/dist/prebuild.rn.js`
52-
}
53-
]
54-
}),
47+
util.applyPrebuilt('prebuilt.rn.js'),
48+
...util.es2017Plugins('rn', /* mangled= */ false)
49+
],
50+
external: util.resolveBrowserExterns,
51+
treeshake: {
52+
moduleSideEffects: false
53+
}
54+
},
55+
// Create memory build
56+
{
57+
input: {
58+
index: 'index.memory.ts',
59+
bundle: 'index.bundle.ts'
60+
},
61+
output: {
62+
dir: 'dist/rn',
63+
format: 'es',
64+
sourcemap: true
65+
},
66+
plugins: [
67+
util.applyPrebuilt('prebuilt.rn.js'),
5568
...util.es2017Plugins('rn', /* mangled= */ true)
5669
],
5770
external: util.resolveBrowserExterns,

packages/firestore/rollup.shared.js

+11
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ const manglePrivatePropertiesOptions = {
203203
};
204204
exports.manglePrivatePropertiesOptions = manglePrivatePropertiesOptions;
205205

206+
exports.applyPrebuilt = function (name = 'prebuilt.js') {
207+
return alias({
208+
entries: [
209+
{
210+
find: /^(.*)\/export$/,
211+
replacement: `$1\/dist/${name}`
212+
}
213+
]
214+
});
215+
};
216+
206217
exports.es2017Plugins = function (platform, mangled = false) {
207218
if (mangled) {
208219
return [

0 commit comments

Comments
 (0)