Skip to content

Create @firebase/app-compat and firebase/compat #3622

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 19 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
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 .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@firebase/functions-types-exp",
"@firebase/testing",
"firebase-exp",
"@firebase/app-compat",
"@firebase/changelog-generator",
"firebase-size-analysis"
],
Expand Down
9 changes: 5 additions & 4 deletions common/api-review/app-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FirebaseApp } from '@firebase/app-types-exp';
import { FirebaseAppConfig } from '@firebase/app-types-exp';
import { FirebaseOptions } from '@firebase/app-types-exp';
import { LogCallback } from '@firebase/logger';
import { LogLevel } from '@firebase/logger';
import { LogLevelString } from '@firebase/logger';
import { LogOptions } from '@firebase/logger';
import { Name } from '@firebase/component';
import { Provider } from '@firebase/component';
Expand All @@ -29,6 +29,9 @@ export function _clearComponents(): void;
// @internal
export const _components: Map<string, Component<any>>;

// @internal
export const _DEFAULT_ENTRY_NAME = "[DEFAULT]";

// @public
export function deleteApp(app: FirebaseApp): Promise<void>;

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

export { LogLevel }

// @public
export function onLog(logCallback: LogCallback | null, options?: LogOptions): void;

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

// @public
export function setLogLevel(logLevel: LogLevel): void;
export function setLogLevel(logLevel: LogLevelString): void;


```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"scripts": {
"dev": "lerna run --parallel --scope @firebase/* --scope firebase --scope rxfire dev",
"build": "lerna run --scope @firebase/app-exp build:deps && lerna run --scope @firebase/* --scope firebase --scope rxfire --ignore @firebase/app-exp build",
"build:exp": "lerna run --scope @firebase/*-exp --scope firebase-exp build",
"build:exp": "lerna run --scope @firebase/*-exp --scope @firebase/*-compat --scope firebase-exp build",
"build:release": "lerna run --scope @firebase/app-exp build:deps && lerna run --scope @firebase/* --scope firebase --scope rxfire --ignore @firebase/*-exp prepare",
"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",
"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",
"build:changed": "ts-node-script scripts/ci-test/build_changed.ts",
"link:packages": "lerna exec --scope @firebase/* --scope firebase --scope rxfire -- yarn link",
"stage:packages": "./scripts/prepublish.sh",
Expand Down
26 changes: 26 additions & 0 deletions packages-exp/app-compat/.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
}
};
5 changes: 5 additions & 0 deletions packages-exp/app-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/app-compat

This is the compat package that recreates the v7 APIs.

**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.**
35 changes: 35 additions & 0 deletions packages-exp/app-compat/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @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.
*/

const karmaBase = require('../../config/karma.base');

const files = ['test/**/*', 'src/**/*.test.ts'];

module.exports = function (config) {
const karmaConfig = Object.assign({}, karmaBase, {
// files to load into karma
files: files,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
frameworks: ['mocha']
});

config.set(karmaConfig);
};

module.exports.files = files;
61 changes: 61 additions & 0 deletions packages-exp/app-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@firebase/app-compat",
"version": "0.0.800",
"description": "The primary entrypoint to the Firebase JS SDK",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"private": true,
"main": "dist/index.cjs.js",
"browser": "dist/index.esm5.js",
"module": "dist/index.esm5.js",
"esm2017": "dist/index.esm2017.js",
"lite": "dist/index.lite.js",
"lite-esm2017": "dist/index.lite.esm2017.js",
"files": [
"dist"
],
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c",
"build:deps": "lerna run --scope @firebase/app-compat --include-dependencies build",
"dev": "rollup -c -w",
"test": "yarn type-check && run-p lint test:browser test:node",
"type-check": "tsc -p . --noEmit",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
"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",
"prepare": "yarn build"
},
"license": "Apache-2.0",
"dependencies": {
"@firebase/app-exp": "0.0.800",
"@firebase/util": "0.3.1",
"@firebase/logger": "0.2.6",
"@firebase/component": "0.1.18",
"tslib": "^1.11.1",
"dom-storage": "2.1.0",
"xmlhttprequest": "1.8.0"
},
"devDependencies": {
"rollup": "2.26.5",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.27.2",
"typescript": "4.0.2"
},
"repository": {
"directory": "packages-exp/app-compat",
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/src/index.d.ts",
"nyc": {
"extension": [
".ts"
],
"reportDir": "./coverage/node"
}
}
102 changes: 102 additions & 0 deletions packages-exp/app-compat/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @license
* Copyright 2018 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 typescriptPlugin from 'rollup-plugin-typescript2';
import json from 'rollup-plugin-json';
import typescript from 'typescript';
import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript
}),
json()
];

const es5Builds = [
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: 'src/index.lite.ts',
output: {
file: pkg.lite,
format: 'es',
sourcemap: true
},
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
}
}),
json({
preferConst: true
})
];

const es2017Builds = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: 'src/index.lite.ts',
output: {
file: pkg['lite-esm2017'],
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

export default [...es5Builds, ...es2017Builds];
40 changes: 40 additions & 0 deletions packages-exp/app-compat/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @license
* Copyright 2019 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 { ErrorFactory, ErrorMap } from '@firebase/util';

export const enum AppError {
NO_APP = 'no-app',
INVALID_APP_ARGUMENT = 'invalid-app-argument'
}

const ERRORS: ErrorMap<AppError> = {
[AppError.NO_APP]:
"No Firebase App '{$appName}' has been created - " +
'call Firebase App.initializeApp()',
[AppError.INVALID_APP_ARGUMENT]:
'firebase.{$appName}() takes either no argument or a ' +
'Firebase App instance.'
};

type ErrorParams = { [key in AppError]: { appName: string } };

export const ERROR_FACTORY = new ErrorFactory<AppError, ErrorParams>(
'app-compat',
'Firebase',
ERRORS
);
Loading