Skip to content

Commit 1a82549

Browse files
authored
Create @firebase/app-compat and firebase/compat (#3622)
* init package * app-compat impl * get tests pass * update some metadata * add firebase compat * release test * build compat packages * fix npm scripts * Revert "release test" This reverts commit 97585c1. * remove npmignore and outdated license headers * add onLog and setLogLevel to app-compat * rename test file * update deps * update * revert * add test:ci script
1 parent e22a295 commit 1a82549

Some content is hidden

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

41 files changed

+1947
-29
lines changed

.changeset/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@firebase/functions-types-exp",
1717
"@firebase/testing",
1818
"firebase-exp",
19+
"@firebase/app-compat",
1920
"@firebase/changelog-generator",
2021
"firebase-size-analysis"
2122
],

common/api-review/app-exp.api.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FirebaseApp } from '@firebase/app-types-exp';
99
import { FirebaseAppConfig } from '@firebase/app-types-exp';
1010
import { FirebaseOptions } from '@firebase/app-types-exp';
1111
import { LogCallback } from '@firebase/logger';
12-
import { LogLevel } from '@firebase/logger';
12+
import { LogLevelString } from '@firebase/logger';
1313
import { LogOptions } from '@firebase/logger';
1414
import { Name } from '@firebase/component';
1515
import { Provider } from '@firebase/component';
@@ -29,6 +29,9 @@ export function _clearComponents(): void;
2929
// @internal
3030
export const _components: Map<string, Component<any>>;
3131

32+
// @internal
33+
export const _DEFAULT_ENTRY_NAME = "[DEFAULT]";
34+
3235
// @public
3336
export function deleteApp(app: FirebaseApp): Promise<void>;
3437

@@ -47,8 +50,6 @@ export function initializeApp(options: FirebaseOptions, name?: string): Firebase
4750
// @public
4851
export function initializeApp(options: FirebaseOptions, config?: FirebaseAppConfig): FirebaseApp;
4952

50-
export { LogLevel }
51-
5253
// @public
5354
export function onLog(logCallback: LogCallback | null, options?: LogOptions): void;
5455

