Skip to content

Commit 537350e

Browse files
authored
Add the umbrella firebase package for modular packages (#2927)
* add firebase-exp * add rollup config for generating CDN scripts * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * [AUTOMATED]: API Reports * remove old files * make release rollup config for firebase package * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: API Reports * add a CDN entry point, so we can collect its usage * [AUTOMATED]: License Headers * fix the transformer * [AUTOMATED]: Prettier Code Styling
1 parent c3f34dc commit 537350e

14 files changed

+608
-11
lines changed

packages-exp/app-exp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1717
"build": "rollup -c",
1818
"build:release": "rollup -c rollup.config.release.js",
19+
"build:deps": "lerna run --scope @firebase/app-exp --include-dependencies build",
1920
"dev": "rollup -c -w",
2021
"test": "yarn type-check && run-p lint test:browser test:node",
2122
"test:browser": "karma start --single-run",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
module.exports = {
19+
extends: '../../config/.eslintrc.js',
20+
parserOptions: {
21+
project: 'tsconfig.json',
22+
// to make vscode-eslint work with monorepo
23+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
24+
tsconfigRootDir: __dirname
25+
}
26+
};

packages-exp/firebase-exp/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/firebase*.js
2+
/firebase*.map
3+
/firebase*.gz
4+
/firebase*.tgz

packages-exp/firebase-exp/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Firebase - App success made simple
2+
3+
## Overview
4+
5+
TODO
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { registerVersion } from '@firebase/app-exp';
19+
import { name, version } from '../package.json';
20+
21+
registerVersion(name, version, 'cdn');
22+
export * from '@firebase/app-exp';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
import { registerVersion } from '@firebase/app-exp';
18+
import { name, version } from '../package.json';
19+
20+
registerVersion(name, version, 'app');
21+
export * from '@firebase/app-exp';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "firebase-exp/app",
3+
"main": "dist/index.cjs.js",
4+
"browser": "dist/index.esm.js",
5+
"module": "dist/index.esm.js",
6+
"typings": "dist/app/index.d.ts"
7+
}

