Skip to content

Create compat package form performance exp #4522

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 6 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -24,6 +24,7 @@
"@firebase/installations-compat",
"@firebase/messaging-exp",
"@firebase/performance-exp",
"@firebase/performance-compat",
"@firebase/remote-config-exp",
"@firebase/remote-config-compat",
"firebase-exp",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/orange-countries-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/performance-compat": patch
---

Create compat package form performance exp
26 changes: 26 additions & 0 deletions packages-exp/performance-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/performance-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/performance-compat

This is the compat package that recreates the v8 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/performance-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/performance-compat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@firebase/performance-compat",
"version": "0.0.900",
"description": "The compatibility package of Firebase Performance",
"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",
"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:release": "rollup -c rollup.config.release.js",
"build:deps": "lerna run --scope @firebase/performance-compat --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p lint test:all",
"test:all": "run-p test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
"prettier": "prettier --write '{src,test}/**/*.{js,ts}'"
},
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app-compat": "0.x",
"@firebase/app-types": "0.x"
},
"dependencies": {
"@firebase/performance-exp": "0.0.900",
"@firebase/util": "0.4.0",
"@firebase/logger": "0.2.6",
"@firebase/component": "0.2.1",
"tslib": "^2.0.0"
},
"devDependencies": {
"rollup": "2.35.1",
"@rollup/plugin-json": "4.1.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.29.0",
"typescript": "4.2.2",
"@firebase/app-compat": "0.0.900"
},
"repository": {
"directory": "packages-exp/performance-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"
}
}
60 changes: 60 additions & 0 deletions packages-exp/performance-compat/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @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 typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import json from '@rollup/plugin-json';
import { es5BuildsNoPlugin, es2017BuildsNoPlugin } from './rollup.shared.js';

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

const es5Builds = es5BuildsNoPlugin.map(build => ({
...build,
plugins: es5BuildPlugins
}));

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

const es2017Builds = es2017BuildsNoPlugin.map(build => ({
...build,
plugins: es2017BuildPlugins
}));

export default [...es5Builds, ...es2017Builds];
67 changes: 67 additions & 0 deletions packages-exp/performance-compat/rollup.config.release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @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 typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import json from '@rollup/plugin-json';
import { es5BuildsNoPlugin, es2017BuildsNoPlugin } from './rollup.shared.js';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
clean: true,
abortOnError: false,
transformers: [importPathTransformer]
}),
json()
];

const es5Builds = es5BuildsNoPlugin.map(build => ({
...build,
plugins: es5BuildPlugins
}));

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

const es2017Builds = es2017BuildsNoPlugin.map(build => ({
...build,
plugins: es2017BuildPlugins
}));

export default [...es5Builds, ...es2017Builds];
51 changes: 51 additions & 0 deletions packages-exp/performance-compat/rollup.shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @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 pkg from './package.json';

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

export const es5BuildsNoPlugin = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.browser, format: 'es', sourcemap: true }
],
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

export const es2017BuildsNoPlugin = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];
57 changes: 57 additions & 0 deletions packages-exp/performance-compat/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @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 firebase, { _FirebaseNamespace } from '@firebase/app-compat';
import {
Component,
ComponentContainer,
ComponentType
} from '@firebase/component';
import { PerformanceCompatImpl } from './performance';
import { name as packageName, version } from '../package.json';
import { FirebasePerformance as FirebasePerformanceCompat } from '@firebase/performance-types';

// TODO: move it to the future performance-compat-types package
declare module '@firebase/component' {
interface NameServiceMapping {
'performance-compat': FirebasePerformanceCompat;
}
}

function registerPerformanceCompat(firebaseInstance: _FirebaseNamespace): void {
firebaseInstance.INTERNAL.registerComponent(
new Component(
'performance-compat',
performanceFactory,
ComponentType.PUBLIC
)
);

firebaseInstance.registerVersion(packageName, version);
}

function performanceFactory(
container: ComponentContainer
): PerformanceCompatImpl {
const app = container.getProvider('app-compat').getImmediate();
// The following call will always succeed.
const performance = container.getProvider('performance-exp').getImmediate();

return new PerformanceCompatImpl(app, performance);
}

registerPerformanceCompat(firebase as _FirebaseNamespace);
Loading