@@ -65,7 +66,7 @@ export function _removeServiceInstance<T extends Name>(app: FirebaseApp, name: T
6566
export const SDK_VERSION: string;
6667

6768
// @public
68-
export function setLogLevel(logLevel: LogLevel): void;
69+
export function setLogLevel(logLevel: LogLevelString): void;
6970

7071

7172
```

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"scripts": {
2424
"dev": "lerna run --parallel --scope @firebase/* --scope firebase --scope rxfire dev",
2525
"build": "lerna run --scope @firebase/app-exp build:deps && lerna run --scope @firebase/* --scope firebase --scope rxfire --ignore @firebase/app-exp build",
26-
"build:exp": "lerna run --scope @firebase/*-exp --scope firebase-exp build",
26+
"build:exp": "lerna run --scope @firebase/*-exp --scope @firebase/*-compat --scope firebase-exp build",
2727
"build:release": "lerna run --scope @firebase/app-exp build:deps && lerna run --scope @firebase/* --scope firebase --scope rxfire --ignore @firebase/*-exp prepare",
28-
"build:exp:release": "yarn --cwd packages/app build:deps && lerna run --scope @firebase/*-exp --scope firebase-exp prepare && yarn --cwd packages-exp/app-exp typings:public",
28+
"build:exp:release": "yarn --cwd packages/app build:deps && lerna run --scope @firebase/*-exp --scope @firebase/*-compat --scope firebase-exp prepare && yarn --cwd packages-exp/app-exp typings:public",
2929
"build:changed": "ts-node-script scripts/ci-test/build_changed.ts",
3030
"link:packages": "lerna exec --scope @firebase/* --scope firebase --scope rxfire -- yarn link",
3131
"stage:packages": "./scripts/prepublish.sh",

packages-exp/app-compat/.eslintrc.js

+26
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/app-compat/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/app-compat
2+
3+
This is the compat package that recreates the v7 APIs.
4+
5+
**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**

packages-exp/app-compat/karma.conf.js

+35
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+
const karmaBase = require('../../config/karma.base');
19+
20+
const files = ['test/**/*', 'src/**/*.test.ts'];
21+
22+
module.exports = function (config) {
23+
const karmaConfig = Object.assign({}, karmaBase, {
24+
// files to load into karma
25+
files: files,
26+
// frameworks to use
27+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
28+
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
29+
frameworks: ['mocha']
30+
});
31+
32+
config.set(karmaConfig);
33+
};
34+
35+
module.exports.files = files;

packages-exp/app-compat/package.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "@firebase/app-compat",
3+
"version": "0.0.800",
4+
"description": "The primary entrypoint to the Firebase JS SDK",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"private": true,
7+
"main": "dist/index.cjs.js",
8+
"browser": "dist/index.esm5.js",
9+
"module": "dist/index.esm5.js",
10+
"esm2017": "dist/index.esm2017.js",
11+
"lite": "dist/index.lite.js",
12+
"lite-esm2017": "dist/index.lite.esm2017.js",
13+
"files": [
14+
"dist"
15+
],
16+
"scripts": {
17+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
18+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
19+
"build": "rollup -c",
20+
"build:deps": "lerna run --scope @firebase/app-compat --include-dependencies build",
21+
"dev": "rollup -c -w",
22+
"test": "run-p lint test:all",
23+
"test:all": "run-p test:browser test:node",
24+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
25+
"test:browser": "karma start --single-run",
26+
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
27+
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* src/**/*.test.ts --config ../../config/mocharc.node.js",
28+
"prepare": "yarn build"
29+
},
30+
"license": "Apache-2.0",
31+
"dependencies": {
32+
"@firebase/app-exp": "0.0.800",
33+
"@firebase/util": "0.3.1",
34+
"@firebase/logger": "0.2.6",
35+
"@firebase/component": "0.1.18",
36+
"tslib": "^1.11.1",
37+
"dom-storage": "2.1.0",
38+
"xmlhttprequest": "1.8.0"
39+
},
40+
"devDependencies": {
41+
"rollup": "2.26.5",
42+
"rollup-plugin-json": "4.0.0",
43+
"rollup-plugin-replace": "2.2.0",
44+
"rollup-plugin-typescript2": "0.27.2",
45+
"typescript": "4.0.2"
46+
},
47+
"repository": {
48+
"directory": "packages-exp/app-compat",
49+
"type": "git",
50+
"url": "https://github.com/firebase/firebase-js-sdk.git"
51+
},
52+
"bugs": {
53+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
54+
},
55+
"typings": "dist/src/index.d.ts",
56+
"nyc": {
57+
"extension": [
58+
".ts"
59+
],
60+
"reportDir": "./coverage/node"
61+
}
62+
}
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license
3+
* Copyright 2018 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 typescriptPlugin from 'rollup-plugin-typescript2';
19+
import json from 'rollup-plugin-json';
20+
import typescript from 'typescript';
21+
import pkg from './package.json';
22+
23+
const deps = Object.keys(
24+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25+
);
26+
27+
/**
28+
* ES5 Builds
29+
*/
30+
const es5BuildPlugins = [
31+
typescriptPlugin({
32+
typescript
33+
}),
34+
json()
35+
];
36+
37+
const es5Builds = [
38+
{
39+
input: 'src/index.ts',
40+
output: [
41+
{ file: pkg.main, format: 'cjs', sourcemap: true },
42+
{ file: pkg.module, format: 'es', sourcemap: true }
43+
],
44+
plugins: es5BuildPlugins,
45+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
46+
},
47+
{
48+
input: 'src/index.lite.ts',
49+
output: {
50+
file: pkg.lite,
51+
format: 'es',
52+
sourcemap: true
53+
},
54+
plugins: es5BuildPlugins,
55+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
56+
}
57+
];
58+
59+
/**
60+
* ES2017 Builds
61+
*/
62+
const es2017BuildPlugins = [
63+
typescriptPlugin({
64+
typescript,
65+
tsconfigOverride: {
66+
compilerOptions: {
67+
target: 'es2017'
68+
}
69+
}
70+
}),
71+
json({
72+
preferConst: true
73+
})
74+
];
75+
76+
const es2017Builds = [
77+
/**
78+
* Browser Builds
79+
*/
80+
{
81+
input: 'src/index.ts',
82+
output: {
83+
file: pkg.esm2017,
84+
format: 'es',
85+
sourcemap: true
86+
},
87+
plugins: es2017BuildPlugins,
88+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
89+
},
90+
{
91+
input: 'src/index.lite.ts',
92+
output: {
93+
file: pkg['lite-esm2017'],
94+
format: 'es',
95+
sourcemap: true
96+
},
97+
plugins: es2017BuildPlugins,
98+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
99+
}
100+
];
101+
102+
export default [...es5Builds, ...es2017Builds];

packages-exp/app-compat/src/errors.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright 2019 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 { ErrorFactory, ErrorMap } from '@firebase/util';
19+
20+
export const enum AppError {
21+
NO_APP = 'no-app',
22+
INVALID_APP_ARGUMENT = 'invalid-app-argument'
23+
}
24+
25+
const ERRORS: ErrorMap<AppError> = {
26+
[AppError.NO_APP]:
27+
"No Firebase App '{$appName}' has been created - " +
28+
'call Firebase App.initializeApp()',
29+
[AppError.INVALID_APP_ARGUMENT]:
30+
'firebase.{$appName}() takes either no argument or a ' +
31+
'Firebase App instance.'
32+
};
33+
34+
type ErrorParams = { [key in AppError]: { appName: string } };
35+
36+
export const ERROR_FACTORY = new ErrorFactory<AppError, ErrorParams>(
37+
'app-compat',
38+
'Firebase',
39+
ERRORS
40+
);

0 commit comments

Comments
 (0)