packages-exp/firebase-exp/gulpfile.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var concat = require('gulp-concat');
20+
var sourcemaps = require('gulp-sourcemaps');
21+
22+
const OUTPUT_FILE = 'firebase.js';
23+
const pkgJson = require('./package.json');
24+
const files = [
25+
...pkgJson.components.map(component => `firebase-${component}.js`)
26+
];
27+
28+
gulp.task('firebase-js', function() {
29+
return gulp
30+
.src(files)
31+
.pipe(sourcemaps.init({ loadMaps: true }))
32+
.pipe(concat(OUTPUT_FILE))
33+
.pipe(sourcemaps.write('.'))
34+
.pipe(gulp.dest('.'));
35+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "firebase-exp",
3+
"version": "0.800.0",
4+
"description": "Firebase JavaScript library for web and Node.js",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"license": "Apache-2.0",
7+
"homepage": "https://firebase.google.com/",
8+
"keywords": [
9+
"authentication",
10+
"database",
11+
"Firebase",
12+
"firebase",
13+
"realtime",
14+
"storage",
15+
"performance",
16+
"remote-config"
17+
],
18+
"files": [
19+
"**/dist/",
20+
"**/package.json",
21+
"/firebase*.js",
22+
"/firebase*.map"
23+
],
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/firebase/firebase-js-sdk.git"
27+
},
28+
"scripts": {
29+
"build": "rollup -c && gulp firebase-js",
30+
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js",
31+
"dev": "rollup -c -w",
32+
"prepare": "yarn build"
33+
},
34+
"dependencies": {
35+
"@firebase/app-exp": "0.800.0"
36+
},
37+
"devDependencies": {
38+
"rollup": "1.28.0",
39+
"rollup-plugin-commonjs": "10.1.0",
40+
"rollup-plugin-license": "0.13.0",
41+
"rollup-plugin-node-resolve": "5.2.0",
42+
"rollup-plugin-sourcemaps": "0.5.0",
43+
"rollup-plugin-terser": "5.1.3",
44+
"rollup-plugin-typescript2": "0.25.3",
45+
"rollup-plugin-uglify": "6.0.4",
46+
"gulp": "4.0.2",
47+
"gulp-sourcemaps": "2.6.5",
48+
"gulp-concat": "2.6.1",
49+
"typescript": "3.7.5"
50+
},
51+
"components": [
52+
"app"
53+
]
54+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { resolve } from 'path';
19+
import resolveModule from 'rollup-plugin-node-resolve';
20+
import commonjs from 'rollup-plugin-commonjs';
21+
import sourcemaps from 'rollup-plugin-sourcemaps';
22+
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
23+
import typescript from 'typescript';
24+
import { uglify } from 'rollup-plugin-uglify';
25+
import json from 'rollup-plugin-json';
26+
import pkg from './package.json';
27+
import appPkg from './app/package.json';
28+
29+
const external = Object.keys(pkg.dependencies || {});
30+
31+
/**
32+
* Global UMD Build
33+
*/
34+
const GLOBAL_NAME = 'firebase';
35+
36+
function createUmdOutputConfig(output, componentName) {
37+
return {
38+
file: output,
39+
format: 'umd',
40+
sourcemap: true,
41+
extend: true,
42+
name: `${GLOBAL_NAME}.${componentName}`,
43+
globals: {
44+
'@firebase/app-exp': `${GLOBAL_NAME}.app`
45+
},
46+
47+
/**
48+
* use iife to avoid below error in the old Safari browser
49+
* SyntaxError: Functions cannot be declared in a nested block in strict mode
50+
* https://github.com/firebase/firebase-js-sdk/issues/1228
51+
*
52+
*/
53+
intro: `
54+
try {
55+
(function() {`,
56+
outro: `
57+
}).apply(this, arguments);
58+
} catch(err) {
59+
console.error(err);
60+
throw new Error(
61+
'Cannot instantiate ${output} - ' +
62+
'be sure to load firebase-app.js first.'
63+
);
64+
}`
65+
};
66+
}
67+
68+
const plugins = [sourcemaps(), resolveModule(), json(), commonjs()];
69+
70+
const typescriptPlugin = rollupTypescriptPlugin({
71+
typescript,
72+
// Workaround for typescript plugins that use async functions.
73+
// In this case, `rollup-plugin-sourcemaps`.
74+
// See https://github.com/ezolenko/rollup-plugin-typescript2/blob/master/README.md
75+
objectHashIgnoreUnknownHack: true,
76+
// For safety, given hack above (see link).
77+
clean: true
78+
});
79+
80+
const typescriptPluginUMD = rollupTypescriptPlugin({
81+
typescript,
82+
// Workaround for typescript plugins that use async functions.
83+
// In this case, `rollup-plugin-sourcemaps`.
84+
// See https://github.com/ezolenko/rollup-plugin-typescript2/blob/master/README.md
85+
objectHashIgnoreUnknownHack: true,
86+
// For safety, given hack above (see link).
87+
clean: true,
88+
tsconfigOverride: {
89+
compilerOptions: {
90+
declaration: false
91+
}
92+
}
93+
});
94+
95+
/**
96+
* Individual Component Builds
97+
*/
98+
const appBuilds = [
99+
/**
100+
* App Browser Builds
101+
*/
102+
{
103+
input: 'app/index.ts',
104+
output: [
105+
{ file: resolve('app', appPkg.main), format: 'cjs', sourcemap: true },
106+
{ file: resolve('app', appPkg.module), format: 'es', sourcemap: true }
107+
],
108+
plugins: [...plugins, typescriptPlugin],
109+
external
110+
},
111+
/**
112+
* App UMD Builds
113+
*/
114+
{
115+
input: 'app/index.cdn.ts',
116+
output: {
117+
file: 'firebase-app.js',
118+
sourcemap: true,
119+
format: 'umd',
120+
name: `${GLOBAL_NAME}.app`
121+
},
122+
plugins: [...plugins, typescriptPluginUMD, uglify()]
123+
}
124+
];
125+
126+
const componentBuilds = pkg.components
127+
// The "app" component is treated differently because it doesn't depend on itself.
128+
.filter(component => component !== 'app')
129+
.map(component => {
130+
const pkg = require(`./${component}/package.json`);
131+
return [
132+
{
133+
input: `${component}/index.ts`,
134+
output: [
135+
{
136+
file: resolve(component, pkg.main),
137+
format: 'cjs',
138+
sourcemap: true
139+
},
140+
{
141+
file: resolve(component, pkg.module),
142+
format: 'es',
143+
sourcemap: true
144+
}
145+
],
146+
plugins: [...plugins, typescriptPlugin],
147+
external
148+
},
149+
{
150+
input: `${component}/index.ts`,
151+
output: createUmdOutputConfig(`firebase-${component}.js`, component),
152+
plugins: [...plugins, typescriptPluginUMD, uglify()],
153+
external: ['@firebase/app-exp']
154+
}
155+
];
156+
})
157+
.reduce((a, b) => a.concat(b), []);
158+
159+
export default [...appBuilds, ...componentBuilds];

0 commit comments

Comments
 (0)