Skip to content

Create experiment modularized FM SDK #3822

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 18 commits into from
Dec 21, 2020
Merged
26 changes: 26 additions & 0 deletions packages-exp/messaging-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
}
};
9 changes: 9 additions & 0 deletions packages-exp/messaging-exp/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Directories not needed by end users
/src
test

# Files not needed by end users
gulpfile.js
index.ts
karma.conf.js
tsconfig.json
5 changes: 5 additions & 0 deletions packages-exp/messaging-exp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @firebase/messaging

This is the Firebase Cloud Messaging 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.**
8 changes: 8 additions & 0 deletions packages-exp/messaging-exp/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../config/api-extractor.json",
// Point it to your entry point d.ts file.
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
"dtsRollup": {
"enabled": true
}
}
32 changes: 32 additions & 0 deletions packages-exp/messaging-exp/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @license
* Copyright 2017 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 = [`src/**/*.test.ts`];

module.exports = function (config) {
const karmaConfig = {
...karmaBase,
files,
frameworks: ['mocha']
};

config.set(karmaConfig);
};

module.exports.files = files;
58 changes: 58 additions & 0 deletions packages-exp/messaging-exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@firebase/messaging-exp",
"private": true,
"version": "0.0.800",
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"main": "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' --ignore-path '../../.gitignore'",
"build": "rollup -c && yarn api-report",
"build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build",
"dev": "rollup -c -w",
"test": "run-p test:karma type-check lint ",
"test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test",
"test:ci": "node ../../scripts/run_tests_in_ci.js",
"test:karma": "karma start --single-run",
"test:debug": "karma start --browsers=Chrome --auto-watch",
"prepare": "yarn build",
"api-report": "api-extractor run --local --verbose",
"type-check": "tsc --noEmit"
},
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app-exp": "0.x",
"@firebase/app-types-exp": "0.x"
},
"dependencies": {
"@firebase/component": "0.1.19",
"@firebase/installations": "0.4.17",
"@firebase/messaging-types-exp": "0.0.800",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@firebase/messaging-types-exp": "0.0.800",
"@firebase/messaging-types-exp": "0.0.900",

"@firebase/util": "0.3.2",
"eslint": "^7.3.1",
"idb": "3.0.2",
"npm-run-all": "^4.1.5",
"tslib": "^1.11.1"
},
"devDependencies": {
"rollup": "2.7.6",
"rollup-plugin-typescript2": "0.27.0",
"ts-essentials": "^6.0.7",
"typescript": "3.8.3"
},
"repository": {
"directory": "packages/messaging",
"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"
}
76 changes: 76 additions & 0 deletions packages-exp/messaging-exp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @license
* Copyright 2018 Google Inc.
*
* 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: '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}/`))
}
];

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

const es2017Builds = [
{
input: 'src/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];
94 changes: 94 additions & 0 deletions packages-exp/messaging-exp/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @license
* Copyright 2017 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 { ComponentContainer, Provider } from '@firebase/component';
import { FirebaseApp, _FirebaseService } from '@firebase/app-types-exp';
import {
FirebaseMessaging,
MessagePayload
} from '@firebase/messaging-types-exp';
import { NextFn, Observer, Unsubscribe } from '@firebase/util';

import { FirebaseInternalDependencies } from './interfaces/internal-dependencies';
import { SwController } from './controllers/sw-controller';
import { WindowController } from './controllers/window-controller';
import { _getProvider } from '@firebase/app-exp';
import { extractAppConfig } from './helpers/extract-app-config';

export function getMessaging(app: FirebaseApp): FirebaseMessaging {
const messagingProvider: Provider<'messaging'> = _getProvider(
app,
'messaging'
);

return messagingProvider.getImmediate();
}

export function getToken(
messaging: FirebaseMessaging,
options?: { vapidKey?: string; swReg?: ServiceWorkerRegistration }
): Promise<string> {
return messaging.getToken(options);
}

export function deleteToken(messaging: FirebaseMessaging): Promise<boolean> {
return messaging.deleteToken();
}

export function onMessage(
messaging: FirebaseMessaging,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
return messaging.onMessage(nextOrObserver);
}

export function onBackgroundMessage(
messaging: FirebaseMessaging,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
return messaging.onBackgroundMessage(nextOrObserver);
}

export class MessagingService implements _FirebaseService {
app!: FirebaseApp;
readonly windowController: WindowController | null = null;
readonly swController: SwController | null = null;

constructor(container: ComponentContainer) {
const app = container.getProvider('app-exp').getImmediate();
const appConfig = extractAppConfig(app);
const installations = container.getProvider('installations').getImmediate();
const analyticsProvider = container.getProvider('analytics-internal');

const firebaseDependencies: FirebaseInternalDependencies = {
app,
appConfig,
installations,
analyticsProvider
};

if (self && 'ServiceWorkerGlobalScope' in self) {
this.swController = new SwController(firebaseDependencies);
} else {
this.windowController = new WindowController(firebaseDependencies);
}
}

_delete(): Promise<void> {
throw new Error('Method not implemented.');
}
}
Loading