Skip to content

Replace Platform injection with source preprocessor #3206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion config/webpack.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,12 @@
const path = require('path');
const webpack = require('webpack');

/**
* A regular expression used to replace Firestore's platform specific modules,
* which are located under 'packages/firestore/src/platform/'.
*/
const FIRESTORE_PLATFORM_RE = /^(.*)\/platform\/([^.\/]*)(\.ts)?$/;

module.exports = {
mode: 'development',
devtool: 'source-map',
Expand Down Expand Up @@ -77,6 +83,15 @@ module.exports = {
extensions: ['.js', '.ts']
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
FIRESTORE_PLATFORM_RE,
resource => {
resource.request = resource.request.replace(
FIRESTORE_PLATFORM_RE,
'$1/platform/browser/$2.ts'
);
}
),
new webpack.EnvironmentPlugin([
'RTDB_EMULATOR_PORT',
'RTDB_EMULATOR_NAMESPACE'
Expand Down
5 changes: 3 additions & 2 deletions packages/firestore/index.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
* limitations under the License.
*/

import './src/platform_browser/browser_init';
// TODO(mrschmidt): Once imported into Google3, fix
// third_party/javascript/firebase/src/packages/firestore/tools/console.build.js

export { Firestore, FirestoreDatabase } from './src/api/database';
export {
Expand All @@ -25,7 +26,7 @@ export {
PublicQuerySnapshot as QuerySnapshot,
PublicFieldValue as FieldValue,
PublicBlob as Blob
} from './src/platform/config';
} from './src/config';
export { GeoPoint } from './src/api/geo_point';
export { FirstPartyCredentialsSettings } from './src/api/credentials';
export { FieldPath } from './src/api/field_path';
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/index.memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { MemoryComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';

import './register-module';
import './src/platform_browser/browser_init';

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

Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/index.node.memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { MemoryComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';
import './register-module';
import './src/platform_node/node_init';

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

Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { IndexedDbComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';

import './register-module';
import './src/platform_node/node_init';

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

Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/index.rn.memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { MemoryComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';

import './register-module';
import './src/platform_rn/rn_init';

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

Expand Down
4 changes: 1 addition & 3 deletions packages/firestore/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { IndexedDbComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';

import './register-module';
import './src/platform_rn/rn_init';

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

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import { FirebaseNamespace } from '@firebase/app-types';

import { Firestore } from './src/api/database';
import { IndexedDbComponentProvider } from './src/core/component_provider';
import { configureForFirebase } from './src/platform/config';
import { configureForFirebase } from './src/config';
import { name, version } from './package.json';

import './register-module';
import './src/platform_browser/browser_init';

/**
* Registers the main Firestore build with the components framework.
Expand Down
2 changes: 0 additions & 2 deletions packages/firestore/lite/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { Firestore } from './src/api/database';
import { version } from '../package.json';
import { Component, ComponentType } from '@firebase/component';

import '../src/platform_node/node_init';

export {
Firestore as FirebaseFirestore,
initializeFirestore,
Expand Down
15 changes: 6 additions & 9 deletions packages/firestore/lite/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
newDatastore,
terminateDatastore
} from '../../../src/remote/datastore';
import { PlatformSupport } from '../../../src/platform/platform';
import { newConnection } from '../../../src/platform/connection';
import { newSerializer } from '../../../src/platform/serializer';
import { cast } from './util';
import { Settings } from '../../';

Expand Down Expand Up @@ -90,14 +91,10 @@ export class Firestore implements firestore.FirebaseFirestore {
_getDatastore(): Promise<Datastore> {
if (!this._datastorePromise) {
const databaseInfo = this._makeDatabaseInfo(this._getSettings());
this._datastorePromise = PlatformSupport.getPlatform()
.loadConnection(databaseInfo)
.then(connection => {
const serializer = PlatformSupport.getPlatform().newSerializer(
databaseInfo.databaseId
);
return newDatastore(connection, this._credentials, serializer);
});
this._datastorePromise = newConnection(databaseInfo).then(connection => {
const serializer = newSerializer(databaseInfo.databaseId);
return newDatastore(connection, this._credentials, serializer);
});
}

return this._datastorePromise;
Expand Down
6 changes: 2 additions & 4 deletions packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
} from '../../../src/remote/datastore';
import { hardAssert } from '../../../src/util/assert';
import { DeleteMutation, Precondition } from '../../../src/model/mutation';
import { PlatformSupport } from '../../../src/platform/platform';
import {
applyFirestoreDataConverter,
BaseQuery
Expand All @@ -60,6 +59,7 @@ import {
validateExactNumberOfArgs,
validatePositiveNumber
} from '../../../src/util/input_validation';
import { newSerializer } from '../../../src/platform/serializer';
import { FieldPath as ExternalFieldPath } from '../../../src/api/field_path';
import { Code, FirestoreError } from '../../../src/util/error';

Expand Down Expand Up @@ -592,9 +592,7 @@ export function queryEqual<T>(

export function newUserDataReader(firestore: Firestore): UserDataReader {
const settings = firestore._getSettings();
const serializer = PlatformSupport.getPlatform().newSerializer(
firestore._databaseId
);
const serializer = newSerializer(firestore._databaseId);
return new UserDataReader(
firestore._databaseId,
!!settings.ignoreUndefinedProperties,
Expand Down
Loading