Skip to content

Initial copy of performance and performance-types to packages-exp #3778

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
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions packages-exp/performance-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
}
};
5 changes: 5 additions & 0 deletions packages-exp/performance-exp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/performance-exp

This is the Firebase Performance component of the Firebase JS SDK.

**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.**
83 changes: 83 additions & 0 deletions packages-exp/performance-exp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @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 from '@firebase/app';
import '@firebase/installations';
import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
import { _FirebaseNamespace } from '@firebase/app-types/private';
import { PerformanceController } from './src/controllers/perf';
import { setupApi } from './src/services/api_service';
import { SettingsService } from './src/services/settings_service';
import { ERROR_FACTORY, ErrorCode } from './src/utils/errors';
import { FirebasePerformance } from '@firebase/performance-types';
import { Component, ComponentType } from '@firebase/component';
import { FirebaseInstallations } from '@firebase/installations-types';
import { name, version } from './package.json';

const DEFAULT_ENTRY_NAME = '[DEFAULT]';

export function registerPerformance(instance: FirebaseNamespace): void {
const factoryMethod = (
app: FirebaseApp,
installations: FirebaseInstallations
): PerformanceController => {
if (app.name !== DEFAULT_ENTRY_NAME) {
throw ERROR_FACTORY.create(ErrorCode.FB_NOT_DEFAULT);
}
if (typeof window === 'undefined') {
throw ERROR_FACTORY.create(ErrorCode.NO_WINDOW);
}
setupApi(window);
SettingsService.getInstance().firebaseAppInstance = app;
SettingsService.getInstance().installationsService = installations;
return new PerformanceController(app);
};

// Register performance with firebase-app.
(instance as _FirebaseNamespace).INTERNAL.registerComponent(
new Component(
'performance',
container => {
/* Dependencies */
// getImmediate for FirebaseApp will always succeed
const app = container.getProvider('app').getImmediate();
// The following call will always succeed because perf has `import '@firebase/installations'`
const installations = container
.getProvider('installations')
.getImmediate();

return factoryMethod(app, installations);
},
ComponentType.PUBLIC
)
);

instance.registerVersion(name, version);
}

registerPerformance(firebase);

declare module '@firebase/app-types' {
interface FirebaseNamespace {
performance?: {
(app?: FirebaseApp): FirebasePerformance;
};
}
interface FirebaseApp {
performance?(): FirebasePerformance;
}
}
34 changes: 34 additions & 0 deletions packages-exp/performance-exp/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @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) {
config.set({
...karmaBase,
// files to load into karma
files,
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha']
});
};

module.exports.files = files;
59 changes: 59 additions & 0 deletions packages-exp/performance-exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@firebase/performance-exp",
"version": "0.0.800",
"description": "Firebase performance for web",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "dist/index.cjs.js",
"browser": "dist/index.cjs.js",
"module": "dist/index.esm.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'",
"build": "rollup -c",
"build:deps": "lerna run --scope @firebase/performance-exp --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p lint test:browser",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
"test:browser": "karma start --single-run",
"test:debug": "karma start --browsers=Chrome --auto-watch",
"prepare": "yarn build",
"prettier": "prettier --write '{src,test}/**/*.{js,ts}'"
},
"peerDependencies": {
"@firebase/app": "0.x",
"@firebase/app-types": "0.x"
},
"dependencies": {
"@firebase/logger": "0.2.6",
"@firebase/installations": "0.4.17",
"@firebase/util": "0.3.2",
"@firebase/performance-types-exp": "0.0.800",
"@firebase/component": "0.1.19",
"tslib": "^1.11.1"
},
"license": "Apache-2.0",
"devDependencies": {
"@firebase/app": "0.6.11",
"rollup": "2.26.7",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-typescript2": "0.27.2",
"typescript": "4.0.2"
},
"repository": {
"directory": "packages/performance-exp",
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/index.d.ts",
"nyc": {
"extension": [
".ts"
],
"reportDir": "./coverage/node"
}
}
69 changes: 69 additions & 0 deletions packages-exp/performance-exp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @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 json from 'rollup-plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
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: '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}/`))
}
];

/**
* ES2017 Builds
*/

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

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

export default [...es5Builds, ...es2017Builds];
42 changes: 42 additions & 0 deletions packages-exp/performance-exp/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @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 { version } from '../package.json';

export const SDK_VERSION = version;
/** The prefix for start User Timing marks used for creating Traces. */
export const TRACE_START_MARK_PREFIX = 'FB-PERF-TRACE-START';
/** The prefix for stop User Timing marks used for creating Traces. */
export const TRACE_STOP_MARK_PREFIX = 'FB-PERF-TRACE-STOP';
/** The prefix for User Timing measure used for creating Traces. */
export const TRACE_MEASURE_PREFIX = 'FB-PERF-TRACE-MEASURE';
/** The prefix for out of the box page load Trace name. */
export const OOB_TRACE_PAGE_LOAD_PREFIX = '_wt_';

export const FIRST_PAINT_COUNTER_NAME = '_fp';

export const FIRST_CONTENTFUL_PAINT_COUNTER_NAME = '_fcp';

export const FIRST_INPUT_DELAY_COUNTER_NAME = '_fid';

export const CONFIG_LOCAL_STORAGE_KEY = '@firebase/performance/config';

export const CONFIG_EXPIRY_LOCAL_STORAGE_KEY =
'@firebase/performance/configexpire';

export const SERVICE = 'performance';
export const SERVICE_NAME = 'Performance';
Loading