Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ npm-debug.log
/.vscode
/.ts-node
/.idea
/.awcache
14 changes: 13 additions & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ const configObj = {
"browsers": [
"ie >= 9"
]
}
},
}]
]
},
babelWebpack: {
presets: [
["env", {
"modules": false,
"targets": {
"browsers": [
"ie >= 9"
]
},
}]
]
},
Expand Down
60 changes: 29 additions & 31 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ const path = require('path');
const clone = require('gulp-clone');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const named = require('vinyl-named');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const uglify = require('gulp-uglify');
const gulpFile = require('gulp-file');
const ignore = require('gulp-ignore');
const rimraf = require('rimraf');
const header = require('gulp-header');
const gitRev = require('git-rev-sync');
Expand All @@ -43,6 +40,7 @@ const glob = require('glob');
const fs = require('fs');
const gzipSize = require('gzip-size');
const WrapperPlugin = require('wrapper-webpack-plugin');
const { CheckerPlugin } = require('awesome-typescript-loader');

function cleanDist(dir) {
return function cleanDistDirectory(done) {
Expand Down Expand Up @@ -115,20 +113,6 @@ function compileIndvES2015ModulesToBrowser() {
return pathObj.name === 'firebase-app';
};

const babelLoader = {
loader: 'babel-loader',
options: config.babel
};

const tsLoader = {
loader: 'ts-loader',
options: {
compilerOptions: {
declaration: false
}
}
};

const webpackConfig = {
devtool: 'source-map',
entry: {
Expand All @@ -144,21 +128,23 @@ function compileIndvES2015ModulesToBrowser() {
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
babelLoader,
tsLoader
]
}, {
test: /\.js$/,
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
babelLoader
]
loader: 'awesome-typescript-loader',
options: {
useCache: true,
useBabel: true,
babelOptions: config.babelWebpack
}
}]
},
plugins: [
new CheckerPlugin(),
new webpack.DefinePlugin({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I diff'ed doing the compression w/ and w/o this. For me I was seeing a little bit better results compiling database without this.

Size Comparison

File With webpack.DefinePlugin Without webpack.DefinePlugin
firebase-database.js 166.19 KB 166.16 KB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll get rid of it then.

'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'firebase-app'
Expand All @@ -171,8 +157,9 @@ function compileIndvES2015ModulesToBrowser() {
`;
},
footer: fileName => {
// Note: '.default' needed because of https://github.com/babel/babel/issues/2212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!

return isFirebaseApp(fileName) ? `
})();` : `
})().default;` : `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably leave a comment here pointing to babel/babel#2212 for future reference as to why this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that link, it has a lot of useful info. Adding .default was more of a temporary fix after the changes I made, I want to see if there's a better (proper) way to export/import the namespace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I was using babel-plugin-add-module-exports for that reason. If we are going to move away from using the babel-loader then we need to do something to recreate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment pointing to that url for reference. I finally opted not to use babel-plugin-add-module-exports since it needs CommonJS modules to do its thing, but webpack needs to work with ES2015 modules in order to perform tree shaking.

} catch(error) {
throw new Error(
'Cannot instantiate ${fileName} - ' +
Expand All @@ -182,13 +169,24 @@ function compileIndvES2015ModulesToBrowser() {
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
sourceMap: true,
mangle: {
props: {
ignore_quoted: true,
regex: /_$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find on this, I found that by expanding this regex I was able to get some other small savings. The regex I used included the _ prefix:

i.e.

/_$|^_/

I think, once this is in, going through and refactoring property names that don't get exposed (regardless of public or private markings as I know we use some of those for internally public stuff) we can get some more savings.

Size Comparison

File Suffix Only Regex Prefix + Suffix Regex
firebase-app.js 16.14 KB (5.61 KB) 15.7 KB (5.55 KB)
firebase-database.js 166.16 KB (45.55 KB) 165.8 KB (45.52 KB)
firebase-messaging.js 18.22 KB (5.59 KB) 18.2 KB (5.59 KB)
firebase.js 371.3 KB (108.1 KB) 370.49 KB (108.02 KB)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! The SDK code only uses _ as a suffix but other imported dependencies must be using it as a prefix too. I'll update it with this change.

}
},
compress: {
passes: 3,
unsafe: true,
warnings: false,
}
})
],
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
}
};

return gulp.src('src/**/*.ts')
.pipe(webpackStream(webpackConfig, webpack))
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.8",
"@types/sinon": "^1.16.35",
"awesome-typescript-loader": "^3.2.1",
"babel-cli": "^6.23.0",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-inline-replace-variables": "^1.2.2",
"babel-plugin-minify-dead-code-elimination": "^0.1.4",
Expand All @@ -53,15 +53,13 @@
"gulp-file": "^0.3.0",
"gulp-header": "^1.8.8",
"gulp-if": "^2.0.2",
"gulp-ignore": "^2.0.2",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^4.1.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-sourcemaps": "^2.4.1",
"gulp-strip-comments": "^2.4.5",
"gulp-typescript": "^3.1.6",
"gulp-uglify": "^2.1.1",
"gzip-size": "^3.0.0",
"husky": "^0.13.3",
"jsdom": "^9.12.0",
Expand All @@ -78,7 +76,6 @@
"shx": "^0.2.2",
"sinon": "^2.1.0",
"through2": "^2.0.3",
"ts-loader": "^2.1.0",
"ts-node": "2.1.1",
"typescript": "^2.2.1",
"validate-commit-msg": "^2.12.1",
Expand Down
29 changes: 14 additions & 15 deletions src/database/core/util/ImmutableTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@ import { forEach } from '../../../utils/obj';

let emptyChildrenSingleton: SortedMap<string, ImmutableTree<null>>;

/**
* Singleton empty children collection.
*
* @const
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
*/
const EmptyChildren = (): SortedMap<string, ImmutableTree<null>> => {
if (!emptyChildrenSingleton) {
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
}
return emptyChildrenSingleton;
};

/**
* A tree with immutable elements.
*/
export class ImmutableTree<T> {
static Empty = new ImmutableTree<any>(null);

/**
* Singleton empty children collection.
*
* @const
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
* @private
*/
private static get EmptyChildren_(): SortedMap<string, ImmutableTree<null>> {
if (!emptyChildrenSingleton) {
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
}
return emptyChildrenSingleton;
}

/**
* @template T
* @param {!Object.<string, !T>} obj
Expand All @@ -60,7 +59,7 @@ export class ImmutableTree<T> {
* @param {SortedMap.<string, !ImmutableTree.<T>>=} children
*/
constructor(public readonly value: T | null,
public readonly children: SortedMap<string, ImmutableTree<T>> = ImmutableTree.EmptyChildren_) {
public readonly children: SortedMap<string, ImmutableTree<T>> = EmptyChildren()) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"outDir": "dist/es2015",
"rootDir": "src",
"sourceMap": true,
"target": "es2015",
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
Expand Down
Loading