Skip to content

Commit 860b649

Browse files
RFC: Memory-only Firestore build
1 parent c48114c commit 860b649

File tree

17 files changed

+665
-286
lines changed

17 files changed

+665
-286
lines changed

integration/firestore/gulpfile.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ function clean() {
2727
return del(['temp/**/*', 'dist/**/*']);
2828
}
2929

30+
function isPersistenceEnabled() {
31+
return process.env.USE_FIRESTORE_PERSISTENCE !== 'false';
32+
}
33+
3034
function copyTests() {
3135
/**
3236
* NOTE: We intentionally don't copy src/ files (to make sure we are only
@@ -37,7 +41,9 @@ function copyTests() {
3741
const firebaseAppSdk = 'firebase/app/dist/index.esm.js';
3842
const firebaseFirestoreSdk = resolve(
3943
__dirname,
40-
'../../packages/firestore/dist/index.esm.min.js'
44+
isPersistenceEnabled()
45+
? '../../packages/firestore/dist/index.esm.min.js'
46+
: '../../packages/firestore/dist/index.memory.esm.js'
4147
);
4248
return gulp
4349
.src(
@@ -63,7 +69,14 @@ function copyTests() {
6369
*/
6470
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
6571
`import firebase from '${firebaseAppSdk}';
66-
import '${firebaseFirestoreSdk}';`
72+
import '${firebaseFirestoreSdk}';
73+
74+
if (typeof process === 'undefined') {
75+
process = { env: { USE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
76+
} else {
77+
process.env.USE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
78+
}
79+
`
6780
)
6881
)
6982
.pipe(

integration/firestore/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
"version": "1.0.1",
44
"private": true,
55
"scripts": {
6-
"build": "(cd ../../ ; yarn build) ; gulp compile-tests",
6+
"build:dependencies": "(cd ../../ ; yarn build)",
7+
"build": "yarn build:dependencies; USE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
8+
"build:memory": "yarn build:dependencies; USE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
9+
"pretest": "yarn build:dependencies",
710
"pretest:manual": "yarn build",
11+
"pretest:manual:memory": "yarn build:memory",
812
"pretest:debug": "yarn build",
9-
"test": "echo 'Automated tests temporarily disabled, run `yarn test:manual` to execute these tests'",
13+
"pretest:debug:memort": "yarn build:memory",
14+
"test": "USE_FIRESTORE_PERSISTENCE=true gulp compile-tests; karma start --single-run; USE_FIRESTORE_PERSISTENCE=false gulp compile-tests; karma start --single-run;",
1015
"test:manual": "karma start --single-run",
11-
"test:debug": "karma start --auto-watch --browsers Chrome"
16+
"test:manual:memory": "karma start --single-run",
17+
"test:debug": "karma start --auto-watch --browsers Chrome",
18+
"test:debug:memory": "karma start --single-run"
1219
},
1320
"devDependencies": {
1421
"@types/mocha": "7.0.1",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google Inc.
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+
import '../../firestore/dist/index.memory.esm';

packages/firebase/rollup.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ const firestoreMinifiedBuild = {
154154
external: ['@firebase/app']
155155
};
156156

157+
const firestoreMemoryBuild = {
158+
input: `firestore/index.memory.ts`,
159+
output: createUmdOutputConfig(`firebase-firestore.memory.js`),
160+
plugins: [...plugins, uglify()],
161+
external: ['@firebase/app']
162+
};
163+
157164
/**
158165
* Complete Package Builds
159166
*/
@@ -271,5 +278,6 @@ export default [
271278
...appBuilds,
272279
...componentBuilds,
273280
firestoreMinifiedBuild,
281+
firestoreMemoryBuild,
274282
...completeBuilds
275283
];

packages/firestore/index.memory.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google Inc.
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+
import firebase from '@firebase/app';
19+
import * as types from '@firebase/firestore-types';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
22+
import { configureForFirebase } from './src/platform/config';
23+
import './src/platform_browser/browser_init';
24+
25+
import { name, version } from './package.json';
26+
27+
export function registerFirestore(instance: FirebaseNamespace): void {
28+
configureForFirebase(instance);
29+
instance.registerVersion(name, version);
30+
}
31+
32+
registerFirestore(firebase);
33+
34+
declare module '@firebase/app-types' {
35+
interface FirebaseNamespace {
36+
firestore?: {
37+
(app?: FirebaseApp): types.FirebaseFirestore;
38+
Blob: typeof types.Blob;
39+
CollectionReference: typeof types.CollectionReference;
40+
DocumentReference: typeof types.DocumentReference;
41+
DocumentSnapshot: typeof types.DocumentSnapshot;
42+
FieldPath: typeof types.FieldPath;
43+
FieldValue: typeof types.FieldValue;
44+
Firestore: typeof types.FirebaseFirestore;
45+
GeoPoint: typeof types.GeoPoint;
46+
Query: typeof types.Query;
47+
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
48+
QuerySnapshot: typeof types.QuerySnapshot;
49+
Timestamp: typeof types.Timestamp;
50+
Transaction: typeof types.Transaction;
51+
WriteBatch: typeof types.WriteBatch;
52+
setLogLevel: typeof types.setLogLevel;
53+
};
54+
}
55+
interface FirebaseApp {
56+
firestore?(): types.FirebaseFirestore;
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google Inc.
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+
import firebase from '@firebase/app';
19+
import * as types from '@firebase/firestore-types';
20+
import { FirebaseNamespace } from '@firebase/app-types';
21+
22+
import { configureForFirebase } from './src/platform/config';
23+
import './src/platform_browser/browser_init';
24+
25+
import { name, version } from './package.json';
26+
27+
export function registerFirestore(instance: FirebaseNamespace): void {
28+
configureForFirebase(instance);
29+
instance.registerVersion(name, version);
30+
}
31+
32+
registerFirestore(firebase);
33+
34+
declare module '@firebase/app-types' {
35+
interface FirebaseNamespace {
36+
firestore?: {
37+
(app?: FirebaseApp): types.FirebaseFirestore;
38+
Blob: typeof types.Blob;
39+
CollectionReference: typeof types.CollectionReference;
40+
DocumentReference: typeof types.DocumentReference;
41+
DocumentSnapshot: typeof types.DocumentSnapshot;
42+
FieldPath: typeof types.FieldPath;
43+
FieldValue: typeof types.FieldValue;
44+
Firestore: typeof types.FirebaseFirestore;
45+
GeoPoint: typeof types.GeoPoint;
46+
Query: typeof types.Query;
47+
QueryDocumentSnapshot: typeof types.QueryDocumentSnapshot;
48+
QuerySnapshot: typeof types.QuerySnapshot;
49+
Timestamp: typeof types.Timestamp;
50+
Transaction: typeof types.Transaction;
51+
WriteBatch: typeof types.WriteBatch;
52+
setLogLevel: typeof types.setLogLevel;
53+
};
54+
}
55+
interface FirebaseApp {
56+
firestore?(): types.FirebaseFirestore;
57+
}
58+
}

packages/firestore/index.node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import firebase from '@firebase/app';
1818
import * as types from '@firebase/firestore-types';
1919
import { configureForFirebase } from './src/platform/config';
20+
import { registerFirestorePersistence } from './src/platform/persistence';
2021
import './src/platform_node/node_init';
2122
import { FirebaseNamespace } from '@firebase/app-types';
2223

2324
import { name, version } from './package.json';
2425

2526
export function registerFirestore(instance: FirebaseNamespace): void {
2627
configureForFirebase(instance);
28+
registerFirestorePersistence(instance);
2729
instance.registerVersion(name, version, 'node');
2830
}
2931

packages/firestore/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import firebase from '@firebase/app';
1919
import { configureForFirebase } from './src/platform/config';
20+
import { registerFirestorePersistence } from './src/platform/persistence';
2021
import './src/platform_browser/browser_init';
2122

2223
import * as types from '@firebase/firestore-types';
@@ -26,6 +27,7 @@ import { name, version } from './package.json';
2627

2728
export function registerFirestore(instance: FirebaseNamespace): void {
2829
configureForFirebase(instance);
30+
registerFirestorePersistence(instance);
2931
instance.registerVersion(name, version);
3032
}
3133

packages/firestore/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
"test:node:persistence": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
2121
"test:node:persistence:prod": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --opts ../../config/mocha.node.opts",
2222
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
23-
"test:minified": "(cd ../../integration/firestore ; yarn test:manual)",
23+
"test:minified": "(cd ../../integration/firestore ; yarn test)",
2424
"prepare": "yarn build"
2525
},
2626
"main": "dist/index.node.cjs.js",
27+
"mainMemoryPersistence": "dist/index.node.memory.cjs.js",
2728
"browser": "dist/index.cjs.js",
2829
"browserMinified": "dist/index.cjs.min.js",
30+
"browserMemoryPersistence": "dist/index.memory.cjs.js",
2931
"module": "dist/index.esm.js",
3032
"moduleMinified": "dist/index.esm.min.js",
33+
"moduleMemoryPersistence": "dist/index.memory.esm.js",
3134
"esm2017": "dist/index.esm2017.js",
3235
"esm2017Minified": "dist/index.esm2017.min.js",
36+
"esm2017MemoryPersistence": "dist/index.memory.esm2017.js",
3337
"license": "Apache-2.0",
3438
"files": [
3539
"dist"

0 commit comments

Comments
 (0)