Skip to content

Add the umbrella firebase package for modular packages #2927

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 13 commits into from
Apr 17, 2020
1 change: 1 addition & 0 deletions packages-exp/app-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c",
"build:release": "rollup -c rollup.config.release.js",
"build:deps": "lerna run --scope @firebase/app-exp --include-dependencies build",
"dev": "rollup -c -w",
"test": "yarn type-check && run-p lint test:browser test:node",
"test:browser": "karma start --single-run",
Expand Down
26 changes: 26 additions & 0 deletions packages-exp/firebase-exp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @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.
*/

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
project: 'tsconfig.json',
// to make vscode-eslint work with monorepo
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
tsconfigRootDir: __dirname
}
};
4 changes: 4 additions & 0 deletions packages-exp/firebase-exp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/firebase*.js
/firebase*.map
/firebase*.gz
/firebase*.tgz
5 changes: 5 additions & 0 deletions packages-exp/firebase-exp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Firebase - App success made simple

## Overview

TODO
22 changes: 22 additions & 0 deletions packages-exp/firebase-exp/app/index.cdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @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 { registerVersion } from '@firebase/app-exp';
import { name, version } from '../package.json';

registerVersion(name, version, 'cdn');
export * from '@firebase/app-exp';
21 changes: 21 additions & 0 deletions packages-exp/firebase-exp/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @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 { registerVersion } from '@firebase/app-exp';
import { name, version } from '../package.json';

registerVersion(name, version, 'app');
export * from '@firebase/app-exp';
7 changes: 7 additions & 0 deletions packages-exp/firebase-exp/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "firebase-exp/app",
"main": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"typings": "dist/app/index.d.ts"
}
35 changes: 35 additions & 0 deletions packages-exp/firebase-exp/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the CDN build? Is it not going to include polyfills anymore? Should we still registerVersion as 'cdn' to track when this build is used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's the firebase.js file. I don't think we need to include polyfills for several reasons:

  1. This file is intended for development and most people would use newer browsers that don't need polyfills.
  2. It discourages people to use it in production because it won't work in "all" browsers out of box.
  3. People can add polyfills themselves if needed. And I want us to get out of the business of deciding what polyfills to include and maintaining them forever.

Yup, good idea that we should keep tracking its usage. Will update.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added packages-exp/firebase-exp/app/index.cdn.ts. PTAL.

* @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 gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');

const OUTPUT_FILE = 'firebase.js';
const pkgJson = require('./package.json');
const files = [
...pkgJson.components.map(component => `firebase-${component}.js`)
];

gulp.task('firebase-js', function() {
return gulp
.src(files)
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat(OUTPUT_FILE))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
});
54 changes: 54 additions & 0 deletions packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "firebase-exp",
"version": "0.800.0",
"description": "Firebase JavaScript library for web and Node.js",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"license": "Apache-2.0",
"homepage": "https://firebase.google.com/",
"keywords": [
"authentication",
"database",
"Firebase",
"firebase",
"realtime",
"storage",
"performance",
"remote-config"
],
"files": [
"**/dist/",
"**/package.json",
"/firebase*.js",
"/firebase*.map"
],
"repository": {
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"scripts": {
"build": "rollup -c && gulp firebase-js",
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js",
"dev": "rollup -c -w",
"prepare": "yarn build"
},
"dependencies": {
"@firebase/app-exp": "0.800.0"
},
"devDependencies": {
"rollup": "1.28.0",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-license": "0.13.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-sourcemaps": "0.5.0",
"rollup-plugin-terser": "5.1.3",
"rollup-plugin-typescript2": "0.25.3",
"rollup-plugin-uglify": "6.0.4",
"gulp": "4.0.2",
"gulp-sourcemaps": "2.6.5",
"gulp-concat": "2.6.1",
"typescript": "3.7.5"
},
"components": [
"app"
]
}
159 changes: 159 additions & 0 deletions packages-exp/firebase-exp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* @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 { resolve } from 'path';
import resolveModule from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import sourcemaps from 'rollup-plugin-sourcemaps';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import { uglify } from 'rollup-plugin-uglify';
import json from 'rollup-plugin-json';
import pkg from './package.json';
import appPkg from './app/package.json';

const external = Object.keys(pkg.dependencies || {});

/**
* Global UMD Build
*/
const GLOBAL_NAME = 'firebase';

function createUmdOutputConfig(output, componentName) {
return {
file: output,
format: 'umd',
sourcemap: true,
extend: true,
name: `${GLOBAL_NAME}.${componentName}`,
globals: {
'@firebase/app-exp': `${GLOBAL_NAME}.app`
},

/**
* use iife to avoid below error in the old Safari browser
* SyntaxError: Functions cannot be declared in a nested block in strict mode
* https://github.com/firebase/firebase-js-sdk/issues/1228
*
*/
intro: `
try {
(function() {`,
outro: `
}).apply(this, arguments);
} catch(err) {
console.error(err);
throw new Error(
'Cannot instantiate ${output} - ' +
'be sure to load firebase-app.js first.'
);
}`
};
}

const plugins = [sourcemaps(), resolveModule(), json(), commonjs()];

const typescriptPlugin = rollupTypescriptPlugin({
typescript,
// Workaround for typescript plugins that use async functions.
// In this case, `rollup-plugin-sourcemaps`.
// See https://github.com/ezolenko/rollup-plugin-typescript2/blob/master/README.md
objectHashIgnoreUnknownHack: true,
// For safety, given hack above (see link).
clean: true
});

const typescriptPluginUMD = rollupTypescriptPlugin({
typescript,
// Workaround for typescript plugins that use async functions.
// In this case, `rollup-plugin-sourcemaps`.
// See https://github.com/ezolenko/rollup-plugin-typescript2/blob/master/README.md
objectHashIgnoreUnknownHack: true,
// For safety, given hack above (see link).
clean: true,
tsconfigOverride: {
compilerOptions: {
declaration: false
}
}
});

/**
* Individual Component Builds
*/
const appBuilds = [
/**
* App Browser Builds
*/
{
input: 'app/index.ts',
output: [
{ file: resolve('app', appPkg.main), format: 'cjs', sourcemap: true },
{ file: resolve('app', appPkg.module), format: 'es', sourcemap: true }
],
plugins: [...plugins, typescriptPlugin],
external
},
/**
* App UMD Builds
*/
{
input: 'app/index.cdn.ts',
output: {
file: 'firebase-app.js',
sourcemap: true,
format: 'umd',
name: `${GLOBAL_NAME}.app`
},
plugins: [...plugins, typescriptPluginUMD, uglify()]
}
];

const componentBuilds = pkg.components
// The "app" component is treated differently because it doesn't depend on itself.
.filter(component => component !== 'app')
.map(component => {
const pkg = require(`./${component}/package.json`);
return [
{
input: `${component}/index.ts`,
output: [
{
file: resolve(component, pkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve(component, pkg.module),
format: 'es',
sourcemap: true
}
],
plugins: [...plugins, typescriptPlugin],
external
},
{
input: `${component}/index.ts`,
output: createUmdOutputConfig(`firebase-${component}.js`, component),
plugins: [...plugins, typescriptPluginUMD, uglify()],
external: ['@firebase/app-exp']
}
];
})
.reduce((a, b) => a.concat(b), []);

export default [...appBuilds, ...componentBuilds];
Loading