diff --git a/packages/firestore/exp/index.d.ts b/packages/firestore/exp-types/index.d.ts similarity index 99% rename from packages/firestore/exp/index.d.ts rename to packages/firestore/exp-types/index.d.ts index 7206aa13e75..4e2183049f2 100644 --- a/packages/firestore/exp/index.d.ts +++ b/packages/firestore/exp-types/index.d.ts @@ -34,7 +34,6 @@ export interface Settings { ssl?: boolean; ignoreUndefinedProperties?: boolean; cacheSizeBytes?: number; - experimentalForceLongPolling?: boolean; } export interface SnapshotListenOptions { @@ -45,7 +44,9 @@ export interface SnapshotOptions { readonly serverTimestamps?: 'estimate' | 'previous' | 'none'; } -export interface SnapshotMetadata { +export class SnapshotMetadata { + private constructor(); + readonly hasPendingWrites: boolean; readonly fromCache: boolean; diff --git a/packages/firestore/exp/index.node.ts b/packages/firestore/exp/index.ts similarity index 100% rename from packages/firestore/exp/index.node.ts rename to packages/firestore/exp/index.ts diff --git a/packages/firestore/exp/package.json b/packages/firestore/exp/package.json index 6346798c28e..a6b980457bb 100644 --- a/packages/firestore/exp/package.json +++ b/packages/firestore/exp/package.json @@ -1,6 +1,8 @@ { "name": "@firebase/firestore/exp", "description": "A tree-shakeable version of the Firestore SDK", - "main": "../dist/exp/index.node.esm2017.js", + "main": "../dist/exp/index.node.umd.js", + "browser": "../dist/exp/index.browser.esm2017.js", + "react-native": "../dist/exp/index.rn.esm2017.js", "private": true } diff --git a/packages/firestore/exp/src/api/database.ts b/packages/firestore/exp/src/api/database.ts index 31fd39e293d..80784b674c8 100644 --- a/packages/firestore/exp/src/api/database.ts +++ b/packages/firestore/exp/src/api/database.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../exp-types'; import { _getProvider, _removeServiceInstance } from '@firebase/app-exp'; import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp'; @@ -101,7 +101,7 @@ export class Firestore extends LiteFirestore const databaseInfo = this._makeDatabaseInfo( settings.host, settings.ssl, - settings.experimentalForceLongPolling + /* experimentalForceLongPolling= */ false ); this._deferredInitialization = this._firestoreClient.start( diff --git a/packages/firestore/exp/src/api/reference.ts b/packages/firestore/exp/src/api/reference.ts index 19d15256cea..bcffc90b25d 100644 --- a/packages/firestore/exp/src/api/reference.ts +++ b/packages/firestore/exp/src/api/reference.ts @@ -17,7 +17,7 @@ // See https://github.com/typescript-eslint/typescript-eslint/issues/363 // eslint-disable-next-line @typescript-eslint/no-unused-vars -import * as firestore from '../../index'; +import * as firestore from '../../../exp-types'; import { Firestore } from './database'; import { diff --git a/packages/firestore/exp/src/api/snapshot.ts b/packages/firestore/exp/src/api/snapshot.ts index cf2de38431b..d6e73ffe9b2 100644 --- a/packages/firestore/exp/src/api/snapshot.ts +++ b/packages/firestore/exp/src/api/snapshot.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../exp-types'; import { DocumentKey } from '../../../src/model/document_key'; import { Document } from '../../../src/model/document'; diff --git a/packages/firestore/exp/src/api/transaction.ts b/packages/firestore/exp/src/api/transaction.ts index cc9726f0aab..ec113c78ffe 100644 --- a/packages/firestore/exp/src/api/transaction.ts +++ b/packages/firestore/exp/src/api/transaction.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../exp-types'; import { Transaction as LiteTransaction } from '../../../lite/src/api/transaction'; import { DocumentSnapshot } from './snapshot'; diff --git a/packages/firestore/exp/src/api/write_batch.ts b/packages/firestore/exp/src/api/write_batch.ts index 559355be2ab..4a9dfd16757 100644 --- a/packages/firestore/exp/src/api/write_batch.ts +++ b/packages/firestore/exp/src/api/write_batch.ts @@ -17,7 +17,7 @@ // See https://github.com/typescript-eslint/typescript-eslint/issues/363 // eslint-disable-next-line @typescript-eslint/no-unused-vars -import * as firestore from '../../index'; +import * as firestore from '../../../exp-types'; import { cast } from '../../../lite/src/api/util'; import { WriteBatch } from '../../../lite/src/api/write_batch'; diff --git a/packages/firestore/exp/test/shim.ts b/packages/firestore/exp/test/shim.ts index db5d1e48282..ef5cc34df02 100644 --- a/packages/firestore/exp/test/shim.ts +++ b/packages/firestore/exp/test/shim.ts @@ -19,7 +19,7 @@ import { FirebaseApp as FirebaseAppLegacy } from '@firebase/app-types'; import { FirebaseApp as FirebaseAppExp } from '@firebase/app-types-exp'; import { deleteApp } from '@firebase/app-exp'; import * as legacy from '@firebase/firestore-types'; -import * as exp from '../'; +import * as exp from '../../exp-types'; import { addDoc, @@ -58,12 +58,12 @@ import { updateDoc, waitForPendingWrites, writeBatch -} from '../../exp/index.node'; +} from '../../exp/index'; import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader'; import { isPartialObserver, PartialObserver } from '../../src/api/observer'; import { isPlainObject } from '../../src/util/input_validation'; -export { GeoPoint, Blob, Timestamp } from '../index.node'; +export { GeoPoint, Blob, Timestamp } from '../index'; /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/packages/firestore/externs.json b/packages/firestore/externs.json index 07007db0f57..22e4a68ee87 100644 --- a/packages/firestore/externs.json +++ b/packages/firestore/externs.json @@ -14,7 +14,10 @@ "node_modules/typescript/lib/lib.es2017.string.d.ts", "packages/app-types/index.d.ts", "packages/app-types/private.d.ts", + "packages-exp/app-types-exp/index.d.ts", "packages/auth-interop-types/index.d.ts", + "packages/firestore/exp-types/index.d.ts", + "packages/firestore/lite-types/index.d.ts", "packages/firestore-types/index.d.ts", "packages/firebase/index.d.ts", "packages/component/dist/src/component.d.ts", diff --git a/packages/firestore/lite/index.d.ts b/packages/firestore/lite-types/index.d.ts similarity index 100% rename from packages/firestore/lite/index.d.ts rename to packages/firestore/lite-types/index.d.ts diff --git a/packages/firestore/lite/index.node.ts b/packages/firestore/lite/index.ts similarity index 100% rename from packages/firestore/lite/index.node.ts rename to packages/firestore/lite/index.ts diff --git a/packages/firestore/lite/package.json b/packages/firestore/lite/package.json index 61582455309..ed534ea7b63 100644 --- a/packages/firestore/lite/package.json +++ b/packages/firestore/lite/package.json @@ -1,6 +1,8 @@ { "name": "@firebase/firestore/lite", "description": "A lite version of the Firestore SDK", - "main": "../dist/lite/index.node.esm2017.js", + "main": "../dist/lite/index.node.umd.js", + "browser": "../dist/lite/index.browser.esm2017.js", + "react-native": "../dist/lite/index.rn.esm2017.js", "private": true } diff --git a/packages/firestore/lite/src/api/database.ts b/packages/firestore/lite/src/api/database.ts index 0e792b22b89..8329ab8e4a0 100644 --- a/packages/firestore/lite/src/api/database.ts +++ b/packages/firestore/lite/src/api/database.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../'; +import * as firestore from '../../../lite-types'; import { _getProvider, _removeServiceInstance } from '@firebase/app-exp'; import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp'; @@ -36,7 +36,6 @@ import { import { newConnection } from '../../../src/platform/connection'; import { newSerializer } from '../../../src/platform/serializer'; import { cast } from './util'; -import { Settings } from '../../'; // settings() defaults: export const DEFAULT_HOST = 'firestore.googleapis.com'; @@ -81,7 +80,7 @@ export class Firestore this._settings = settings; } - _getSettings(): Settings { + _getSettings(): firestore.Settings { if (!this._settings) { this._settings = {}; } diff --git a/packages/firestore/lite/src/api/field_path.ts b/packages/firestore/lite/src/api/field_path.ts index 65b0164a227..60a4619b17c 100644 --- a/packages/firestore/lite/src/api/field_path.ts +++ b/packages/firestore/lite/src/api/field_path.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../lite-types'; import { BaseFieldPath } from '../../../src/api/field_path'; import { cast } from './util'; diff --git a/packages/firestore/lite/src/api/field_value.ts b/packages/firestore/lite/src/api/field_value.ts index a4cdda53b1b..05b35b6ef8c 100644 --- a/packages/firestore/lite/src/api/field_value.ts +++ b/packages/firestore/lite/src/api/field_value.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../'; +import * as firestore from '../../../lite-types'; import { validateAtLeastNumberOfArgs } from '../../../src/util/input_validation'; import { diff --git a/packages/firestore/lite/src/api/reference.ts b/packages/firestore/lite/src/api/reference.ts index 942cd7689be..50b6091f7df 100644 --- a/packages/firestore/lite/src/api/reference.ts +++ b/packages/firestore/lite/src/api/reference.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../lite-types'; import { Document } from '../../../src/model/document'; import { DocumentKey } from '../../../src/model/document_key'; diff --git a/packages/firestore/lite/src/api/snapshot.ts b/packages/firestore/lite/src/api/snapshot.ts index 15cb2c4d2d2..9221894c989 100644 --- a/packages/firestore/lite/src/api/snapshot.ts +++ b/packages/firestore/lite/src/api/snapshot.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../lite-types'; import { Firestore } from './database'; import { DocumentReference, queryEqual } from './reference'; diff --git a/packages/firestore/lite/src/api/transaction.ts b/packages/firestore/lite/src/api/transaction.ts index 86ee5b1b3ba..a1811c5256e 100644 --- a/packages/firestore/lite/src/api/transaction.ts +++ b/packages/firestore/lite/src/api/transaction.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as firestore from '../../'; +import * as firestore from '../../../lite-types'; import { parseSetData, diff --git a/packages/firestore/lite/src/api/write_batch.ts b/packages/firestore/lite/src/api/write_batch.ts index 58b44d40ddf..835212282c3 100644 --- a/packages/firestore/lite/src/api/write_batch.ts +++ b/packages/firestore/lite/src/api/write_batch.ts @@ -15,7 +15,8 @@ * limitations under the License. */ -import * as firestore from '../../index'; +import * as firestore from '../../../lite-types'; + import { DeleteMutation, Mutation, diff --git a/packages/firestore/lite/test/shim.ts b/packages/firestore/lite/test/shim.ts index 96dbe2c8509..f694d5bc3cc 100644 --- a/packages/firestore/lite/test/shim.ts +++ b/packages/firestore/lite/test/shim.ts @@ -16,7 +16,7 @@ */ import * as legacy from '@firebase/firestore-types'; -import * as lite from '../'; +import * as lite from '../../lite-types'; import { addDoc, @@ -43,11 +43,11 @@ import { updateDoc, writeBatch, initializeFirestore -} from '../../lite/index.node'; +} from '../../lite/index'; import { UntypedFirestoreDataConverter } from '../../src/api/user_data_reader'; import { isPlainObject } from '../../src/util/input_validation'; -export { GeoPoint, Blob, Timestamp } from '../index.node'; +export { GeoPoint, Blob, Timestamp } from '../index'; /* eslint-disable @typescript-eslint/no-explicit-any */ diff --git a/packages/firestore/package.json b/packages/firestore/package.json index cd63b58c311..2f66d85ff91 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -24,8 +24,8 @@ "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", "pregendeps:lite": "yarn build:lite", "gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite/index.d.ts --bundle ./dist/lite/index.node.esm2017.js --output ./lite/test/dependencies.json", - "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", - "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", + "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", + "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", "test": "run-s lint test:all", "test:ci": "node ../../scripts/run_tests_in_ci.js", "test:all": "run-p test:browser test:travis test:minified test:exp", @@ -38,7 +38,7 @@ "test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts", "test:minified": "(cd ../../integration/firestore ; yarn test)", "pretest:lite": "yarn build:lite", - "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", + "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", "prepare": "yarn build:release" }, "main": "dist/index.node.cjs.js", diff --git a/packages/firestore/rollup.config.exp.js b/packages/firestore/rollup.config.exp.js index 4038620726c..b209c254614 100644 --- a/packages/firestore/rollup.config.exp.js +++ b/packages/firestore/rollup.config.exp.js @@ -20,18 +20,24 @@ import alias from '@rollup/plugin-alias'; import typescriptPlugin from 'rollup-plugin-typescript2'; import typescript from 'typescript'; import path from 'path'; +import { terser } from 'rollup-plugin-terser'; -import { generateAliasConfig, resolveNodeExterns } from './rollup.shared'; +import { + firestoreTransformers, + generateAliasConfig, + manglePrivatePropertiesOptions, + resolveBrowserExterns, + resolveNodeExterns +} from './rollup.shared'; import pkg from './exp/package.json'; -const defaultPlugins = [ - alias(generateAliasConfig('node')), +const nodePlugins = [ typescriptPlugin({ typescript, tsconfigOverride: { compilerOptions: { - target: 'es2017' + target: 'es5' } }, clean: true @@ -39,19 +45,53 @@ const defaultPlugins = [ json({ preferConst: true }) ]; -const nodeBuilds = [ +const browserPlugins = [ + typescriptPlugin({ + typescript, + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + clean: true, + transformers: firestoreTransformers + }), + json({ preferConst: true }), + terser(manglePrivatePropertiesOptions) +]; + +const allBuilds = [ + // Node build { - input: './exp/index.node.ts', + input: './exp/index.ts', output: { file: path.resolve('./exp', pkg.main), + format: 'umd', + name: 'firebase.firestore' + }, + plugins: [alias(generateAliasConfig('node')), ...nodePlugins], + external: resolveNodeExterns + }, + // Browser build + { + input: './exp/index.ts', + output: { + file: path.resolve('./exp', pkg.browser), + format: 'es' + }, + plugins: [alias(generateAliasConfig('browser')), ...browserPlugins], + external: resolveBrowserExterns + }, + // RN build + { + input: './exp/index.ts', + output: { + file: path.resolve('./exp', pkg['react-native']), format: 'es' }, - plugins: defaultPlugins, - external: resolveNodeExterns, - treeshake: { - tryCatchDeoptimization: false - } + plugins: [alias(generateAliasConfig('rn')), ...browserPlugins], + external: resolveBrowserExterns } ]; -export default [...nodeBuilds]; +export default allBuilds; diff --git a/packages/firestore/rollup.config.lite.js b/packages/firestore/rollup.config.lite.js index 571d7961c15..8515537a48e 100644 --- a/packages/firestore/rollup.config.lite.js +++ b/packages/firestore/rollup.config.lite.js @@ -19,19 +19,25 @@ import json from 'rollup-plugin-json'; import alias from '@rollup/plugin-alias'; import typescriptPlugin from 'rollup-plugin-typescript2'; import typescript from 'typescript'; +import { terser } from 'rollup-plugin-terser'; -import { resolveNodeExterns, generateAliasConfig } from './rollup.shared'; +import { + resolveNodeExterns, + generateAliasConfig, + resolveBrowserExterns, + firestoreTransformers, + manglePrivatePropertiesOptions +} from './rollup.shared'; import pkg from './lite/package.json'; import path from 'path'; -const defaultPlugins = [ - alias(generateAliasConfig('node')), +const nodePlugins = [ typescriptPlugin({ typescript, tsconfigOverride: { compilerOptions: { - target: 'es2017' + target: 'es5' } }, clean: true @@ -39,21 +45,53 @@ const defaultPlugins = [ json({ preferConst: true }) ]; -const nodeBuilds = [ +const browserPlugins = [ + typescriptPlugin({ + typescript, + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + clean: true, + transformers: firestoreTransformers + }), + json({ preferConst: true }), + terser(manglePrivatePropertiesOptions) +]; + +const allBuilds = [ + // Node build { - input: 'lite/index.node.ts', + input: './lite/index.ts', output: { file: path.resolve('./lite', pkg.main), + format: 'umd', + name: 'firebase.firestore' + }, + plugins: [alias(generateAliasConfig('node')), ...nodePlugins], + external: resolveNodeExterns + }, + // Browser build + { + input: './lite/index.ts', + output: { + file: path.resolve('./lite', pkg.browser), format: 'es' }, - plugins: defaultPlugins, - external: resolveNodeExterns, - treeshake: { - tryCatchDeoptimization: false - } + plugins: [alias(generateAliasConfig('browser')), ...browserPlugins], + external: resolveBrowserExterns + }, + // RN build + { + input: './lite/index.ts', + output: { + file: path.resolve('./lite', pkg['react-native']), + format: 'es' + }, + plugins: [alias(generateAliasConfig('rn')), ...browserPlugins], + external: resolveBrowserExterns } ]; -// TODO(firestorelite): Add browser builds - -export default [...nodeBuilds]; +export default allBuilds;