Skip to content

Commit a8919cd

Browse files
authored
refactor(database): Implement database in Typescript (#72)
* refactor(database): remove old database implementation [Part 1/3] (#61) * refactor(database): remove old database implementation This is part #1 of 4 PR's to migrate database * refactor(database): remove database build processes * refactor(database): Add typescript database implementation [Part 2/3] (#62) * refactor(database): add typescript implementation * refactor(database): update build process to include database.ts All integration tests pass at this point * refactor(*): refactor environment builds to be based on separate .ts files * WIP: patch database code in nodeJS * refactor(database): classes for typescript database implementation (#55) * refactor(database): classes for typescript database implementation * refactor(database): requested changes & other improvements * fix(database): Add missing "typeof" (#74) https://github.com/firebase/firebase-js-sdk/blob/fd0728138d88c454f8e38a78f35d831d6365070c/src/database/js-client/core/Repo.js#L86 * WIP: fixes from @schmidt-sebastian's review * WIP: fix: TS Build error * fix(database): fix issue with missing repo method * WIP: review adjustments #1 * WIP: review comments #2 * WIP: refactor(database): Add migrated test harness [Part 3/3] (#71) * refactor(database): add typescript implementation * refactor(database): update build process to include database.ts All integration tests pass at this point * refactor(*): refactor environment builds to be based on separate .ts files * WIP: patch database code in nodeJS * refactor(database): classes for typescript database implementation (#55) * refactor(database): classes for typescript database implementation * refactor(database): requested changes & other improvements * WIP: add the /tests/config dir to the .gitignore * WIP: add test harness * WIP: add query tests There are some tests that have weird timing issues, and because of the polling nature of the original implementation, we never caught the issue. These should be resolved when able * WIP: add database.test.ts * WIP: add node.test.ts * WIP: add sortedmap.test.ts * WIP: add datasnapshot.test.ts * WIP: add sparsesnapshottree.test.ts * refactor(database): refactor query.test.ts to better preserve original test meaning * WIP: add crawler_support.test.ts * WIP: refactor EventAccumulator.ts for data.test.ts * WIP: fix issue with query.test.ts * WIP: add connection.test.ts * WIP: add info.test.ts * WIP: add order_by.test.ts I only migrated some of these tests as there was a dependency on the server for several tests * WIP: fix several code signature problems, add test files * WIP: add transaction.test.ts * WIP: working on the broken npm test command * WIP: working on fixes * WIP: remove logging * WIP: fix node tests * fix(*): fixing test files and CI integration * WIP: tEMP: Allow branch builds * WIP: escape string * refactor(CI): use ChromeHeadless launcher * WIP: fixes from review. * WIP: skip flakey test * WIP: remove unneeded debugger statement * WIP: fixing nits * Prevent using uninitialized array in EventEmitter (#85) * perf(*): fixing build size output issues * chore(*): remove unneeded build deps
1 parent 6aaef70 commit a8919cd

File tree

2,652 files changed

+25830
-662814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,652 files changed

+25830
-662814
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
npm-debug.log
55
/coverage
66
/.nyc_output
7-
/tests/integration/config
7+
/tests/config
88
/temp
99
/.vscode
10+
/.ts-node
1011
/.idea

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ addons:
1616
- g++-4.8
1717
before_script:
1818
- "export DISPLAY=:99.0"
19+
- "mkdir -p tests/config && echo \"$PROJECT_CONFIG\" > tests/config/project.json"
1920
script:
2021
- xvfb-run npm test
21-
branches:
22-
only:
23-
- master

gulp/config.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ const path = require('path');
1717
const cwd = process.cwd();
1818
const karma = require('karma');
1919

20-
module.exports = {
20+
const configObj = {
2121
root: path.resolve(cwd),
2222
pkg: require(path.resolve(cwd, 'package.json')),
23+
testConfig: {
24+
timeout: 5000,
25+
retries: 5
26+
},
2327
tsconfig: require(path.resolve(cwd, 'tsconfig.json')),
2428
tsconfigTest: require(path.resolve(cwd, 'tsconfig.test.json')),
2529
paths: {
@@ -30,6 +34,7 @@ module.exports = {
3034
'tests/**/*.test.ts',
3135
'!tests/**/browser/**/*.test.ts',
3236
'!tests/**/binary/**/*.test.ts',
37+
'!src/firebase-*.ts',
3338
],
3439
binary: [
3540
'tests/**/binary/**/*.test.ts',
@@ -44,11 +49,10 @@ module.exports = {
4449
},
4550
babel: {
4651
plugins: [
47-
require('babel-plugin-add-module-exports'),
48-
require('babel-plugin-minify-dead-code-elimination')
52+
'add-module-exports',
4953
],
5054
presets: [
51-
[require('babel-preset-env'), {
55+
['env', {
5256
"targets": {
5357
"browsers": [
5458
"ie >= 9"
@@ -103,7 +107,7 @@ module.exports = {
103107

104108
// start these browsers
105109
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
106-
browsers: ['Chrome', 'Firefox'],
110+
browsers: ['ChromeHeadless', 'Firefox'],
107111

108112
// Continuous Integration mode
109113
// if true, Karma captures browsers, runs the tests and exits
@@ -116,6 +120,16 @@ module.exports = {
116120
// karma-typescript config
117121
karmaTypescriptConfig: {
118122
tsconfig: `./tsconfig.test.json`
123+
},
124+
125+
// Stub for client config
126+
client: {
127+
mocha: {}
119128
}
120129
}
121-
};
130+
};
131+
132+
configObj.karma.client.mocha.timeout = configObj.testConfig.timeout;
133+
configObj.karma.client.mocha.retries = configObj.testConfig.retries;
134+
135+
module.exports = configObj;

gulp/tasks/build.js

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const glob = require('glob');
4242
const fs = require('fs');
4343
const gzipSize = require('gzip-size');
4444
const WrapperPlugin = require('wrapper-webpack-plugin');
45-
const legacyBuild = require('./build.legacy');
4645

4746
function cleanDist(dir) {
4847
return function cleanDistDirectory(done) {
@@ -135,11 +134,12 @@ function compileIndvES2015ModulesToBrowser() {
135134
'firebase-app': './src/app.ts',
136135
'firebase-storage': './src/storage.ts',
137136
'firebase-messaging': './src/messaging.ts',
137+
'firebase-database': './src/database.ts',
138138
},
139139
output: {
140-
path: path.resolve(__dirname, './dist/browser'),
141140
filename: '[name].js',
142-
jsonpFunction: 'webpackJsonpFirebase'
141+
jsonpFunction: 'webpackJsonpFirebase',
142+
path: path.resolve(__dirname, './dist/browser'),
143143
},
144144
module: {
145145
rules: [{
@@ -158,6 +158,7 @@ function compileIndvES2015ModulesToBrowser() {
158158
}]
159159
},
160160
plugins: [
161+
new webpack.optimize.ModuleConcatenationPlugin(),
161162
new webpack.optimize.CommonsChunkPlugin({
162163
name: 'firebase-app'
163164
}),
@@ -193,27 +194,6 @@ function compileIndvES2015ModulesToBrowser() {
193194
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
194195
}
195196

196-
function compileSDKES2015ToBrowser() {
197-
return gulp.src('./dist/es2015/firebase.js')
198-
.pipe(webpackStream({
199-
plugins: [
200-
new webpack.DefinePlugin({
201-
TARGET_ENVIRONMENT: JSON.stringify('browser')
202-
})
203-
]
204-
}, webpack))
205-
.pipe(sourcemaps.init({ loadMaps: true }))
206-
.pipe(through.obj(function(file, enc, cb) {
207-
// Dont pipe through any source map files as it will be handled
208-
// by gulp-sourcemaps
209-
var isSourceMap = /\.map$/.test(file.path);
210-
if (!isSourceMap) this.push(file);
211-
cb();
212-
}))
213-
.pipe(sourcemaps.write('.'))
214-
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
215-
}
216-
217197
function buildBrowserFirebaseJs() {
218198
return gulp.src('./dist/browser/*.js')
219199
.pipe(sourcemaps.init({ loadMaps: true }))
@@ -223,32 +203,18 @@ function buildBrowserFirebaseJs() {
223203
}
224204

225205
function buildAltEnvFirebaseJs() {
226-
const envs = [
227-
'browser',
228-
'node',
229-
'react-native'
230-
];
231-
232-
const streams = envs.map(env => {
233-
const babelConfig = Object.assign({}, config.babel, {
234-
plugins: [
235-
['inline-replace-variables', {
236-
'TARGET_ENVIRONMENT': env
237-
}],
238-
...config.babel.plugins
239-
]
240-
});
241-
return gulp.src('./dist/es2015/firebase.js')
242-
.pipe(sourcemaps.init({ loadMaps: true }))
243-
.pipe(babel(babelConfig))
244-
.pipe(rename({
245-
suffix: `-${env}`
246-
}))
247-
.pipe(sourcemaps.write('.'))
248-
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
206+
const babelConfig = Object.assign({}, config.babel, {
207+
plugins: config.babel.plugins
249208
});
250-
251-
return merge(streams);
209+
return gulp.src([
210+
'./dist/es2015/firebase-browser.js',
211+
'./dist/es2015/firebase-node.js',
212+
'./dist/es2015/firebase-react-native.js',
213+
])
214+
.pipe(sourcemaps.init({ loadMaps: true }))
215+
.pipe(babel(babelConfig))
216+
.pipe(sourcemaps.write('.'))
217+
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
252218
}
253219

254220
function copyPackageContents() {
@@ -429,7 +395,6 @@ gulp.task('build:cjs', gulp.parallel([
429395
gulp.parallel(compileES2015ToCJS, buildAltEnvFirebaseJs)
430396
]),
431397
processPrebuiltFilesForCJS,
432-
legacyBuild.compileDatabaseForCJS
433398
]));
434399

435400
gulp.task('process:prebuilt', gulp.parallel([
@@ -444,8 +409,6 @@ const compileSourceAssets = gulp.series([
444409
gulp.parallel([
445410
compileIndvES2015ModulesToBrowser,
446411
compileES2015ToCJS,
447-
legacyBuild.compileDatabaseForBrowser,
448-
legacyBuild.compileDatabaseForCJS
449412
])
450413
]);
451414

@@ -455,7 +418,6 @@ gulp.task('build:browser', gulp.series([
455418
gulp.parallel([
456419
compileSourceAssets,
457420
processPrebuiltFilesForBrowser,
458-
legacyBuild.compileDatabaseForBrowser
459421
]),
460422
buildBrowserFirebaseJs
461423
]));

gulp/tasks/build.legacy.js

Lines changed: 0 additions & 141 deletions
This file was deleted.

gulp/tasks/dev.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ const gulp = require('gulp');
1717
const config = require('../config');
1818

1919
// Ensure that the test tasks get set up
20-
require('./test');
20+
const testFxns = require('./test');
2121

2222
function watchDevFiles() {
2323
const stream = gulp.watch([
2424
`${config.root}/src/**/*.ts`,
25-
config.paths.test.unit
26-
], gulp.parallel('test:unit'));
25+
'tests/**/*.test.ts'
26+
], testFxns.runBrowserUnitTests(true));
2727

28-
stream.on('error', () => {});
28+
stream.on('error', err => {});
2929
return stream;
3030
}
3131

3232
gulp.task('dev', gulp.parallel([
33-
'test:unit',
3433
watchDevFiles
3534
]));

0 commit comments

Comments
 (0)