Skip to content

Add entry point firebase/messaging/sw #4938

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 4 commits into from
May 25, 2021
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
9 changes: 6 additions & 3 deletions common/api-review/messaging-exp.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export type _FirebaseMessagingName = 'messaging';
export function getMessaging(app?: FirebaseApp): FirebaseMessaging;

// @public
export function getToken(messaging: FirebaseMessaging, options?: {
vapidKey?: string;
export function getToken(messaging: FirebaseMessaging, options?: GetTokenOptions): Promise<string>;

// @public
export interface GetTokenOptions {
swReg?: ServiceWorkerRegistration;
}): Promise<string>;
vapidKey?: string;
}

// @public
export function isSupported(): Promise<boolean>;
Expand Down
56 changes: 56 additions & 0 deletions common/api-review/messaging-exp.sw.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## API Report File for "@firebase/messaging-exp/sw"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import { FirebaseApp } from '@firebase/app-exp';
import { NextFn } from '@firebase/util';
import { Observer } from '@firebase/util';
import { Unsubscribe } from '@firebase/util';

// @public
export interface FcmOptions {
analyticsLabel?: string;
link?: string;
}

// @public
export interface FirebaseMessaging {
}

// @public
export function getMessaging(app?: FirebaseApp): FirebaseMessaging;

// @public
export function isSupported(): Promise<boolean>;

// @public
export interface MessagePayload {
collapseKey: string;
data?: {
[key: string]: string;
};
fcmOptions?: FcmOptions;
from: string;
notification?: NotificationPayload;
}

export { NextFn }

// @public
export interface NotificationPayload {
body?: string;
image?: string;
title?: string;
}

export { Observer }

// @public
export function onBackgroundMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;

export { Unsubscribe }


```
8 changes: 8 additions & 0 deletions packages-exp/firebase-exp/messaging/sw/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "firebase-exp/messaging/sw",
"main": "dist/index.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"typings": "dist/messaging/sw/index.d.ts"
}

5 changes: 3 additions & 2 deletions packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"scripts": {
"build": "rollup -c && gulp firebase-js && yarn build:compat",
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat:release",
"build": "rollup -c && yarn build:compat",
"build:release": "rollup -c rollup.config.release.js && yarn build:compat:release",
"build:compat": "rollup -c compat/rollup.config.js",
"build:compat:release": "rollup -c compat/rollup.config.release.js",
"dev": "rollup -c -w",
Expand Down Expand Up @@ -167,6 +167,7 @@
"performance",
"remote-config",
"messaging",
"messaging/sw",
"database"
]
}
124 changes: 0 additions & 124 deletions packages-exp/firebase-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,14 @@ import resolveModule from '@rollup/plugin-node-resolve';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'typescript';
import { uglify } from 'rollup-plugin-uglify';

const external = Object.keys(pkg.dependencies || {});

/**
* Global UMD Build
*/
const GLOBAL_NAME = 'firebase';

function createUmdOutputConfig(output, componentName) {
return {
file: output,
format: 'umd',
sourcemap: true,
extend: true,
name: `${GLOBAL_NAME}.${camelize(componentName)}`,
globals: {
'@firebase/app-exp': `${GLOBAL_NAME}.app`
},

/**
* use iife to avoid below error in the old Safari browser
* SyntaxError: Functions cannot be declared in a nested block in strict mode
* https://github.com/firebase/firebase-js-sdk/issues/1228
*
*/
intro: `
try {
(function() {`,
outro: `
}).apply(this, arguments);
} catch(err) {
console.error(err);
throw new Error(
'Cannot instantiate ${output} - ' +
'be sure to load firebase-app.js first.'
);
}`
};
}

function camelize(str) {
const arr = str.split('-');
const capital = arr.map((item, index) =>
index > 0
? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
: item.toLowerCase()
);
return capital.join('');
}

const plugins = [sourcemaps(), resolveModule(), json(), commonjs()];

const typescriptPlugin = rollupTypescriptPlugin({
typescript
});

const typescriptPluginUMD = rollupTypescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
declaration: false
}
}
});

/**
* Individual Component Builds
*/
Expand All @@ -105,19 +47,6 @@ const appBuilds = [
],
plugins: [...plugins, typescriptPlugin],
external
},
/**
* App UMD Builds
*/
{
input: 'app/index.cdn.ts',
output: {
file: 'firebase-app.js',
sourcemap: true,
format: 'umd',
name: `${GLOBAL_NAME}.app`
},
plugins: [...plugins, typescriptPluginUMD, uglify()]
}
];

Expand All @@ -126,50 +55,6 @@ const componentBuilds = pkg.components
.filter(component => component !== 'app')
.map(component => {
const pkg = require(`./${component}/package.json`);
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
// Otherwise, we will create a directory with '/' in the name.
const componentName = component.replace('/', '-');

if (component === 'messaging') {
return [
{
input: `${component}/index.ts`,
output: [
{
file: resolve(component, pkg.main),
format: 'cjs',
sourcemap: true
},
{
file: resolve(component, pkg.module),
format: 'es',
sourcemap: true
}
],
plugins: [...plugins, typescriptPlugin],
external
},
{
input: `${component}/index.ts`,
output: createUmdOutputConfig(
`firebase-${componentName}.js`,
componentName
),
plugins: [...plugins, typescriptPluginUMD, uglify()],
external: ['@firebase/app-exp']
},
{
input: `${component}/index.sw.ts`,
output: createUmdOutputConfig(
`firebase-${componentName}-sw.js`,
componentName
),
plugins: [...plugins, typescriptPluginUMD, uglify()],
external: ['@firebase/app-exp']
}
];
}

return [
{
input: `${component}/index.ts`,
Expand All @@ -187,15 +72,6 @@ const componentBuilds = pkg.components
],
plugins: [...plugins, typescriptPlugin],
external
},
{
input: `${component}/index.ts`,
output: createUmdOutputConfig(
`firebase-${componentName}.js`,
componentName
),
plugins: [...plugins, typescriptPluginUMD, uglify()],
external: ['@firebase/app-exp']
}
];
})
Expand Down
Loading