-
Notifications
You must be signed in to change notification settings - Fork 946
Memory-only Firestore build #2608
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
Changes from 10 commits
860b649
a4a8856
2080ba8
0ed63b3
af52293
7121065
34c6f64
cce2ddd
9b4ef91
5d61740
9544744
e4a596c
df0b87c
09276a7
2ac9dfc
ce47ef8
37e1f0f
2a8e78a
de25f91
07ff26e
6a6ec47
53a4d12
df6a633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @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 '../../firestore/dist/index.memory.esm'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @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 firebase from '@firebase/app'; | ||
import { FirebaseNamespace } from '@firebase/app-types'; | ||
|
||
import { configureForFirebase } from './src/platform/config'; | ||
import './register-module'; | ||
import './src/platform_browser/browser_init'; | ||
|
||
import { name, version } from './package.json'; | ||
import { Firestore, PublicMemoryFirestore } from './src/api/database'; | ||
|
||
export function registerFirestore(instance: FirebaseNamespace): void { | ||
configureForFirebase(instance, PublicMemoryFirestore, Firestore); | ||
instance.registerVersion(name, version); | ||
} | ||
|
||
registerFirestore(firebase); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @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 firebase from '@firebase/app'; | ||
import { FirebaseNamespace } from '@firebase/app-types'; | ||
|
||
import { configureForFirebase } from './src/platform/config'; | ||
import './register-module'; | ||
import './src/platform_node/node_init'; | ||
|
||
import { name, version } from './package.json'; | ||
import { Firestore, PublicMemoryFirestore } from './src/api/database'; | ||
|
||
export function registerFirestore(instance: FirebaseNamespace): void { | ||
configureForFirebase(instance, PublicMemoryFirestore, Firestore); | ||
instance.registerVersion(name, version); | ||
} | ||
|
||
registerFirestore(firebase); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,32 +62,81 @@ const terserOptions = { | |
} | ||
}; | ||
|
||
/** | ||
* ES5 Builds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This configuration is now quite complex. For someone who isn't well versed in all this it's essentially inscrutable. This comment doesn't really help anyone who doesn't already know exactly what they're doing already. What's an ES5 build? Where's it used (in the browser? node?)? Is this shipped to end users or an input into some later stage in the build? This might be cumbersome to document inline so another way to approach this might be to put together an overview somewhere--either in comments in this file or in a doc--that described what all these pieces are and how they fit together. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expanded on these comments a bit, but I think it is a bit too much to ask to explain these concepts in comments to someone that is new to the JavaScript build process. So even with the new comments, there will be room for lots of questions. I spent a lot of time digging through the Rollup documentation, and I don't think it will be possible for someone to ramp up on this without doing the same. @Feiyang1 Do you think we could provide a high-level document that describes some of the paradigms that we use in our SDKs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I can add a page in go/jscore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
const es5BuildPlugins = [ | ||
typescriptPlugin({ | ||
typescript, | ||
transformers, | ||
cacheRoot: './.cache/es5.min/' | ||
}), | ||
json(), | ||
terser(terserOptions) | ||
]; | ||
|
||
const nodeBuildPlugins = [ | ||
...es5BuildPlugins, | ||
// Needed as we also use the *.proto files | ||
copy({ | ||
assets: ['./src/protos'] | ||
}), | ||
replace({ | ||
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') | ||
}) | ||
]; | ||
|
||
/** | ||
* Returns the externs locations for the Memory-based Firestore implementation. | ||
* Verifies that no persistence sources are used by Firestore's memory-only | ||
* implementation. | ||
*/ | ||
function resolveMemoryExterns(id, referencedBy) { | ||
const externalRef = path | ||
.resolve(path.dirname(referencedBy), id) | ||
.replace('.ts', ''); | ||
|
||
const persistenceRef = [ | ||
'local/indexeddb_persistence.ts', | ||
'local/indexeddb_index_manager.ts', | ||
'local/indexeddb_mutation_queue.ts', | ||
'local/indexeddb_remote_document_cache.ts', | ||
'local/indexeddb_schema.ts', | ||
'local/indexeddb_target_cache.ts', | ||
'local/local_serializer.ts', | ||
'local/simple_db.ts', | ||
'api/persistence.ts' | ||
].map(p => path.resolve(__dirname, 'src', p)); | ||
|
||
if (persistenceRef.indexOf(externalRef) !== -1) { | ||
throw new Error('Unexpected reference in Memory-only client on ' + id); | ||
} | ||
return [...deps, 'util', 'path'].some( | ||
dep => id === dep || id.startsWith(`${dep}/`) | ||
); | ||
} | ||
|
||
const es5Builds = [ | ||
/** | ||
* Node.js Build | ||
*/ | ||
{ | ||
input: 'index.node.ts', | ||
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }], | ||
plugins: [ | ||
typescriptPlugin({ | ||
typescript, | ||
cacheRoot: './.cache/node.cjs/' | ||
}), | ||
json(), | ||
// Needed as we also use the *.proto files | ||
copy({ | ||
assets: ['./src/protos'] | ||
}), | ||
replace({ | ||
'process.env.FIRESTORE_PROTO_ROOT': JSON.stringify('src/protos') | ||
}) | ||
], | ||
plugins: nodeBuildPlugins, | ||
external: id => | ||
[...deps, 'util', 'path'].some( | ||
dep => id === dep || id.startsWith(`${dep}/`) | ||
) | ||
}, | ||
{ | ||
input: 'index.node.memory.ts', | ||
output: [ | ||
{ file: pkg.mainMemoryPersistence, format: 'cjs', sourcemap: true } | ||
], | ||
plugins: nodeBuildPlugins, | ||
external: resolveMemoryExterns | ||
}, | ||
/** | ||
* Browser ESM Build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment to above: what's an ESM build? Why do we need this? How does it relate to the other things in here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two import styles in JavaScript. ESM uses |
||
*/ | ||
|
@@ -105,17 +154,40 @@ const es5Builds = [ | |
], | ||
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) | ||
}, | ||
{ | ||
input: 'index.memory.ts', | ||
output: { file: pkg.moduleMemoryPersistence, format: 'es', sourcemap: true }, | ||
plugins: [ | ||
typescriptPlugin({ | ||
typescript, | ||
transformers, | ||
cacheRoot: './.cache/esm/' | ||
}), | ||
json(), | ||
terser(terserOptions) | ||
], | ||
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
}, | ||
/** | ||
* Browser CJS Build | ||
* | ||
* This build is based on the mangling in the ESM build above, since | ||
* Browser CJS Build | ||
* | ||
* These builds are based on the mangling in the ESM build above, since | ||
* Terser's Property name mangling doesn't work well with CJS's syntax. | ||
*/ | ||
{ | ||
input: pkg.module, | ||
output: { file: pkg.browser, format: 'cjs', sourcemap: true }, | ||
plugins: [ sourcemaps() ] | ||
plugins: [sourcemaps()] | ||
}, | ||
{ | ||
input: pkg.moduleMemoryPersistence, | ||
output: { | ||
file: pkg.browserMemoryPersistence, | ||
format: 'cjs', | ||
sourcemap: true | ||
}, | ||
plugins: [sourcemaps()] | ||
} | ||
]; | ||
|
||
/** | ||
|
@@ -149,6 +221,16 @@ const es2017Builds = [ | |
}, | ||
plugins: es2017BuildPlugins, | ||
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) | ||
}, | ||
{ | ||
input: 'index.memory.ts', | ||
output: { | ||
file: pkg.esm2017MemoryPersistence, | ||
format: 'es', | ||
sourcemap: true | ||
}, | ||
plugins: es2017BuildPlugins, | ||
external: resolveMemoryExterns | ||
} | ||
]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (here and elsewhere)