Skip to content

Commit 07cbd42

Browse files
authored
Initial copy of performance and performance-types to packages-exp (#3778)
* Initial copy of performance and performance-types to packages-exp * Removing CHANGELOG.md * Updated the copyright year on all files * Updating the version to 0.0.800 on both the performance-exp and performance-types-exp packages * Removing a file I added by mistake * Updating the copyright year of a few more files that I missed
1 parent 80e4219 commit 07cbd42

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

+4484
-0
lines changed
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+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @firebase/performance-exp
2+
3+
This is the Firebase Performance component of the Firebase JS SDK.
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/performance-exp/index.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 firebase from '@firebase/app';
19+
import '@firebase/installations';
20+
import { FirebaseApp, FirebaseNamespace } from '@firebase/app-types';
21+
import { _FirebaseNamespace } from '@firebase/app-types/private';
22+
import { PerformanceController } from './src/controllers/perf';
23+
import { setupApi } from './src/services/api_service';
24+
import { SettingsService } from './src/services/settings_service';
25+
import { ERROR_FACTORY, ErrorCode } from './src/utils/errors';
26+
import { FirebasePerformance } from '@firebase/performance-types';
27+
import { Component, ComponentType } from '@firebase/component';
28+
import { FirebaseInstallations } from '@firebase/installations-types';
29+
import { name, version } from './package.json';
30+
31+
const DEFAULT_ENTRY_NAME = '[DEFAULT]';
32+
33+
export function registerPerformance(instance: FirebaseNamespace): void {
34+
const factoryMethod = (
35+
app: FirebaseApp,
36+
installations: FirebaseInstallations
37+
): PerformanceController => {
38+
if (app.name !== DEFAULT_ENTRY_NAME) {
39+
throw ERROR_FACTORY.create(ErrorCode.FB_NOT_DEFAULT);
40+
}
41+
if (typeof window === 'undefined') {
42+
throw ERROR_FACTORY.create(ErrorCode.NO_WINDOW);
43+
}
44+
setupApi(window);
45+
SettingsService.getInstance().firebaseAppInstance = app;
46+
SettingsService.getInstance().installationsService = installations;
47+
return new PerformanceController(app);
48+
};
49+
50+
// Register performance with firebase-app.
51+
(instance as _FirebaseNamespace).INTERNAL.registerComponent(
52+
new Component(
53+
'performance',
54+
container => {
55+
/* Dependencies */
56+
// getImmediate for FirebaseApp will always succeed
57+
const app = container.getProvider('app').getImmediate();
58+
// The following call will always succeed because perf has `import '@firebase/installations'`
59+
const installations = container
60+
.getProvider('installations')
61+
.getImmediate();
62+
63+
return factoryMethod(app, installations);
64+
},
65+
ComponentType.PUBLIC
66+
)
67+
);
68+
69+
instance.registerVersion(name, version);
70+
}
71+
72+
registerPerformance(firebase);
73+
74+
declare module '@firebase/app-types' {
75+
interface FirebaseNamespace {
76+
performance?: {
77+
(app?: FirebaseApp): FirebasePerformance;
78+
};
79+
}
80+
interface FirebaseApp {
81+
performance?(): FirebasePerformance;
82+
}
83+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
config.set({
24+
...karmaBase,
25+
// files to load into karma
26+
files,
27+
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
28+
// frameworks to use
29+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
30+
frameworks: ['mocha']
31+
});
32+
};
33+
34+
module.exports.files = files;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@firebase/performance-exp",
3+
"version": "0.0.800",
4+
"description": "Firebase performance for web",
5+
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
6+
"main": "dist/index.cjs.js",
7+
"browser": "dist/index.cjs.js",
8+
"module": "dist/index.esm.js",
9+
"esm2017": "dist/index.esm2017.js",
10+
"files": ["dist"],
11+
"scripts": {
12+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
13+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts'",
14+
"build": "rollup -c",
15+
"build:deps": "lerna run --scope @firebase/performance-exp --include-dependencies build",
16+
"dev": "rollup -c -w",
17+
"test": "run-p lint test:browser",
18+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:browser",
19+
"test:browser": "karma start --single-run",
20+
"test:debug": "karma start --browsers=Chrome --auto-watch",
21+
"prepare": "yarn build",
22+
"prettier": "prettier --write '{src,test}/**/*.{js,ts}'"
23+
},
24+
"peerDependencies": {
25+
"@firebase/app": "0.x",
26+
"@firebase/app-types": "0.x"
27+
},
28+
"dependencies": {
29+
"@firebase/logger": "0.2.6",
30+
"@firebase/installations": "0.4.17",
31+
"@firebase/util": "0.3.2",
32+
"@firebase/performance-types-exp": "0.0.800",
33+
"@firebase/component": "0.1.19",
34+
"tslib": "^1.11.1"
35+
},
36+
"license": "Apache-2.0",
37+
"devDependencies": {
38+
"@firebase/app": "0.6.11",
39+
"rollup": "2.26.7",
40+
"rollup-plugin-json": "4.0.0",
41+
"rollup-plugin-typescript2": "0.27.2",
42+
"typescript": "4.0.2"
43+
},
44+
"repository": {
45+
"directory": "packages/performance-exp",
46+
"type": "git",
47+
"url": "https://github.com/firebase/firebase-js-sdk.git"
48+
},
49+
"bugs": {
50+
"url": "https://github.com/firebase/firebase-js-sdk/issues"
51+
},
52+
"typings": "dist/index.d.ts",
53+
"nyc": {
54+
"extension": [
55+
".ts"
56+
],
57+
"reportDir": "./coverage/node"
58+
}
59+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 json from 'rollup-plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
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 = [typescriptPlugin({ typescript }), json()];
31+
32+
const es5Builds = [
33+
{
34+
input: 'index.ts',
35+
output: [
36+
{ file: pkg.main, format: 'cjs', sourcemap: true },
37+
{ file: pkg.module, format: 'es', sourcemap: true }
38+
],
39+
plugins: es5BuildPlugins,
40+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
41+
}
42+
];
43+
44+
/**
45+
* ES2017 Builds
46+
*/
47+
48+
const es2017BuildPlugins = [
49+
typescriptPlugin({
50+
typescript,
51+
tsconfigOverride: {
52+
compilerOptions: {
53+
target: 'es2017'
54+
}
55+
}
56+
}),
57+
json({ preferConst: true })
58+
];
59+
60+
const es2017Builds = [
61+
{
62+
input: 'index.ts',
63+
output: [{ file: pkg.esm2017, format: 'es', sourcemap: true }],
64+
plugins: es2017BuildPlugins,
65+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
66+
}
67+
];
68+
69+
export default [...es5Builds, ...es2017Builds];
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 { version } from '../package.json';
19+
20+
export const SDK_VERSION = version;
21+
/** The prefix for start User Timing marks used for creating Traces. */
22+
export const TRACE_START_MARK_PREFIX = 'FB-PERF-TRACE-START';
23+
/** The prefix for stop User Timing marks used for creating Traces. */
24+
export const TRACE_STOP_MARK_PREFIX = 'FB-PERF-TRACE-STOP';
25+
/** The prefix for User Timing measure used for creating Traces. */
26+
export const TRACE_MEASURE_PREFIX = 'FB-PERF-TRACE-MEASURE';
27+
/** The prefix for out of the box page load Trace name. */
28+
export const OOB_TRACE_PAGE_LOAD_PREFIX = '_wt_';
29+
30+
export const FIRST_PAINT_COUNTER_NAME = '_fp';
31+
32+
export const FIRST_CONTENTFUL_PAINT_COUNTER_NAME = '_fcp';
33+
34+
export const FIRST_INPUT_DELAY_COUNTER_NAME = '_fid';
35+
36+
export const CONFIG_LOCAL_STORAGE_KEY = '@firebase/performance/config';
37+
38+
export const CONFIG_EXPIRY_LOCAL_STORAGE_KEY =
39+
'@firebase/performance/configexpire';
40+
41+
export const SERVICE = 'performance';
42+
export const SERVICE_NAME = 'Performance';

0 commit comments

Comments
 (0)