Skip to content

Commit a5d80d9

Browse files
Memory-only Firestore build (#2608)
1 parent c8bebeb commit a5d80d9

25 files changed

+835
-343
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.INCLUDE_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.js'
44+
isPersistenceEnabled()
45+
? '../../packages/firestore/dist/index.esm.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: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
76+
} else {
77+
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
78+
}
79+
`
6780
)
6881
)
6982
.pipe(

integration/firestore/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"version": "1.0.1",
44
"private": true,
55
"scripts": {
6-
"build": "gulp compile-tests",
7-
"build:deps": "cd ../../ ; yarn build",
8-
"pretest:manual": "yarn build",
9-
"pretest:debug": "yarn build:deps && yarn build",
10-
"test": "echo 'Automated tests temporarily disabled, run `yarn test:manual` to execute these tests'",
11-
"test:manual": "karma start --single-run",
12-
"test:debug": "karma start --auto-watch --browsers Chrome"
6+
"build:deps": "cd ../../packages/firestore ; yarn build",
7+
"build:persistence": "INCLUDE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
8+
"build:memory": "INCLUDE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
9+
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
10+
"test:persistence": " yarn build:persistence; karma start --single-run",
11+
"test:memory": "yarn build:memory; karma start --single-run",
12+
"test:debug:persistence": "yarn build:deps; yarn build:persistence; karma start --auto-watch --browsers Chrome",
13+
"test:debug:memory": "yarn build:deps; yarn build:memory; karma start --single-run"
1314
},
1415
"devDependencies": {
1516
"@types/mocha": "7.0.2",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
/**
19+
* This file serves as the public entrypoint for users that import
20+
* `firebase/firestore/memory`.
21+
*/
22+
23+
import '../../../firestore/dist/index.memory.esm';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "firebase/firestore/memory",
3+
"description": "A memory-only build of the Cloud Firestore JS SDK.",
4+
"main": "dist/index.cjs.js",
5+
"module": "dist/index.esm.js",
6+
"typings": "../../empty-import.d.ts",
7+
}

packages/firebase/firestore/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "firebase/firestore",
3+
"description": "The Cloud Firestore component of the Firebase JS SDK.",
34
"main": "dist/index.cjs.js",
45
"module": "dist/index.esm.js",
56
"typings": "../empty-import.d.ts"

packages/firebase/rollup.config.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ const componentBuilds = pkg.components
147147
})
148148
.reduce((a, b) => a.concat(b), []);
149149

150+
const firestoreMemoryBuilds = [
151+
{
152+
input: `firestore/memory/index.ts`,
153+
output: [
154+
{
155+
file: resolve('firestore/memory', pkg.main),
156+
format: 'cjs',
157+
sourcemap: true
158+
},
159+
{
160+
file: resolve('firestore/memory', pkg.module),
161+
format: 'es',
162+
sourcemap: true
163+
}
164+
],
165+
plugins,
166+
external
167+
},
168+
{
169+
input: `firestore/memory/index.ts`,
170+
output: createUmdOutputConfig(`firebase-firestore.memory.js`),
171+
plugins: [...plugins, uglify()],
172+
external: ['@firebase/app']
173+
}
174+
];
175+
150176
/**
151177
* Complete Package Builds
152178
*/
@@ -260,4 +286,9 @@ const completeBuilds = [
260286
}
261287
];
262288

263-
export default [...appBuilds, ...componentBuilds, ...completeBuilds];
289+
export default [
290+
...appBuilds,
291+
...componentBuilds,
292+
...firestoreMemoryBuilds,
293+
...completeBuilds
294+
];

packages/firestore/index.memory.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import firebase from '@firebase/app';
19+
import { FirebaseNamespace } from '@firebase/app-types';
20+
21+
import { Firestore } from './src/api/database';
22+
import { MemoryPersistenceProvider } from './src/local/memory_persistence';
23+
import { configureForFirebase } from './src/platform/config';
24+
25+
import './register-module';
26+
import './src/platform_browser/browser_init';
27+
28+
import { name, version } from './package.json';
29+
30+
/**
31+
* Registers the memory-only Firestore build with the components framework.
32+
*/
33+
export function registerFirestore(instance: FirebaseNamespace): void {
34+
configureForFirebase(
35+
instance,
36+
(app, auth) => new Firestore(app, auth, new MemoryPersistenceProvider())
37+
);
38+
instance.registerVersion(name, version);
39+
}
40+
41+
registerFirestore(firebase);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import firebase from '@firebase/app';
19+
import { FirebaseNamespace } from '@firebase/app-types';
20+
21+
import { Firestore } from './src/api/database';
22+
import { MemoryPersistenceProvider } from './src/local/memory_persistence';
23+
import { configureForFirebase } from './src/platform/config';
24+
import './register-module';
25+
import './src/platform_node/node_init';
26+
27+
import { name, version } from './package.json';
28+
29+
/**
30+
* Registers the memory-only Firestore build for Node with the components
31+
* framework.
32+
*/
33+
export function registerFirestore(instance: FirebaseNamespace): void {
34+
configureForFirebase(
35+
instance,
36+
(app, auth) => new Firestore(app, auth, new MemoryPersistenceProvider())
37+
);
38+
instance.registerVersion(name, version);
39+
}
40+
41+
registerFirestore(firebase);

packages/firestore/index.node.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@
1515
* limitations under the License.
1616
*/
1717
import firebase from '@firebase/app';
18+
import { FirebaseNamespace } from '@firebase/app-types';
19+
20+
import { Firestore } from './src/api/database';
21+
import { IndexedDbPersistenceProvider } from './src/local/indexeddb_persistence';
1822
import { configureForFirebase } from './src/platform/config';
23+
1924
import './register-module';
2025
import './src/platform_node/node_init';
21-
import { FirebaseNamespace } from '@firebase/app-types';
2226

2327
import { name, version } from './package.json';
2428

29+
/**
30+
* Registers the main Firestore Node build with the components framework.
31+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
32+
*/
2533
export function registerFirestore(instance: FirebaseNamespace): void {
26-
configureForFirebase(instance);
34+
configureForFirebase(
35+
instance,
36+
(app, auth) => new Firestore(app, auth, new IndexedDbPersistenceProvider())
37+
);
2738
instance.registerVersion(name, version, 'node');
2839
}
2940

packages/firestore/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@
1616
*/
1717

1818
import firebase from '@firebase/app';
19-
import { configureForFirebase } from './src/platform/config';
20-
import './register-module';
21-
import './src/platform_browser/browser_init';
22-
2319
import { FirebaseNamespace } from '@firebase/app-types';
2420

21+
import { Firestore } from './src/api/database';
22+
import { IndexedDbPersistenceProvider } from './src/local/indexeddb_persistence';
23+
import { configureForFirebase } from './src/platform/config';
2524
import { name, version } from './package.json';
2625

26+
import './register-module';
27+
import './src/platform_browser/browser_init';
28+
29+
/**
30+
* Registers the main Firestore build with the components framework.
31+
* Persistence can be enabled via `firebase.firestore().enablePersistence()`.
32+
*/
2733
export function registerFirestore(instance: FirebaseNamespace): void {
28-
configureForFirebase(instance);
34+
configureForFirebase(
35+
instance,
36+
(app, auth) => new Firestore(app, auth, new IndexedDbPersistenceProvider())
37+
);
2938
instance.registerVersion(name, version);
3039
}
3140

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@firebase/firestore/memory",
3+
"description": "A memory-only build of the Cloud Firestore JS SDK.",
4+
"main": "../dist/index.memory.node.cjs.js",
5+
"browser": "../dist/index.memory.cjs.js",
6+
"module": "../dist/index.memory.esm.js",
7+
"esm2017": "../dist/index.memory.esm2017.js",
8+
"typings": "../dist/index.d.ts"
9+
}

packages/firestore/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@firebase/firestore",
3-
"version": "1.12.1",
4-
"description": "",
3+
"version": "1.11.2",
4+
"description": "The Cloud Firestore component of the Firebase JS SDK.",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"scripts": {
77
"prebuild": "tsc -d --downlevelIteration --declarationDir dist/lib --emitDeclarationOnly && tsc -m es2015 --moduleResolution node scripts/*.ts ",
@@ -10,7 +10,7 @@
1010
"dev": "rollup -c -w",
1111
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1212
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
13-
"prettier": "prettier --write 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'",
13+
"prettier": "prettier --write '*.ts' '*.js' 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'",
1414
"test": "run-s lint test:all",
1515
"test:all": "run-p test:browser test:travis test:minified",
1616
"test:browser": "karma start --single-run",
@@ -20,7 +20,7 @@
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",
@@ -29,7 +29,8 @@
2929
"esm2017": "dist/index.esm2017.js",
3030
"license": "Apache-2.0",
3131
"files": [
32-
"dist"
32+
"dist",
33+
"memory/package.json"
3334
],
3435
"dependencies": {
3536
"@firebase/component": "0.1.7",

0 commit comments

Comments
 (0)