Skip to content

Commit

Permalink
Add version reporting for all packages (#2405)
Browse files Browse the repository at this point in the history
Add version reporting for all packages plus bundle variant suffix
  • Loading branch information
hsubox76 authored Dec 10, 2019
1 parent 85c9f48 commit 33388ae
Show file tree
Hide file tree
Showing 37 changed files with 147 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/app-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface FirebaseNamespace {
* @param library Name of 1p or 3p library (e.g. firestore, angularfire)
* @param version Current version of that library.
*/
registerVersion(library: string, version: string): void;
registerVersion(library: string, version: string, variant?: string): void;

// The current SDK version.
SDK_VERSION: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/index.lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { registerCoreComponents } from './src/registerCoreComponents';

export const firebase = createFirebaseNamespaceLite();

registerCoreComponents(firebase);
registerCoreComponents(firebase, 'lite');

// eslint-disable-next-line import/no-default-export
export default firebase;
2 changes: 1 addition & 1 deletion packages/app/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { registerCoreComponents } from './src/registerCoreComponents';

export const firebase = _firebase as FirebaseNamespace;

registerCoreComponents(firebase);
registerCoreComponents(firebase, 'node');

// eslint-disable-next-line import/no-default-export
export default firebase;
2 changes: 1 addition & 1 deletion packages/app/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const { AsyncStorage } = require('react-native');

export const firebase = _firebase as FirebaseNamespace;

registerCoreComponents(firebase);
registerCoreComponents(firebase, 'rn');

// eslint-disable-next-line import/no-default-export
export default firebase;
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/app/index.d.ts",
"typings": "dist/packages/app/index.d.ts",
"nyc": {
"extension": [
".ts"
Expand Down
8 changes: 2 additions & 6 deletions packages/app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { name as performanceName } from '../../performance/package.json';
import { name as remoteConfigName } from '../../remote-config/package.json';
import { name as storageName } from '../../storage/package.json';
import { name as firestoreName } from '../../firestore/package.json';
import { name as packageName } from '../../../package.json';

export const PLATFORM_LOG_STRING = {
[appName]: 'fire-core',
Expand All @@ -39,10 +40,5 @@ export const PLATFORM_LOG_STRING = {
[storageName]: 'fire-gcs',
[firestoreName]: 'fire-fst',
'fire-js': 'fire-js', // Platform identifier for JS SDK.
'fire-js-all-app': 'fire-js-all-app', // firebase/app import
'fire-js-all': 'fire-js-all', // 'firebase' import
'fire-js-all-node': 'fire-js-all-node',
'fire-js-all-rn': 'fire-js-all-rn',
'fire-js-all-lite': 'fire-js-all-lite',
'fire-js-all-cdn': 'fire-js-all-cdn'
[packageName]: 'fire-js-all'
} as const;
11 changes: 9 additions & 2 deletions packages/app/src/firebaseNamespaceCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,17 @@ export function createFirebaseNamespaceCore(
: null;
}

function registerVersion(libraryKeyOrName: string, version: string): void {
function registerVersion(
libraryKeyOrName: string,
version: string,
variant?: string
): void {
// TODO: We can use this check to whitelist strings when/if we set up
// a good whitelist system.
const library = PLATFORM_LOG_STRING[libraryKeyOrName] ?? libraryKeyOrName;
let library = PLATFORM_LOG_STRING[libraryKeyOrName] ?? libraryKeyOrName;
if (variant) {
library += `-${variant}`;
}
const libraryMismatch = library.match(/\s|\//);
const versionMismatch = version.match(/\s|\//);
if (libraryMismatch || versionMismatch) {
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/registerCoreComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { Component, ComponentType } from '@firebase/component';
import { PlatformLoggerService } from './platformLoggerService';
import { name, version } from '../package.json';

export function registerCoreComponents(firebase: FirebaseNamespace): void {
export function registerCoreComponents(
firebase: FirebaseNamespace,
variant?: string
): void {
(firebase as _FirebaseNamespace).INTERNAL.registerComponent(
new Component(
'platform-logger',
Expand All @@ -30,7 +33,7 @@ export function registerCoreComponents(firebase: FirebaseNamespace): void {
)
);
// Register `app` package.
firebase.registerVersion(name, version);
firebase.registerVersion(name, version, variant);
// Register platform SDK identifier (no version).
firebase.registerVersion('fire-js', '');
}
23 changes: 23 additions & 0 deletions packages/app/test/platformLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ describe('Platform Logger Service', () => {
return (firebase as any)['test-shell']();
});

it(`logs core version with bundle variant`, () => {
firebase.initializeApp({});
registerCoreComponents(firebase, 'node');
(firebase as _FirebaseNamespace).INTERNAL.registerComponent(
new Component(
'test-shell',
async (container: ComponentContainer) => {
const platformLoggerProvider = container.getProvider(
'platform-logger'
);
const platformLogger = (await platformLoggerProvider.get()) as PlatformLoggerService;
const platformInfoString = platformLogger.getPlatformInfoString();
expect(platformInfoString).to.include(
`fire-core-node/${appVersion}`
);
expect(platformInfoString).to.include('fire-js/');
},
ComponentType.PUBLIC
)
);
return (firebase as any)['test-shell']();
});

it(`logs other components' versions`, () => {
firebase.initializeApp({});
registerCoreComponents(firebase);
Expand Down
5 changes: 4 additions & 1 deletion packages/auth/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const del = require('del');
const express = require('express');
const path = require('path');
const sourcemaps = require('gulp-sourcemaps');
const pkg = require('./package.json');

// The optimization level for the JS compiler.
// Valid levels: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.
Expand Down Expand Up @@ -79,7 +80,9 @@ function createBuildTask(filename, prefix, suffix) {
)
],
language_out: 'ES5',
only_closure_dependencies: true
only_closure_dependencies: true,
// Insert current package.json version into registerVersion call.
define: `AUTH_NPM_PACKAGE_VERSION=${pkg.version}`
})
)
.pipe(sourcemaps.write('.'))
Expand Down
3 changes: 3 additions & 0 deletions packages/auth/src/exports_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ goog.require('fireauth.grecaptcha');
goog.require('fireauth.idp.ProviderId');
goog.require('goog.Promise');

/** @define {string} */
const AUTH_NPM_PACKAGE_VERSION = '';

fireauth.exportlib.exportPrototypeMethods(
fireauth.Auth.prototype, {
Expand Down Expand Up @@ -705,6 +707,7 @@ fireauth.exportlib.exportFunction(

firebase.INTERNAL.registerComponent(authComponent);
firebase.INTERNAL.registerComponent(authInteropComponent);
firebase.registerVersion('@firebase/auth', AUTH_NPM_PACKAGE_VERSION);

// Expose User as firebase.User.
firebase.INTERNAL.extendNamespace({
Expand Down
4 changes: 4 additions & 0 deletions packages/database/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
} from '@firebase/component';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';

import { name, version } from './package.json';

setWebSocketImpl(Client);

const ServerValue = Database.ServerValue;
Expand Down Expand Up @@ -131,6 +133,8 @@ export function registerDatabase(instance: FirebaseNamespace) {
.setMultipleInstances(true)
);

instance.registerVersion(name, version, 'node');

if (isNodeSdk()) {
module.exports = Object.assign({}, namespace, { initStandalone });
}
Expand Down
4 changes: 4 additions & 0 deletions packages/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import * as types from '@firebase/database-types';
import { setSDKVersion } from './src/core/version';
import { Component, ComponentType } from '@firebase/component';

import { name, version } from './package.json';

const ServerValue = Database.ServerValue;

export function registerDatabase(instance: FirebaseNamespace) {
Expand Down Expand Up @@ -71,6 +73,8 @@ export function registerDatabase(instance: FirebaseNamespace) {
.setMultipleInstances(true)
);

instance.registerVersion(name, version);

if (isNodeSdk()) {
module.exports = namespace;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/database/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* 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';
Expand All @@ -29,7 +30,8 @@ const deps = Object.keys(
const es5BuildPlugins = [
typescriptPlugin({
typescript
})
}),
json()
];

const es5Builds = [
Expand Down Expand Up @@ -67,7 +69,8 @@ const es2017BuildPlugins = [
target: 'es2017'
}
}
})
}),
json({ preferConst: true })
];

const es2017Builds = [
Expand Down
3 changes: 2 additions & 1 deletion packages/firebase/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

import firebase from '@firebase/app';
import { name, version } from '../package.json';

firebase.registerVersion('fire-js-all-app', firebase.SDK_VERSION);
firebase.registerVersion(name, version, 'app');

export default firebase;
7 changes: 7 additions & 0 deletions packages/firebase/externs/firebase-app-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,10 @@ firebase.CompleteFn;

/** @typedef {function(): void} */
firebase.Unsubscribe;

/**
* @param {string} name
* @param {string} version
* @param {?string} variant
*/
firebase.registerVersion = function(name, version, variant) {};
7 changes: 6 additions & 1 deletion packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ declare namespace firebase {
* Registers a library's name and version for platform logging purposes.
* @param library Name of 1p or 3p library (e.g. firestore, angularfire)
* @param version Current version of that library.
* @param variant Bundle variant, e.g., node, rn, etc.
*/
function registerVersion(library: string, version: string): void;
function registerVersion(
library: string,
version: string,
variant?: string
): void;

/**
* @hidden
Expand Down
6 changes: 6 additions & 0 deletions packages/firebase/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import { uglify } from 'rollup-plugin-uglify';
import { terser } from 'rollup-plugin-terser';
import json from 'rollup-plugin-json';
import pkg from './package.json';

import appPkg from './app/package.json';
Expand All @@ -33,6 +34,7 @@ const plugins = [
typescriptPlugin({
typescript
}),
json(),
commonjs()
];

Expand Down Expand Up @@ -199,6 +201,7 @@ const completeBuilds = [
typescriptPlugin({
typescript
}),
json(),
commonjs(),
uglify()
]
Expand Down Expand Up @@ -227,6 +230,9 @@ const completeBuilds = [
}
}
}),
json({
preferConst: true
}),
commonjs(),
terser()
]
Expand Down
3 changes: 2 additions & 1 deletion packages/firebase/src/index.cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ https://www.gstatic.com/firebasejs/5.0.0/firebase-<PACKAGE>.js

import '@firebase/polyfill';
import firebase from '../app';
import { name, version } from '../package.json';

import '../auth';
import '../database';
Expand All @@ -39,6 +40,6 @@ import '../performance';
import '../analytics';
import '../remote-config';

firebase.registerVersion('fire-js-all-cdn', firebase.SDK_VERSION);
firebase.registerVersion(name, version, 'cdn');

export default firebase;
3 changes: 2 additions & 1 deletion packages/firebase/src/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
*/

import firebase from '../app';
import { name, version } from '../package.json';

import '../auth';
import '../database';
import '../firestore';
import '../functions';

firebase.registerVersion('fire-js-all-node', firebase.SDK_VERSION);
firebase.registerVersion(name, version, 'node');

export default firebase;
3 changes: 2 additions & 1 deletion packages/firebase/src/index.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import firebase from '@firebase/app';
import '@firebase/performance';
import { name, version } from '../package.json';

firebase.registerVersion('fire-js-all-lite', firebase.SDK_VERSION);
firebase.registerVersion(name, version, 'lite');

export default firebase;
3 changes: 2 additions & 1 deletion packages/firebase/src/index.rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
*/

import firebase from '../app';
import { name, version } from '../package.json';

import '../auth';
import '../database';
import '../storage';

firebase.registerVersion('fire-js-all-rn', firebase.SDK_VERSION);
firebase.registerVersion(name, version, 'rn');

export default firebase;
3 changes: 2 additions & 1 deletion packages/firebase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import 'firebase/<PACKAGE>';
`);

import firebase from '../app';
import { name, version } from '../package.json';

import '../auth';
import '../database';
Expand All @@ -48,6 +49,6 @@ import '../performance';
import '../analytics';
import '../remote-config';

firebase.registerVersion('fire-js-all', firebase.SDK_VERSION);
firebase.registerVersion(name, version);

export default firebase;
3 changes: 3 additions & 0 deletions packages/firestore/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import { configureForFirebase } from './src/platform/config';
import './src/platform_node/node_init';
import { FirebaseNamespace } from '@firebase/app-types';

import { name, version } from './package.json';

export function registerFirestore(instance: FirebaseNamespace): void {
configureForFirebase(instance);
instance.registerVersion(name, version, 'node');
}

registerFirestore(firebase);
Expand Down
Loading

0 comments on commit 33388ae

Please sign in to comment.