Skip to content

Commit d434118

Browse files
Add ReactNative and Browser builds (Lite/Exp) (#3400)
1 parent ee33ebf commit d434118

24 files changed

+140
-54
lines changed

packages/firestore/exp/index.d.ts renamed to packages/firestore/exp-types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export interface Settings {
3434
ssl?: boolean;
3535
ignoreUndefinedProperties?: boolean;
3636
cacheSizeBytes?: number;
37-
experimentalForceLongPolling?: boolean;
3837
}
3938

4039
export interface SnapshotListenOptions {
@@ -45,7 +44,9 @@ export interface SnapshotOptions {
4544
readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
4645
}
4746

48-
export interface SnapshotMetadata {
47+
export class SnapshotMetadata {
48+
private constructor();
49+
4950
readonly hasPendingWrites: boolean;
5051
readonly fromCache: boolean;
5152

packages/firestore/exp/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "@firebase/firestore/exp",
33
"description": "A tree-shakeable version of the Firestore SDK",
4-
"main": "../dist/exp/index.node.esm2017.js",
4+
"main": "../dist/exp/index.node.umd.js",
5+
"browser": "../dist/exp/index.browser.esm2017.js",
6+
"react-native": "../dist/exp/index.rn.esm2017.js",
57
"private": true
68
}

packages/firestore/exp/src/api/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../exp-types';
1919

2020
import { _getProvider, _removeServiceInstance } from '@firebase/app-exp';
2121
import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp';
@@ -101,7 +101,7 @@ export class Firestore extends LiteFirestore
101101
const databaseInfo = this._makeDatabaseInfo(
102102
settings.host,
103103
settings.ssl,
104-
settings.experimentalForceLongPolling
104+
/* experimentalForceLongPolling= */ false
105105
);
106106

107107
this._deferredInitialization = this._firestoreClient.start(

packages/firestore/exp/src/api/reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
1919
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20-
import * as firestore from '../../index';
20+
import * as firestore from '../../../exp-types';
2121

2222
import { Firestore } from './database';
2323
import {

packages/firestore/exp/src/api/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../exp-types';
1919

2020
import { DocumentKey } from '../../../src/model/document_key';
2121
import { Document } from '../../../src/model/document';

packages/firestore/exp/src/api/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../exp-types';
1919

2020
import { Transaction as LiteTransaction } from '../../../lite/src/api/transaction';
2121
import { DocumentSnapshot } from './snapshot';

packages/firestore/exp/src/api/write_batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
1919
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20-
import * as firestore from '../../index';
20+
import * as firestore from '../../../exp-types';
2121

2222
import { cast } from '../../../lite/src/api/util';
2323
import { WriteBatch } from '../../../lite/src/api/write_batch';

packages/firestore/exp/test/shim.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FirebaseApp as FirebaseAppLegacy } from '@firebase/app-types';
1919
import { FirebaseApp as FirebaseAppExp } from '@firebase/app-types-exp';
2020
import { deleteApp } from '@firebase/app-exp';
2121
import * as legacy from '@firebase/firestore-types';
22-
import * as exp from '../';
22+
import * as exp from '../../exp-types';
2323

2424
import {
2525
addDoc,
@@ -58,12 +58,12 @@ import {
5858
updateDoc,
5959
waitForPendingWrites,
6060
writeBatch
61-
} from '../../exp/index.node';
61+
} from '../../exp/index';
6262
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
6363
import { isPartialObserver, PartialObserver } from '../../src/api/observer';
6464
import { isPlainObject } from '../../src/util/input_validation';
6565

66-
export { GeoPoint, Blob, Timestamp } from '../index.node';
66+
export { GeoPoint, Blob, Timestamp } from '../index';
6767

6868
/* eslint-disable @typescript-eslint/no-explicit-any */
6969

packages/firestore/externs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"node_modules/typescript/lib/lib.es2017.string.d.ts",
1515
"packages/app-types/index.d.ts",
1616
"packages/app-types/private.d.ts",
17+
"packages-exp/app-types-exp/index.d.ts",
1718
"packages/auth-interop-types/index.d.ts",
19+
"packages/firestore/exp-types/index.d.ts",
20+
"packages/firestore/lite-types/index.d.ts",
1821
"packages/firestore-types/index.d.ts",
1922
"packages/firebase/index.d.ts",
2023
"packages/component/dist/src/component.d.ts",

packages/firestore/lite/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "@firebase/firestore/lite",
33
"description": "A lite version of the Firestore SDK",
4-
"main": "../dist/lite/index.node.esm2017.js",
4+
"main": "../dist/lite/index.node.umd.js",
5+
"browser": "../dist/lite/index.browser.esm2017.js",
6+
"react-native": "../dist/lite/index.rn.esm2017.js",
57
"private": true
68
}

packages/firestore/lite/src/api/database.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../';
18+
import * as firestore from '../../../lite-types';
1919

2020
import { _getProvider, _removeServiceInstance } from '@firebase/app-exp';
2121
import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp';
@@ -36,7 +36,6 @@ import {
3636
import { newConnection } from '../../../src/platform/connection';
3737
import { newSerializer } from '../../../src/platform/serializer';
3838
import { cast } from './util';
39-
import { Settings } from '../../';
4039

4140
// settings() defaults:
4241
export const DEFAULT_HOST = 'firestore.googleapis.com';
@@ -81,7 +80,7 @@ export class Firestore
8180
this._settings = settings;
8281
}
8382

84-
_getSettings(): Settings {
83+
_getSettings(): firestore.Settings {
8584
if (!this._settings) {
8685
this._settings = {};
8786
}

packages/firestore/lite/src/api/field_path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../lite-types';
1919

2020
import { BaseFieldPath } from '../../../src/api/field_path';
2121
import { cast } from './util';

packages/firestore/lite/src/api/field_value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../';
18+
import * as firestore from '../../../lite-types';
1919

2020
import { validateAtLeastNumberOfArgs } from '../../../src/util/input_validation';
2121
import {

packages/firestore/lite/src/api/reference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../lite-types';
1919

2020
import { Document } from '../../../src/model/document';
2121
import { DocumentKey } from '../../../src/model/document_key';

packages/firestore/lite/src/api/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../lite-types';
1919

2020
import { Firestore } from './database';
2121
import { DocumentReference, queryEqual } from './reference';

packages/firestore/lite/src/api/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../';
18+
import * as firestore from '../../../lite-types';
1919

2020
import {
2121
parseSetData,

packages/firestore/lite/src/api/write_batch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as firestore from '../../index';
18+
import * as firestore from '../../../lite-types';
19+
1920
import {
2021
DeleteMutation,
2122
Mutation,

packages/firestore/lite/test/shim.ts

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

1818
import * as legacy from '@firebase/firestore-types';
19-
import * as lite from '../';
19+
import * as lite from '../../lite-types';
2020

2121
import {
2222
addDoc,
@@ -43,11 +43,11 @@ import {
4343
updateDoc,
4444
writeBatch,
4545
initializeFirestore
46-
} from '../../lite/index.node';
46+
} from '../../lite/index';
4747
import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader';
4848
import { isPlainObject } from '../../src/util/input_validation';
4949

50-
export { GeoPoint, Blob, Timestamp } from '../index.node';
50+
export { GeoPoint, Blob, Timestamp } from '../index';
5151

5252
/* eslint-disable @typescript-eslint/no-explicit-any */
5353

packages/firestore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp/index.d.ts --bundle ./dist/exp/index.node.esm2017.js --output ./exp/test/deps/dependencies.json",
2525
"pregendeps:lite": "yarn build:lite",
2626
"gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite/index.d.ts --bundle ./dist/lite/index.node.esm2017.js --output ./lite/test/dependencies.json",
27-
"test:exp": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --file exp/index.node.ts --config ../../config/mocharc.node.js",
28-
"test:exp:persistence": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --require ts-node/register --require exp/index.node.ts --require test/util/node_persistence.ts --config ../../config/mocharc.node.js",
27+
"test:exp": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --file exp/index.ts --config ../../config/mocharc.node.js",
28+
"test:exp:persistence": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --require ts-node/register --require exp/index.ts --require test/util/node_persistence.ts --config ../../config/mocharc.node.js",
2929
"test": "run-s lint test:all",
3030
"test:ci": "node ../../scripts/run_tests_in_ci.js",
3131
"test:all": "run-p test:browser test:travis test:minified test:exp",
@@ -38,7 +38,7 @@
3838
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
3939
"test:minified": "(cd ../../integration/firestore ; yarn test)",
4040
"pretest:lite": "yarn build:lite",
41-
"test:lite": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'lite/test/**/*.test.ts' --file lite/index.node.ts --config ../../config/mocharc.node.js",
41+
"test:lite": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'lite/test/**/*.test.ts' --file lite/index.ts --config ../../config/mocharc.node.js",
4242
"prepare": "yarn build:release"
4343
},
4444
"main": "dist/index.node.cjs.js",

packages/firestore/rollup.config.exp.js

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,78 @@ import alias from '@rollup/plugin-alias';
2020
import typescriptPlugin from 'rollup-plugin-typescript2';
2121
import typescript from 'typescript';
2222
import path from 'path';
23+
import { terser } from 'rollup-plugin-terser';
2324

24-
import { generateAliasConfig, resolveNodeExterns } from './rollup.shared';
25+
import {
26+
firestoreTransformers,
27+
generateAliasConfig,
28+
manglePrivatePropertiesOptions,
29+
resolveBrowserExterns,
30+
resolveNodeExterns
31+
} from './rollup.shared';
2532

2633
import pkg from './exp/package.json';
2734

28-
const defaultPlugins = [
29-
alias(generateAliasConfig('node')),
35+
const nodePlugins = [
3036
typescriptPlugin({
3137
typescript,
3238
tsconfigOverride: {
3339
compilerOptions: {
34-
target: 'es2017'
40+
target: 'es5'
3541
}
3642
},
3743
clean: true
3844
}),
3945
json({ preferConst: true })
4046
];
4147

42-
const nodeBuilds = [
48+
const browserPlugins = [
49+
typescriptPlugin({
50+
typescript,
51+
tsconfigOverride: {
52+
compilerOptions: {
53+
target: 'es2017'
54+
}
55+
},
56+
clean: true,
57+
transformers: firestoreTransformers
58+
}),
59+
json({ preferConst: true }),
60+
terser(manglePrivatePropertiesOptions)
61+
];
62+
63+
const allBuilds = [
64+
// Node build
4365
{
44-
input: './exp/index.node.ts',
66+
input: './exp/index.ts',
4567
output: {
4668
file: path.resolve('./exp', pkg.main),
69+
format: 'umd',
70+
name: 'firebase.firestore'
71+
},
72+
plugins: [alias(generateAliasConfig('node')), ...nodePlugins],
73+
external: resolveNodeExterns
74+
},
75+
// Browser build
76+
{
77+
input: './exp/index.ts',
78+
output: {
79+
file: path.resolve('./exp', pkg.browser),
80+
format: 'es'
81+
},
82+
plugins: [alias(generateAliasConfig('browser')), ...browserPlugins],
83+
external: resolveBrowserExterns
84+
},
85+
// RN build
86+
{
87+
input: './exp/index.ts',
88+
output: {
89+
file: path.resolve('./exp', pkg['react-native']),
4790
format: 'es'
4891
},
49-
plugins: defaultPlugins,
50-
external: resolveNodeExterns,
51-
treeshake: {
52-
tryCatchDeoptimization: false
53-
}
92+
plugins: [alias(generateAliasConfig('rn')), ...browserPlugins],
93+
external: resolveBrowserExterns
5494
}
5595
];
5696

57-
export default [...nodeBuilds];
97+
export default allBuilds;

0 commit comments

Comments
 (0)