diff --git a/packages/firestore/.eslintrc.js b/packages/firestore/.eslintrc.js index f6bdcb1e36d..d570b10446d 100644 --- a/packages/firestore/.eslintrc.js +++ b/packages/firestore/.eslintrc.js @@ -53,6 +53,13 @@ module.exports = { '@typescript-eslint/no-explicit-any': 'error' } }, + { + files: ['scripts/*.ts'], + rules: { + 'import/no-extraneous-dependencies': 'off', + '@typescript-eslint/no-require-imports': 'off' + } + }, // TODO(firestorelite): Remove this exception when app-exp is published { files: ['lite/**/*.ts'], diff --git a/packages/firestore/.gitignore b/packages/firestore/.gitignore deleted file mode 100644 index c581e13b30a..00000000000 --- a/packages/firestore/.gitignore +++ /dev/null @@ -1 +0,0 @@ -scripts/*.js diff --git a/packages/firestore/exp/test/deps/dependencies.json b/packages/firestore/exp/dependencies.json similarity index 97% rename from packages/firestore/exp/test/deps/dependencies.json rename to packages/firestore/exp/dependencies.json index 2ea60cc44ce..5e92763988b 100644 --- a/packages/firestore/exp/test/deps/dependencies.json +++ b/packages/firestore/exp/dependencies.json @@ -333,7 +333,7 @@ ], "variables": [] }, - "sizeInBytes": 213002 + "sizeInBytes": 213157 }, "CollectionReference": { "dependencies": { @@ -705,7 +705,7 @@ ], "variables": [] }, - "sizeInBytes": 238931 + "sizeInBytes": 239194 }, "DocumentReference": { "dependencies": { @@ -1032,7 +1032,7 @@ ], "variables": [] }, - "sizeInBytes": 210014 + "sizeInBytes": 210221 }, "DocumentSnapshot": { "dependencies": { @@ -1386,7 +1386,7 @@ ], "variables": [] }, - "sizeInBytes": 222249 + "sizeInBytes": 222481 }, "FieldPath": { "dependencies": { @@ -1721,7 +1721,7 @@ ], "variables": [] }, - "sizeInBytes": 212226 + "sizeInBytes": 212381 }, "FieldValue": { "dependencies": { @@ -2048,7 +2048,7 @@ ], "variables": [] }, - "sizeInBytes": 209606 + "sizeInBytes": 209761 }, "FirebaseFirestore": { "dependencies": { @@ -2373,7 +2373,7 @@ ], "variables": [] }, - "sizeInBytes": 209515 + "sizeInBytes": 209670 }, "GeoPoint": { "dependencies": { @@ -2707,7 +2707,7 @@ ], "variables": [] }, - "sizeInBytes": 212367 + "sizeInBytes": 212522 }, "Query": { "dependencies": { @@ -3078,7 +3078,7 @@ ], "variables": [] }, - "sizeInBytes": 238535 + "sizeInBytes": 238775 }, "QueryDocumentSnapshot": { "dependencies": { @@ -3432,7 +3432,7 @@ ], "variables": [] }, - "sizeInBytes": 222259 + "sizeInBytes": 222491 }, "QuerySnapshot": { "dependencies": { @@ -3790,7 +3790,333 @@ ], "variables": [] }, - "sizeInBytes": 224891 + "sizeInBytes": 225123 + }, + "SnapshotMetadata": { + "dependencies": { + "functions": [ + "applyArrayRemoveTransformOperation", + "applyArrayUnionTransformOperation", + "applyDeleteMutationToLocalView", + "applyDeleteMutationToRemoteDocument", + "applyMutationToLocalView", + "applyMutationToRemoteDocument", + "applyNumericIncrementTransformOperationToLocalView", + "applyPatchMutationToLocalView", + "applyPatchMutationToRemoteDocument", + "applySetMutationToLocalView", + "applySetMutationToRemoteDocument", + "applyTransformMutationToLocalView", + "applyTransformMutationToRemoteDocument", + "applyTransformOperationToLocalView", + "applyTransformOperationToRemoteDocument", + "argToString", + "arrayEquals", + "arrayValueContains", + "asNumber", + "assertPresent", + "binaryStringFromUint8Array", + "blobEquals", + "boundEquals", + "canonicalId", + "canonifyArray", + "canonifyBound", + "canonifyByteString", + "canonifyFilter", + "canonifyGeoPoint", + "canonifyMap", + "canonifyOrderBy", + "canonifyQuery", + "canonifyReference", + "canonifyTarget", + "canonifyTimestamp", + "canonifyValue", + "cast", + "coercedFieldValuesArray", + "compareArrays", + "compareBlobs", + "compareChangeType", + "compareDocs", + "compareDocumentsByField", + "compareGeoPoints", + "compareMaps", + "compareNumbers", + "compareReferences", + "compareTimestamps", + "computeTransformOperationBaseValue", + "createMetadata", + "debugCast", + "decodeBase64", + "documentEntryMap", + "documentKeySet", + "documentMap", + "documentTargetMap", + "documentVersionMap", + "encodeBase64", + "extractFieldMask", + "extractLocalPathFromResourceName", + "extractMutationBaseValue", + "extractTransformMutationBaseValue", + "fail", + "fieldTransformEquals", + "filterEquals", + "forEach", + "formatJSON", + "fromBytes", + "fromFound", + "fromMaybeDocument", + "fromMissing", + "fromName", + "fromResourceName", + "fromRpcStatus", + "fromTimestamp", + "fromVersion", + "fromWatchChange", + "fromWatchTargetChangeState", + "fromWriteResult", + "fromWriteResults", + "fullyQualifiedPrefixPath", + "geoPointEquals", + "getEncodedDatabaseId", + "getLocalWriteTime", + "getLogLevel", + "getMessageOrStack", + "getPostMutationVersion", + "getWindow", + "hardAssert", + "ignoreIfPrimaryLeaseLoss", + "invokeBatchGetDocumentsRpc", + "invokeCommitRpc", + "isArray", + "isDocumentTarget", + "isDouble", + "isEmpty", + "isIndexedDbTransactionError", + "isInteger", + "isMapValue", + "isNanValue", + "isNegativeZero", + "isNullOrUndefined", + "isNullValue", + "isNumber", + "isPermanentError", + "isPermanentWriteError", + "isServerTimestamp", + "isValidResourceName", + "loadProtos", + "localTransformResults", + "logDebug", + "logError", + "logWarn", + "mapCodeFromRpcCode", + "maybeDocumentMap", + "mutationEquals", + "newConnection", + "newConnectivityMonitor", + "newDatastore", + "newLocalStore", + "newPersistentWatchStream", + "newPersistentWriteStream", + "newQueryComparator", + "newSerializer", + "newSyncEngine", + "newTarget", + "nodePromise", + "normalizeByteString", + "normalizeNumber", + "normalizeTimestamp", + "nullableMaybeDocumentMap", + "numberEquals", + "objectEquals", + "objectSize", + "orderByEquals", + "patchDocument", + "patchObject", + "preconditionIsValidForDocument", + "primitiveComparator", + "queryEquals", + "queryMatches", + "queryMatchesBounds", + "queryMatchesFilters", + "queryMatchesOrderBy", + "queryMatchesPathAndCollectionGroup", + "randomBytes", + "registerFirestore", + "requireDocument", + "serverTimestamp", + "serverTransformResults", + "snapshotChangesMap", + "sortsBeforeDocument", + "stringifyFilter", + "stringifyOrderBy", + "stringifyQuery", + "stringifyTarget", + "targetEquals", + "targetIdSet", + "terminate", + "terminate$1", + "terminateDatastore", + "timestampEquals", + "toBytes", + "toCursor", + "toDirection", + "toDocumentMask", + "toDocumentsTarget", + "toDouble", + "toFieldPathReference", + "toFieldTransform", + "toFilter", + "toInt32Proto", + "toInteger", + "toLabel", + "toListenRequestLabels", + "toMutation", + "toMutationDocument", + "toName", + "toOperatorName", + "toOrder", + "toPrecondition", + "toPropertyOrder", + "toQueryPath", + "toQueryTarget", + "toResourceName", + "toTarget", + "toTimestamp", + "toUnaryOrFieldFilter", + "toVersion", + "transformObject", + "transformOperationEquals", + "typeOrder", + "uint8ArrayFromBinaryString", + "valueCompare", + "valueEquals", + "versionFromListenResponse", + "wrapInUserErrorIfRecoverable" + ], + "classes": [ + "AddedLimboDocument", + "ArrayContainsAnyFilter", + "ArrayContainsFilter", + "ArrayRemoveTransformOperation", + "ArrayUnionTransformOperation", + "AsyncQueue", + "AutoId", + "BasePath", + "Bound", + "ByteString", + "DatabaseId", + "DatabaseInfo", + "Datastore", + "DatastoreImpl", + "Deferred", + "DelayedOperation", + "DeleteMutation", + "DocReference", + "Document", + "DocumentChangeSet", + "DocumentKey", + "DocumentSet", + "DocumentWatchChange", + "EventManager", + "ExistenceFilter", + "ExistenceFilterChange", + "ExponentialBackoff", + "FieldFilter", + "FieldMask", + "FieldPath", + "Filter", + "FirebaseCredentialsProvider", + "Firestore", + "Firestore$1", + "FirestoreClient", + "FirestoreError", + "GrpcConnection", + "InFilter", + "IndexFreeQueryEngine", + "JsonProtoSerializer", + "KeyFieldFilter", + "KeyFieldInFilter", + "LLRBEmptyNode", + "LLRBNode", + "LimboResolution", + "ListenSequence", + "LocalClientState", + "LocalDocumentsView", + "LocalStoreImpl", + "LocalViewChanges", + "LruParams", + "MaybeDocument", + "MemoryCollectionParentIndex", + "MemoryComponentProvider", + "MemoryEagerDelegate", + "MemoryIndexManager", + "MemoryMutationQueue", + "MemoryPersistence", + "MemoryRemoteDocumentCache", + "MemorySharedClientState", + "MemoryTargetCache", + "MemoryTransaction", + "Mutation", + "MutationBatch", + "MutationBatchResult", + "MutationResult", + "NoDocument", + "NoopConnectivityMonitor", + "NumericIncrementTransformOperation", + "OAuthToken", + "ObjectMap", + "ObjectValue", + "ObjectValueBuilder", + "OnlineStateTracker", + "OrderBy", + "PatchMutation", + "PersistencePromise", + "PersistenceTransaction", + "PersistentListenStream", + "PersistentStream", + "PersistentWriteStream", + "Precondition", + "Query", + "QueryListener", + "QueryListenersInfo", + "QueryView", + "ReferenceSet", + "RemoteDocumentChangeBuffer", + "RemoteEvent", + "RemoteStore", + "RemovedLimboDocument", + "ResourcePath", + "ServerTimestampTransform", + "SetMutation", + "SnapshotMetadata", + "SnapshotVersion", + "SortedMap", + "SortedMapIterator", + "SortedSet", + "SortedSetIterator", + "StreamBridge", + "SyncEngineImpl", + "TargetChange", + "TargetData", + "TargetIdGenerator", + "TargetImpl", + "TargetState", + "Timestamp", + "Transaction", + "TransactionRunner", + "TransformMutation", + "TransformOperation", + "UnknownDocument", + "User", + "VerifyMutation", + "View", + "ViewSnapshot", + "WatchChangeAggregator", + "WatchTargetChange" + ], + "variables": [] + }, + "sizeInBytes": 209885 }, "Timestamp": { "dependencies": { @@ -4115,7 +4441,7 @@ ], "variables": [] }, - "sizeInBytes": 209492 + "sizeInBytes": 209647 }, "Transaction": { "dependencies": { @@ -4496,7 +4822,7 @@ ], "variables": [] }, - "sizeInBytes": 236841 + "sizeInBytes": 237073 }, "WriteBatch": { "dependencies": { @@ -4868,7 +5194,7 @@ ], "variables": [] }, - "sizeInBytes": 231107 + "sizeInBytes": 231314 }, "addDoc": { "dependencies": { @@ -5247,7 +5573,7 @@ ], "variables": [] }, - "sizeInBytes": 242401 + "sizeInBytes": 242996 }, "arrayRemove": { "dependencies": { @@ -5605,7 +5931,7 @@ ], "variables": [] }, - "sizeInBytes": 222185 + "sizeInBytes": 222340 }, "arrayUnion": { "dependencies": { @@ -5963,7 +6289,7 @@ ], "variables": [] }, - "sizeInBytes": 222178 + "sizeInBytes": 222333 }, "clearIndexedDbPersistence": { "dependencies": { @@ -6298,7 +6624,7 @@ ], "variables": [] }, - "sizeInBytes": 219642 + "sizeInBytes": 219797 }, "collection": { "dependencies": { @@ -6672,7 +6998,7 @@ ], "variables": [] }, - "sizeInBytes": 239566 + "sizeInBytes": 240178 }, "collectionGroup": { "dependencies": { @@ -7044,7 +7370,7 @@ ], "variables": [] }, - "sizeInBytes": 238991 + "sizeInBytes": 239231 }, "deleteDoc": { "dependencies": { @@ -7372,7 +7698,7 @@ ], "variables": [] }, - "sizeInBytes": 210264 + "sizeInBytes": 210471 }, "deleteField": { "dependencies": { @@ -7702,7 +8028,7 @@ ], "variables": [] }, - "sizeInBytes": 210572 + "sizeInBytes": 210727 }, "disableNetwork": { "dependencies": { @@ -8028,7 +8354,7 @@ ], "variables": [] }, - "sizeInBytes": 209679 + "sizeInBytes": 209834 }, "doc": { "dependencies": { @@ -8402,7 +8728,7 @@ ], "variables": [] }, - "sizeInBytes": 239635 + "sizeInBytes": 240230 }, "documentId": { "dependencies": { @@ -8738,7 +9064,7 @@ ], "variables": [] }, - "sizeInBytes": 212276 + "sizeInBytes": 212431 }, "enableIndexedDbPersistence": { "dependencies": { @@ -9169,7 +9495,7 @@ ], "variables": [] }, - "sizeInBytes": 289566 + "sizeInBytes": 289722 }, "enableMultiTabIndexedDbPersistence": { "dependencies": { @@ -9308,11 +9634,14 @@ "fromWriteResults", "fullyQualifiedPrefixPath", "geoPointEquals", + "getCachedTarget", + "getCurrentlyActiveClients", "getDocument", "getEncodedDatabaseId", "getLocalWriteTime", "getLogLevel", "getMessageOrStack", + "getNewDocumentChanges", "getPostMutationVersion", "getWindow", "globalTargetStore", @@ -9346,6 +9675,7 @@ "logDebug", "logError", "logWarn", + "lookupMutationDocuments", "mapCodeFromRpcCode", "maybeDocumentMap", "mutationEquals", @@ -9357,7 +9687,6 @@ "newConnectivityMonitor", "newDatastore", "newLocalStore", - "newMultiTabLocalStore", "newMultiTabSyncEngine", "newPersistentWatchStream", "newPersistentWriteStream", @@ -9388,6 +9717,7 @@ "randomBytes", "registerFirestore", "remoteDocumentsStore", + "removeCachedMutationBatchMetadata", "removeMutationBatch", "requireDocument", "sentinelKey", @@ -9401,6 +9731,7 @@ "stringifyOrderBy", "stringifyQuery", "stringifyTarget", + "synchronizeLastDocumentChangeReadTime", "targetEquals", "targetIdSet", "targetsStore", @@ -9546,7 +9877,6 @@ "MemoryTargetCache", "MemoryTransaction", "MultiTabIndexedDbComponentProvider", - "MultiTabLocalStoreImpl", "MultiTabSyncEngineImpl", "Mutation", "MutationBatch", @@ -9617,7 +9947,7 @@ ], "variables": [] }, - "sizeInBytes": 312642 + "sizeInBytes": 312634 }, "enableNetwork": { "dependencies": { @@ -9943,7 +10273,7 @@ ], "variables": [] }, - "sizeInBytes": 209676 + "sizeInBytes": 209831 }, "getDoc": { "dependencies": { @@ -10303,7 +10633,7 @@ ], "variables": [] }, - "sizeInBytes": 224596 + "sizeInBytes": 224828 }, "getDocFromCache": { "dependencies": { @@ -10659,7 +10989,7 @@ ], "variables": [] }, - "sizeInBytes": 222871 + "sizeInBytes": 223103 }, "getDocFromServer": { "dependencies": { @@ -11019,7 +11349,7 @@ ], "variables": [] }, - "sizeInBytes": 224634 + "sizeInBytes": 224866 }, "getFirestore": { "dependencies": { @@ -11345,7 +11675,7 @@ ], "variables": [] }, - "sizeInBytes": 209591 + "sizeInBytes": 209746 }, "getQuery": { "dependencies": { @@ -11727,7 +12057,7 @@ ], "variables": [] }, - "sizeInBytes": 244559 + "sizeInBytes": 244809 }, "getQueryFromCache": { "dependencies": { @@ -12105,7 +12435,7 @@ ], "variables": [] }, - "sizeInBytes": 242888 + "sizeInBytes": 243138 }, "getQueryFromServer": { "dependencies": { @@ -12486,7 +12816,7 @@ ], "variables": [] }, - "sizeInBytes": 244297 + "sizeInBytes": 244547 }, "increment": { "dependencies": { @@ -12819,7 +13149,7 @@ ], "variables": [] }, - "sizeInBytes": 210824 + "sizeInBytes": 210979 }, "initializeFirestore": { "dependencies": { @@ -13145,7 +13475,7 @@ ], "variables": [] }, - "sizeInBytes": 210002 + "sizeInBytes": 210157 }, "onSnapshot": { "dependencies": { @@ -13530,7 +13860,7 @@ ], "variables": [] }, - "sizeInBytes": 246130 + "sizeInBytes": 246380 }, "onSnapshotsInSync": { "dependencies": { @@ -13860,7 +14190,7 @@ ], "variables": [] }, - "sizeInBytes": 210835 + "sizeInBytes": 210990 }, "parent": { "dependencies": { @@ -14233,7 +14563,7 @@ ], "variables": [] }, - "sizeInBytes": 239274 + "sizeInBytes": 239520 }, "queryEqual": { "dependencies": { @@ -14605,7 +14935,7 @@ ], "variables": [] }, - "sizeInBytes": 238743 + "sizeInBytes": 238983 }, "refEqual": { "dependencies": { @@ -14978,7 +15308,7 @@ ], "variables": [] }, - "sizeInBytes": 239216 + "sizeInBytes": 239479 }, "runTransaction": { "dependencies": { @@ -15360,7 +15690,7 @@ ], "variables": [] }, - "sizeInBytes": 237198 + "sizeInBytes": 237430 }, "serverTimestamp": { "dependencies": { @@ -15691,7 +16021,7 @@ ], "variables": [] }, - "sizeInBytes": 210467 + "sizeInBytes": 210622 }, "setDoc": { "dependencies": { @@ -16056,7 +16386,7 @@ ], "variables": [] }, - "sizeInBytes": 226158 + "sizeInBytes": 226365 }, "setLogLevel": { "dependencies": { @@ -16382,7 +16712,7 @@ ], "variables": [] }, - "sizeInBytes": 209557 + "sizeInBytes": 209712 }, "snapshotEqual": { "dependencies": { @@ -16761,7 +17091,7 @@ ], "variables": [] }, - "sizeInBytes": 243309 + "sizeInBytes": 243559 }, "terminate": { "dependencies": { @@ -17086,7 +17416,7 @@ ], "variables": [] }, - "sizeInBytes": 209507 + "sizeInBytes": 209662 }, "updateDoc": { "dependencies": { @@ -17454,7 +17784,7 @@ ], "variables": [] }, - "sizeInBytes": 227657 + "sizeInBytes": 227864 }, "waitForPendingWrites": { "dependencies": { @@ -17780,7 +18110,7 @@ ], "variables": [] }, - "sizeInBytes": 209697 + "sizeInBytes": 209852 }, "writeBatch": { "dependencies": { @@ -18153,6 +18483,6 @@ ], "variables": [] }, - "sizeInBytes": 231320 + "sizeInBytes": 231527 } } \ No newline at end of file diff --git a/packages/firestore/exp/test/deps/verify_dependencies.test.ts b/packages/firestore/exp/test/deps/verify_dependencies.test.ts deleted file mode 100644 index 4fdf6109dc2..00000000000 --- a/packages/firestore/exp/test/deps/verify_dependencies.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @license - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { expect } from 'chai'; -import { resolve } from 'path'; - -import { extractDependencies } from '../../../../../scripts/exp/extract-deps.helpers'; - -import * as dependencies from './dependencies.json'; -import * as pkg from '../../package.json'; -import { forEach } from '../../../src/util/obj'; - -// TODO(firestoreexp): Enable once the dependencies are stable -// eslint-disable-next-line no-restricted-properties -describe.skip('Dependencies', () => { - forEach(dependencies, (api, { dependencies }) => { - it(api, () => { - return extractDependencies(api, resolve('exp', pkg.main)).then( - extractedDependencies => { - expect(extractedDependencies.classes).to.have.members( - dependencies.classes, - 'for classes' - ); - expect(extractedDependencies.functions).to.have.members( - dependencies.functions, - 'for functions' - ); - expect(extractedDependencies.variables).to.have.members( - dependencies.variables, - 'for variables' - ); - } - ); - }); - }); -}); diff --git a/packages/firestore/lite/test/dependencies.json b/packages/firestore/lite/dependencies.json similarity index 98% rename from packages/firestore/lite/test/dependencies.json rename to packages/firestore/lite/dependencies.json index be79049c3a7..52c3e6f86cf 100644 --- a/packages/firestore/lite/test/dependencies.json +++ b/packages/firestore/lite/dependencies.json @@ -56,7 +56,7 @@ ], "variables": [] }, - "sizeInBytes": 20582 + "sizeInBytes": 20614 }, "CollectionReference": { "dependencies": { @@ -206,7 +206,7 @@ ], "variables": [] }, - "sizeInBytes": 69755 + "sizeInBytes": 69895 }, "DocumentReference": { "dependencies": { @@ -233,11 +233,13 @@ "terminateDatastore" ], "classes": [ + "BasePath", "DatabaseId", "DatabaseInfo", "Datastore", "DatastoreImpl", "Deferred", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FirebaseCredentialsProvider", @@ -246,12 +248,13 @@ "GrpcConnection", "JsonProtoSerializer", "OAuthToken", + "ResourcePath", "StreamBridge", "User" ], "variables": [] }, - "sizeInBytes": 16293 + "sizeInBytes": 19219 }, "DocumentSnapshot": { "dependencies": { @@ -339,7 +342,7 @@ ], "variables": [] }, - "sizeInBytes": 36707 + "sizeInBytes": 36806 }, "FieldPath": { "dependencies": { @@ -394,7 +397,7 @@ ], "variables": [] }, - "sizeInBytes": 21845 + "sizeInBytes": 21877 }, "FieldValue": { "dependencies": { @@ -439,7 +442,7 @@ ], "variables": [] }, - "sizeInBytes": 15885 + "sizeInBytes": 15917 }, "FirebaseFirestore": { "dependencies": { @@ -482,7 +485,7 @@ ], "variables": [] }, - "sizeInBytes": 15792 + "sizeInBytes": 15824 }, "GeoPoint": { "dependencies": { @@ -534,7 +537,7 @@ ], "variables": [] }, - "sizeInBytes": 18646 + "sizeInBytes": 18678 }, "Query": { "dependencies": { @@ -678,7 +681,7 @@ ], "variables": [] }, - "sizeInBytes": 64598 + "sizeInBytes": 64715 }, "QueryDocumentSnapshot": { "dependencies": { @@ -766,7 +769,7 @@ ], "variables": [] }, - "sizeInBytes": 36712 + "sizeInBytes": 36811 }, "QuerySnapshot": { "dependencies": { @@ -810,7 +813,7 @@ ], "variables": [] }, - "sizeInBytes": 16026 + "sizeInBytes": 16058 }, "Timestamp": { "dependencies": { @@ -854,7 +857,7 @@ ], "variables": [] }, - "sizeInBytes": 17328 + "sizeInBytes": 17360 }, "Transaction": { "dependencies": { @@ -995,7 +998,7 @@ ], "variables": [] }, - "sizeInBytes": 59416 + "sizeInBytes": 59515 }, "WriteBatch": { "dependencies": { @@ -1094,6 +1097,7 @@ "Deferred", "DeleteFieldValueImpl", "DeleteMutation", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FieldMask", @@ -1127,7 +1131,7 @@ ], "variables": [] }, - "sizeInBytes": 53607 + "sizeInBytes": 54277 }, "addDoc": { "dependencies": { @@ -1310,7 +1314,7 @@ ], "variables": [] }, - "sizeInBytes": 79064 + "sizeInBytes": 79536 }, "arrayRemove": { "dependencies": { @@ -1405,7 +1409,7 @@ ], "variables": [] }, - "sizeInBytes": 35152 + "sizeInBytes": 35184 }, "arrayUnion": { "dependencies": { @@ -1500,7 +1504,7 @@ ], "variables": [] }, - "sizeInBytes": 35144 + "sizeInBytes": 35176 }, "collection": { "dependencies": { @@ -1652,7 +1656,7 @@ ], "variables": [] }, - "sizeInBytes": 70390 + "sizeInBytes": 70879 }, "collectionGroup": { "dependencies": { @@ -1802,7 +1806,7 @@ ], "variables": [] }, - "sizeInBytes": 69815 + "sizeInBytes": 69932 }, "deleteDoc": { "dependencies": { @@ -1851,6 +1855,7 @@ "DatastoreImpl", "Deferred", "DeleteMutation", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FirebaseCredentialsProvider", @@ -1874,7 +1879,7 @@ ], "variables": [] }, - "sizeInBytes": 23962 + "sizeInBytes": 24632 }, "deleteField": { "dependencies": { @@ -1922,7 +1927,7 @@ ], "variables": [] }, - "sizeInBytes": 16851 + "sizeInBytes": 16883 }, "doc": { "dependencies": { @@ -2076,7 +2081,7 @@ ], "variables": [] }, - "sizeInBytes": 70960 + "sizeInBytes": 71432 }, "documentId": { "dependencies": { @@ -2132,7 +2137,7 @@ ], "variables": [] }, - "sizeInBytes": 21895 + "sizeInBytes": 21927 }, "getDoc": { "dependencies": { @@ -2250,7 +2255,7 @@ ], "variables": [] }, - "sizeInBytes": 44898 + "sizeInBytes": 44997 }, "getFirestore": { "dependencies": { @@ -2294,7 +2299,7 @@ ], "variables": [] }, - "sizeInBytes": 15871 + "sizeInBytes": 15903 }, "getQuery": { "dependencies": { @@ -2466,7 +2471,7 @@ ], "variables": [] }, - "sizeInBytes": 72058 + "sizeInBytes": 72175 }, "increment": { "dependencies": { @@ -2522,7 +2527,7 @@ ], "variables": [] }, - "sizeInBytes": 17716 + "sizeInBytes": 17748 }, "initializeFirestore": { "dependencies": { @@ -2566,7 +2571,7 @@ ], "variables": [] }, - "sizeInBytes": 15957 + "sizeInBytes": 15989 }, "parent": { "dependencies": { @@ -2717,7 +2722,7 @@ ], "variables": [] }, - "sizeInBytes": 70098 + "sizeInBytes": 70221 }, "queryEqual": { "dependencies": { @@ -2867,7 +2872,7 @@ ], "variables": [] }, - "sizeInBytes": 66184 + "sizeInBytes": 66301 }, "refEqual": { "dependencies": { @@ -3018,7 +3023,7 @@ ], "variables": [] }, - "sizeInBytes": 70040 + "sizeInBytes": 70180 }, "runTransaction": { "dependencies": { @@ -3197,7 +3202,7 @@ ], "variables": [] }, - "sizeInBytes": 76752 + "sizeInBytes": 76851 }, "serverTimestamp": { "dependencies": { @@ -3248,7 +3253,7 @@ ], "variables": [] }, - "sizeInBytes": 16839 + "sizeInBytes": 16871 }, "setDoc": { "dependencies": { @@ -3354,6 +3359,7 @@ "DatastoreImpl", "Deferred", "DeleteMutation", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FieldMask", @@ -3387,7 +3393,7 @@ ], "variables": [] }, - "sizeInBytes": 50416 + "sizeInBytes": 51086 }, "setLogLevel": { "dependencies": { @@ -3431,7 +3437,7 @@ ], "variables": [] }, - "sizeInBytes": 15836 + "sizeInBytes": 15868 }, "snapshotEqual": { "dependencies": { @@ -3583,7 +3589,7 @@ ], "variables": [] }, - "sizeInBytes": 66917 + "sizeInBytes": 67034 }, "terminate": { "dependencies": { @@ -3626,7 +3632,7 @@ ], "variables": [] }, - "sizeInBytes": 15771 + "sizeInBytes": 15803 }, "updateDoc": { "dependencies": { @@ -3734,6 +3740,7 @@ "Deferred", "DeleteFieldValueImpl", "DeleteMutation", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FieldMask", @@ -3769,7 +3776,7 @@ ], "variables": [] }, - "sizeInBytes": 53523 + "sizeInBytes": 54193 }, "writeBatch": { "dependencies": { @@ -3880,6 +3887,7 @@ "Deferred", "DeleteFieldValueImpl", "DeleteMutation", + "DocumentKey", "DocumentKeyReference", "DocumentReference", "FieldMask", @@ -3917,6 +3925,6 @@ ], "variables": [] }, - "sizeInBytes": 57224 + "sizeInBytes": 57894 } } \ No newline at end of file diff --git a/packages/firestore/lite/test/verify_dependencies.test.ts b/packages/firestore/lite/test/verify_dependencies.test.ts deleted file mode 100644 index 35b115012fe..00000000000 --- a/packages/firestore/lite/test/verify_dependencies.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @license - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { expect } from 'chai'; -import { resolve } from 'path'; - -import { extractDependencies } from '../../../../scripts/exp/extract-deps.helpers'; - -import * as dependencies from './dependencies.json'; -import * as pkg from '../package.json'; -import { forEach } from '../../src/util/obj'; - -describe('Dependencies', () => { - forEach(dependencies, (api, { dependencies }) => { - it(api, () => { - return extractDependencies(api, resolve('lite', pkg.main)).then( - extractedDependencies => { - expect(extractedDependencies.classes).to.have.members( - dependencies.classes, - 'for classes' - ); - expect(extractedDependencies.functions).to.have.members( - dependencies.functions, - 'for functions' - ); - expect(extractedDependencies.variables).to.have.members( - dependencies.variables, - 'for variables' - ); - } - ); - }); - }); -}); diff --git a/packages/firestore/package.json b/packages/firestore/package.json index 5d53c0d6f68..cee5e1ecae0 100644 --- a/packages/firestore/package.json +++ b/packages/firestore/package.json @@ -7,11 +7,8 @@ "description": "The Cloud Firestore component of the Firebase JS SDK.", "author": "Firebase (https://firebase.google.com/)", "scripts": { - "prebuild": "tsc -m es2015 --moduleResolution node scripts/*.ts ", - "prebuild:lite": "yarn prebuild", - "prebuild:exp": "yarn prebuild", - "prebuild:release": "yarn prebuild", "build": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js && yarn build:lite && yarn build:exp", + "build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts", "build:release": "rollup -c rollup.config.es2017.js && rollup -c rollup.config.es5.js", "build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build", "build:console": "node tools/console.build.js", @@ -22,10 +19,10 @@ "lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", "lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", "prettier": "prettier --write '*.ts' '*.js' 'lite/**/*.ts' 'exp/**/*.ts' 'src/**/*.js' 'test/**/*.js' 'src/**/*.ts' 'test/**/*.ts'", - "pregendeps:exp": "yarn build:exp", - "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", + "pregendeps:exp" : "node scripts/build-bundle.js --input ./exp/index.ts --output ./dist/exp/tmp.js", + "gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp-types/index.d.ts --bundle ./dist/exp/tmp.js --output ./exp/dependencies.json", + "pregendeps:lite" : "node scripts/build-bundle.js --input ./lite/index.ts --output ./dist/lite/tmp.js", + "gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite-types/index.d.ts --bundle ./dist/lite/tmp.js --output ./lite/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.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", diff --git a/packages/firestore/rollup.config.es2017.js b/packages/firestore/rollup.config.es2017.js index d26a32be9d7..3c72ce50d77 100644 --- a/packages/firestore/rollup.config.es2017.js +++ b/packages/firestore/rollup.config.es2017.js @@ -28,14 +28,7 @@ import { terser } from 'rollup-plugin-terser'; import pkg from './package.json'; import memoryPkg from './memory/package.json'; -import { - removeAssertTransformer, - removeAssertAndPrefixInternalTransformer, - manglePrivatePropertiesOptions, - resolveNodeExterns, - resolveBrowserExterns, - generateAliasConfig -} from './rollup.shared'; +const util = require('./rollup.shared'); // Firestore is released in a number of different build configurations: // - Browser builds that support persistence in ES5 CJS and ES5 ESM formats and @@ -64,7 +57,7 @@ import { // MARK: Browser builds const browserBuildPlugins = [ - alias(generateAliasConfig('browser')), + alias(util.generateAliasConfig('browser')), typescriptPlugin({ typescript, tsconfigOverride: { @@ -73,10 +66,10 @@ const browserBuildPlugins = [ } }, clean: true, - transformers: removeAssertAndPrefixInternalTransformer + transformers: util.removeAssertAndPrefixInternalTransformer }), json({ preferConst: true }), - terser(manglePrivatePropertiesOptions) + terser(util.manglePrivatePropertiesOptions) ]; const browserBuilds = [ @@ -89,7 +82,7 @@ const browserBuilds = [ sourcemap: true }, plugins: browserBuildPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns }, // Memory-only build { @@ -100,12 +93,12 @@ const browserBuilds = [ sourcemap: true }, plugins: browserBuildPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns } ]; const reactNativeBuildPlugins = [ - alias(generateAliasConfig('rn')), + alias(util.generateAliasConfig('rn')), ...browserBuildPlugins.slice(1) ]; @@ -119,7 +112,7 @@ const reactNativeBuilds = [ sourcemap: true }, plugins: reactNativeBuildPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns }, // Memory-only build { @@ -130,14 +123,14 @@ const reactNativeBuilds = [ sourcemap: true }, plugins: reactNativeBuildPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns } ]; // MARK: Node builds const nodeBuildPlugins = [ - alias(generateAliasConfig('node')), + alias(util.generateAliasConfig('node')), typescriptPlugin({ typescript, tsconfigOverride: { @@ -146,7 +139,7 @@ const nodeBuildPlugins = [ } }, clean: true, - transformers: removeAssertTransformer + transformers: util.removeAssertTransformer }), json(), // Needed as we also use the *.proto files @@ -164,7 +157,7 @@ const nodeBuilds = [ input: 'index.node.ts', output: [{ file: pkg['main-esm2017'], format: 'es', sourcemap: true }], plugins: nodeBuildPlugins, - external: resolveNodeExterns + external: util.resolveNodeExterns }, // Memory-only build { @@ -177,7 +170,7 @@ const nodeBuilds = [ } ], plugins: nodeBuildPlugins, - external: resolveNodeExterns + external: util.resolveNodeExterns } ]; diff --git a/packages/firestore/rollup.config.es5.js b/packages/firestore/rollup.config.es5.js index 701ab5d3029..926307fd7a3 100644 --- a/packages/firestore/rollup.config.es5.js +++ b/packages/firestore/rollup.config.es5.js @@ -21,11 +21,12 @@ import typescriptPlugin from 'rollup-plugin-typescript2'; import sourcemaps from 'rollup-plugin-sourcemaps'; import typescript from 'typescript'; import { terser } from 'rollup-plugin-terser'; -import { resolveNodeExterns, resolveBrowserExterns } from './rollup.shared'; import pkg from './package.json'; import memoryPkg from './memory/package.json'; +const util = require('./rollup.shared'); + // This file defines the second rollup pipeline and transpiles the ES2017 SDK // into ES5 code. By splitting the build process into two independent build // pipelines, we take advantage of tree shaking in ES2017 builds even for @@ -65,7 +66,7 @@ const browserBuilds = [ input: pkg.esm2017, output: { file: pkg.module, format: 'es', sourcemap: true }, plugins: browserPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns }, { input: path.resolve('./memory', memoryPkg.esm2017), @@ -75,13 +76,13 @@ const browserBuilds = [ sourcemap: true }, plugins: browserPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns }, { input: pkg.esm2017, output: { file: pkg.browser, format: 'cjs', sourcemap: true }, plugins: browserPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns }, { input: path.resolve('./memory', memoryPkg.esm2017), @@ -91,7 +92,7 @@ const browserBuilds = [ sourcemap: true }, plugins: browserPlugins, - external: resolveBrowserExterns + external: util.resolveBrowserExterns } ]; @@ -100,7 +101,7 @@ const nodeBuilds = [ input: pkg['main-esm2017'], output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], plugins: nodePlugins, - external: resolveNodeExterns + external: util.resolveNodeExterns }, { input: path.resolve('./memory', memoryPkg['main-esm2017']), @@ -112,7 +113,7 @@ const nodeBuilds = [ } ], plugins: nodePlugins, - external: resolveNodeExterns + external: util.resolveNodeExterns } ]; diff --git a/packages/firestore/rollup.config.exp.js b/packages/firestore/rollup.config.exp.js index aaf94a82a7a..967b5c282ad 100644 --- a/packages/firestore/rollup.config.exp.js +++ b/packages/firestore/rollup.config.exp.js @@ -22,17 +22,10 @@ import typescript from 'typescript'; import path from 'path'; import { terser } from 'rollup-plugin-terser'; -import { - resolveNodeExterns, - generateAliasConfig, - resolveBrowserExterns, - removeAssertTransformer, - removeAssertAndPrefixInternalTransformer, - manglePrivatePropertiesOptions -} from './rollup.shared'; - import pkg from './exp/package.json'; +const util = require('./rollup.shared'); + const nodePlugins = [ typescriptPlugin({ typescript, @@ -42,7 +35,7 @@ const nodePlugins = [ } }, clean: true, - transformers: removeAssertTransformer + transformers: util.removeAssertTransformer }), json() ]; @@ -56,10 +49,10 @@ const browserPlugins = [ } }, clean: true, - transformers: removeAssertAndPrefixInternalTransformer + transformers: util.removeAssertAndPrefixInternalTransformer }), json({ preferConst: true }), - terser(manglePrivatePropertiesOptions) + terser(util.manglePrivatePropertiesOptions) ]; const allBuilds = [ @@ -71,8 +64,8 @@ const allBuilds = [ format: 'umd', name: 'firebase.firestore' }, - plugins: [alias(generateAliasConfig('node')), ...nodePlugins], - external: resolveNodeExterns + plugins: [alias(util.generateAliasConfig('node')), ...nodePlugins], + external: util.resolveNodeExterns }, // Browser build { @@ -81,8 +74,8 @@ const allBuilds = [ file: path.resolve('./exp', pkg.browser), format: 'es' }, - plugins: [alias(generateAliasConfig('browser')), ...browserPlugins], - external: resolveBrowserExterns + plugins: [alias(util.generateAliasConfig('browser')), ...browserPlugins], + external: util.resolveBrowserExterns }, // RN build { @@ -91,8 +84,8 @@ const allBuilds = [ file: path.resolve('./exp', pkg['react-native']), format: 'es' }, - plugins: [alias(generateAliasConfig('rn')), ...browserPlugins], - external: resolveBrowserExterns + plugins: [alias(util.generateAliasConfig('rn')), ...browserPlugins], + external: util.resolveBrowserExterns } ]; diff --git a/packages/firestore/rollup.config.lite.js b/packages/firestore/rollup.config.lite.js index 52a2f12f037..58fac3433bb 100644 --- a/packages/firestore/rollup.config.lite.js +++ b/packages/firestore/rollup.config.lite.js @@ -15,23 +15,16 @@ * limitations under the License. */ +import path from 'path'; 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, - resolveBrowserExterns, - removeAssertTransformer, - removeAssertAndPrefixInternalTransformer, - manglePrivatePropertiesOptions -} from './rollup.shared'; - import pkg from './lite/package.json'; -import path from 'path'; + +const util = require('./rollup.shared'); const nodePlugins = [ typescriptPlugin({ @@ -42,7 +35,7 @@ const nodePlugins = [ } }, clean: true, - transformers: removeAssertTransformer + transformers: util.removeAssertTransformer }), json() ]; @@ -56,10 +49,10 @@ const browserPlugins = [ } }, clean: true, - transformers: removeAssertAndPrefixInternalTransformer + transformers: util.removeAssertAndPrefixInternalTransformer }), json({ preferConst: true }), - terser(manglePrivatePropertiesOptions) + terser(util.manglePrivatePropertiesOptions) ]; const allBuilds = [ @@ -71,8 +64,8 @@ const allBuilds = [ format: 'umd', name: 'firebase.firestore' }, - plugins: [alias(generateAliasConfig('node')), ...nodePlugins], - external: resolveNodeExterns + plugins: [alias(util.generateAliasConfig('node')), ...nodePlugins], + external: util.resolveNodeExterns }, // Browser build { @@ -81,8 +74,8 @@ const allBuilds = [ file: path.resolve('./lite', pkg.browser), format: 'es' }, - plugins: [alias(generateAliasConfig('browser')), ...browserPlugins], - external: resolveBrowserExterns + plugins: [alias(util.generateAliasConfig('browser')), ...browserPlugins], + external: util.resolveBrowserExterns }, // RN build { @@ -91,8 +84,8 @@ const allBuilds = [ file: path.resolve('./lite', pkg['react-native']), format: 'es' }, - plugins: [alias(generateAliasConfig('rn')), ...browserPlugins], - external: resolveBrowserExterns + plugins: [alias(util.generateAliasConfig('rn')), ...browserPlugins], + external: util.resolveBrowserExterns } ]; diff --git a/packages/firestore/rollup.shared.js b/packages/firestore/rollup.shared.js index 3870ed58604..347e927bc58 100644 --- a/packages/firestore/rollup.shared.js +++ b/packages/firestore/rollup.shared.js @@ -15,21 +15,21 @@ * limitations under the License. */ -import * as path from 'path'; +const path = require('path'); -import { externs } from './externs.json'; -import { renameInternals } from './scripts/rename-internals'; -import { extractPublicIdentifiers } from './scripts/extract-api'; -import { removeAsserts } from './scripts/remove-asserts'; +const { renameInternals } = require('./scripts/rename-internals'); +const { extractPublicIdentifiers } = require('./scripts/extract-api'); +const { removeAsserts } = require('./scripts/remove-asserts'); -import pkg from './package.json'; +const { externs } = require('./externs.json'); +const pkg = require('./package.json'); /** * Returns an replacement configuration for `@rollup/plugin-alias` that replaces * references to platform-specific files with implementations for the provided * target platform. */ -export function generateAliasConfig(platform) { +exports.generateAliasConfig = function (platform) { return { entries: [ { @@ -38,7 +38,7 @@ export function generateAliasConfig(platform) { } ] }; -} +}; const browserDeps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) @@ -47,14 +47,14 @@ const browserDeps = Object.keys( const nodeDeps = [...browserDeps, 'util', 'path']; /** Resolves the external dependencies for the browser build. */ -export function resolveBrowserExterns(id) { +exports.resolveBrowserExterns = function (id) { return browserDeps.some(dep => id === dep || id.startsWith(`${dep}/`)); -} +}; /** Resolves the external dependencies for the Node build. */ -export function resolveNodeExterns(id) { +exports.resolveNodeExterns = function (id) { return nodeDeps.some(dep => id === dep || id.startsWith(`${dep}/`)); -} +}; const externsPaths = externs.map(p => path.resolve(__dirname, '../../', p)); const publicIdentifiers = extractPublicIdentifiers(externsPaths); @@ -63,7 +63,7 @@ const publicIdentifiers = extractPublicIdentifiers(externsPaths); * Transformers that remove calls to `debugAssert` and messages for 'fail` and * `hardAssert`. */ -export const removeAssertTransformer = [ +exports.removeAssertTransformer = [ service => ({ before: [removeAsserts(service.getProgram())], after: [] @@ -74,7 +74,7 @@ export const removeAssertTransformer = [ * Transformers that remove calls to `debugAssert`, messages for 'fail` and * `hardAssert` and appends a __PRIVATE_ prefix to all internal symbols. */ -export const removeAssertAndPrefixInternalTransformer = [ +exports.removeAssertAndPrefixInternalTransformer = [ service => ({ before: [ removeAsserts(service.getProgram()), @@ -90,7 +90,7 @@ export const removeAssertAndPrefixInternalTransformer = [ /** * Terser options that mangle all properties prefixed with __PRIVATE_. */ -export const manglePrivatePropertiesOptions = { +exports.manglePrivatePropertiesOptions = { output: { comments: 'all', beautify: true diff --git a/packages/firestore/scripts/build-bundle.js b/packages/firestore/scripts/build-bundle.js new file mode 100644 index 00000000000..749f83534e7 --- /dev/null +++ b/packages/firestore/scripts/build-bundle.js @@ -0,0 +1,212 @@ +'use strict'; +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var __awaiter = + (this && this.__awaiter) || + function (thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P + ? value + : new P(function (resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator['throw'](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done + ? resolve(result.value) + : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; +var __generator = + (this && this.__generator) || + function (thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [] + }, + f, + y, + t, + g; + return ( + (g = { next: verb(0), 'throw': verb(1), 'return': verb(2) }), + typeof Symbol === 'function' && + (g[Symbol.iterator] = function () { + return this; + }), + g + ); + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + function step(op) { + if (f) throw new TypeError('Generator is already executing.'); + while (_) + try { + if ( + ((f = 1), + y && + (t = + op[0] & 2 + ? y['return'] + : op[0] + ? y['throw'] || ((t = y['return']) && t.call(y), 0) + : y.next) && + !(t = t.call(y, op[1])).done) + ) + return t; + if (((y = 0), t)) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: + case 1: + t = op; + break; + case 4: + _.label++; + return { value: op[1], done: false }; + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + case 7: + op = _.ops.pop(); + _.trys.pop(); + continue; + default: + if ( + !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && + (op[0] === 6 || op[0] === 2) + ) { + _ = 0; + continue; + } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { + _.label = op[1]; + break; + } + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + if (t && _.label < t[2]) { + _.label = t[2]; + _.ops.push(op); + break; + } + if (t[2]) _.ops.pop(); + _.trys.pop(); + continue; + } + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + if (op[0] & 5) throw op[1]; + return { value: op[0] ? op[1] : void 0, done: true }; + } + }; +exports.__esModule = true; +var yargs = require('yargs'); +var rollup_1 = require('rollup'); +var typescriptPlugin = require('rollup-plugin-typescript2'); +var alias = require('@rollup/plugin-alias'); +var json = require('rollup-plugin-json'); +var rollup_shared_1 = require('../rollup.shared'); +var argv = yargs.options({ + input: { + type: 'string', + demandOption: true, + desc: 'The location of the index.ts file' + }, + output: { + type: 'string', + demandOption: true, + desc: 'The location for the transpiled JavaScript bundle' + } +}).argv; +/** + * Builds an ESM bundle for the Typescript file at `index` and writes it the + * file located at `output`. + * + * This is used in the `gendeps` build and does not minify or mangle property + * names. + */ +function buildBundle(input, output) { + return __awaiter(this, void 0, void 0, function () { + var bundle; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + return [ + 4 /*yield*/, + rollup_1.rollup({ + input: input, + plugins: [ + alias(rollup_shared_1.generateAliasConfig('node')), + typescriptPlugin({ + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + transformers: rollup_shared_1.removeAssertTransformer + }), + json({ preferConst: true }) + ], + external: rollup_shared_1.resolveNodeExterns + }) + ]; + case 1: + bundle = _a.sent(); + return [4 /*yield*/, bundle.write({ file: output, format: 'es' })]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); +} +buildBundle(argv.input, argv.output); diff --git a/packages/firestore/scripts/build-bundle.ts b/packages/firestore/scripts/build-bundle.ts new file mode 100644 index 00000000000..cfc035ad6d7 --- /dev/null +++ b/packages/firestore/scripts/build-bundle.ts @@ -0,0 +1,72 @@ +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as yargs from 'yargs'; +import { rollup } from 'rollup'; + +const typescriptPlugin = require('rollup-plugin-typescript2'); +const alias = require('@rollup/plugin-alias'); +const json = require('rollup-plugin-json'); + +import { + removeAssertTransformer, + resolveNodeExterns, + generateAliasConfig +} from '../rollup.shared'; + +const argv = yargs.options({ + input: { + type: 'string', + demandOption: true, + desc: 'The location of the index.ts file' + }, + output: { + type: 'string', + demandOption: true, + desc: 'The location for the transpiled JavaScript bundle' + } +}).argv; + +/** + * Builds an ESM bundle for the Typescript file at `index` and writes it the + * file located at `output`. + * + * This is used in the `gendeps` build and does not minify or mangle property + * names. + */ +async function buildBundle(input: string, output: string): Promise { + const bundle = await rollup({ + input, + plugins: [ + alias(generateAliasConfig('node')), + typescriptPlugin({ + tsconfigOverride: { + compilerOptions: { + target: 'es2017' + } + }, + transformers: removeAssertTransformer + }), + json({ preferConst: true }) + ], + external: resolveNodeExterns + }); + await bundle.write({ file: output, format: 'es' }); +} + +// eslint-disable-next-line @typescript-eslint/no-floating-promises +buildBundle(argv.input, argv.output); diff --git a/packages/firestore/scripts/extract-api.js b/packages/firestore/scripts/extract-api.js new file mode 100644 index 00000000000..d7a76df13ff --- /dev/null +++ b/packages/firestore/scripts/extract-api.js @@ -0,0 +1,78 @@ +'use strict'; +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +exports.__esModule = true; +exports.extractPublicIdentifiers = void 0; +// eslint-disable-next-line import/no-extraneous-dependencies +var ts = require('typescript'); +var fs = require('fs'); +function extractIdentifiersFromNodeAndChildren(node, symbols) { + if (ts.isIdentifier(node)) { + symbols.add(node.escapedText.toString()); + } + ts.forEachChild(node, function (childNode) { + return extractIdentifiersFromNodeAndChildren(childNode, symbols); + }); +} +/** Generates the "d.ts" content for `fileName`. */ +function extractTypeDeclaration(fileName) { + var result; + var compilerOptions = { declaration: true, emitDeclarationOnly: true }; + var host = ts.createCompilerHost(compilerOptions); + host.writeFile = function (_, contents) { + return (result = contents); + }; + var program = ts.createProgram([fileName], compilerOptions, host); + program.emit(); + return result; +} +/** + * Traverses TypeScript type definition files and returns the list of referenced + * identifiers. + */ +function extractPublicIdentifiers(filePaths) { + var publicIdentifiers = new Set(); + var _loop_1 = function (filePath) { + var contents = fs.readFileSync(filePath, { encoding: 'UTF-8' }); + var sourceFile = ts.createSourceFile( + filePath, + contents, + ts.ScriptTarget.ES2015 + ); + if (!sourceFile.isDeclarationFile) { + var dtsSource = extractTypeDeclaration(filePath); + sourceFile = ts.createSourceFile( + filePath.replace('.ts', '.d.ts'), + dtsSource, + ts.ScriptTarget.ES2015 + ); + } + var identifiers = new Set(); + ts.forEachChild(sourceFile, function (childNode) { + return extractIdentifiersFromNodeAndChildren(childNode, identifiers); + }); + identifiers.forEach(function (api) { + publicIdentifiers.add(api); + }); + }; + for (var _i = 0, filePaths_1 = filePaths; _i < filePaths_1.length; _i++) { + var filePath = filePaths_1[_i]; + _loop_1(filePath); + } + return publicIdentifiers; +} +exports.extractPublicIdentifiers = extractPublicIdentifiers; diff --git a/packages/firestore/scripts/extract-api.ts b/packages/firestore/scripts/extract-api.ts index 49dee323669..d9524898f0c 100644 --- a/packages/firestore/scripts/extract-api.ts +++ b/packages/firestore/scripts/extract-api.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -// eslint-disable-next-line import/no-extraneous-dependencies import * as ts from 'typescript'; import * as fs from 'fs'; diff --git a/packages/firestore/scripts/remove-asserts.js b/packages/firestore/scripts/remove-asserts.js new file mode 100644 index 00000000000..3a89c1aad03 --- /dev/null +++ b/packages/firestore/scripts/remove-asserts.js @@ -0,0 +1,94 @@ +'use strict'; +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +exports.__esModule = true; +exports.removeAsserts = void 0; +// eslint-disable-next-line import/no-extraneous-dependencies +var ts = require('typescript'); +// Location of file that includes the asserts +var ASSERT_LOCATION = 'packages/firestore/src/util/assert.ts'; +function removeAsserts(program) { + var removeAsserts = new RemoveAsserts(program.getTypeChecker()); + return function (context) { + return function (file) { + return removeAsserts.visitNodeAndChildren(file, context); + }; + }; +} +exports.removeAsserts = removeAsserts; +/** + * Transformer that removes all "debugAssert" statements from the SDK and + * removes the custom message for fail() and hardAssert(). + */ +var RemoveAsserts = /** @class */ (function () { + function RemoveAsserts(typeChecker) { + this.typeChecker = typeChecker; + } + RemoveAsserts.prototype.visitNodeAndChildren = function (node, context) { + var _this = this; + return ts.visitEachChild( + this.visitNode(node), + function (childNode) { + return _this.visitNodeAndChildren(childNode, context); + }, + context + ); + }; + RemoveAsserts.prototype.visitNode = function (node) { + var updatedNode = null; + if (ts.isCallExpression(node)) { + var signature = this.typeChecker.getResolvedSignature(node); + if ( + signature && + signature.declaration && + signature.declaration.kind === ts.SyntaxKind.FunctionDeclaration + ) { + var declaration = signature.declaration; + if ( + declaration && + declaration.getSourceFile().fileName.indexOf(ASSERT_LOCATION) >= 0 + ) { + var method = declaration.name.text; + if (method === 'debugAssert') { + updatedNode = ts.createEmptyStatement(); + } else if (method === 'hardAssert') { + // Remove the log message but keep the assertion + updatedNode = ts.createCall( + declaration.name, + /*typeArgs*/ undefined, + [node.arguments[0]] + ); + } else if (method === 'fail') { + // Remove the log message + updatedNode = ts.createCall( + declaration.name, + /*typeArgs*/ undefined, + [] + ); + } + } + } + } + if (updatedNode) { + ts.setSourceMapRange(updatedNode, ts.getSourceMapRange(node)); + return updatedNode; + } else { + return node; + } + }; + return RemoveAsserts; +})(); diff --git a/packages/firestore/scripts/remove-asserts.ts b/packages/firestore/scripts/remove-asserts.ts index 22e3b17a099..7fcb9d1b877 100644 --- a/packages/firestore/scripts/remove-asserts.ts +++ b/packages/firestore/scripts/remove-asserts.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -// eslint-disable-next-line import/no-extraneous-dependencies import * as ts from 'typescript'; // Location of file that includes the asserts diff --git a/packages/firestore/scripts/rename-internals.js b/packages/firestore/scripts/rename-internals.js new file mode 100644 index 00000000000..744facb5afa --- /dev/null +++ b/packages/firestore/scripts/rename-internals.js @@ -0,0 +1,75 @@ +'use strict'; +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +exports.__esModule = true; +exports.renameInternals = void 0; +// eslint-disable-next-line import/no-extraneous-dependencies +var ts = require('typescript'); +// `undefined` is treated as an identifier by TSC, but not part of any externs. +var blacklist = ['undefined']; +/** + * Processes TypeScript source files and renames all identifiers that do not + * reference the public API. + */ +var RenameInternals = /** @class */ (function () { + function RenameInternals(publicApi, prefix) { + this.publicApi = publicApi; + this.prefix = prefix; + } + RenameInternals.prototype.visitNodeAndChildren = function (node, context) { + var _this = this; + return ts.visitEachChild( + this.visitNode(node), + function (childNode) { + return _this.visitNodeAndChildren(childNode, context); + }, + context + ); + }; + RenameInternals.prototype.visitNode = function (node) { + if (ts.isIdentifier(node)) { + var name_1 = node.escapedText.toString(); + if ( + !this.publicApi.has(name_1) && + blacklist.indexOf(node.escapedText.toString()) === -1 + ) { + var newIdentifier = ts.createIdentifier(this.prefix + name_1); + ts.setSourceMapRange(newIdentifier, ts.getSourceMapRange(node)); + return newIdentifier; + } + } + return node; + }; + return RenameInternals; +})(); +var DEFAULT_PREFIX = '_'; +/** + * A TypeScript transformer that minifies existing source files. All identifiers + * are minified unless listed in `config.publicIdentifiers`. + */ +function renameInternals(program, config) { + var _a; + var prefix = + (_a = config.prefix) !== null && _a !== void 0 ? _a : DEFAULT_PREFIX; + var renamer = new RenameInternals(config.publicIdentifiers, prefix); + return function (context) { + return function (file) { + return renamer.visitNodeAndChildren(file, context); + }; + }; +} +exports.renameInternals = renameInternals; diff --git a/packages/firestore/scripts/rename-internals.ts b/packages/firestore/scripts/rename-internals.ts index 2441fadb81a..47ba546af0d 100644 --- a/packages/firestore/scripts/rename-internals.ts +++ b/packages/firestore/scripts/rename-internals.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -// eslint-disable-next-line import/no-extraneous-dependencies import * as ts from 'typescript'; // `undefined` is treated as an identifier by TSC, but not part of any externs.