Skip to content

Commit 7f950c9

Browse files
authored
Add entry point firebase/messaging/sw (#4938)
* generate reports for the sw entry point * remove unneeded scripts * add entry point firebase/messaging/sw * update verbiage
1 parent 8296730 commit 7f950c9

File tree

12 files changed

+128
-309
lines changed

12 files changed

+128
-309
lines changed

common/api-review/messaging-exp.api.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ export type _FirebaseMessagingName = 'messaging';
2929
export function getMessaging(app?: FirebaseApp): FirebaseMessaging;
3030

3131
// @public
32-
export function getToken(messaging: FirebaseMessaging, options?: {
33-
vapidKey?: string;
32+
export function getToken(messaging: FirebaseMessaging, options?: GetTokenOptions): Promise<string>;
33+
34+
// @public
35+
export interface GetTokenOptions {
3436
swReg?: ServiceWorkerRegistration;
35-
}): Promise<string>;
37+
vapidKey?: string;
38+
}
3639

3740
// @public
3841
export function isSupported(): Promise<boolean>;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## API Report File for "@firebase/messaging-exp/sw"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { FirebaseApp } from '@firebase/app-exp';
8+
import { NextFn } from '@firebase/util';
9+
import { Observer } from '@firebase/util';
10+
import { Unsubscribe } from '@firebase/util';
11+
12+
// @public
13+
export interface FcmOptions {
14+
analyticsLabel?: string;
15+
link?: string;
16+
}
17+
18+
// @public
19+
export interface FirebaseMessaging {
20+
}
21+
22+
// @public
23+
export function getMessaging(app?: FirebaseApp): FirebaseMessaging;
24+
25+
// @public
26+
export function isSupported(): Promise<boolean>;
27+
28+
// @public
29+
export interface MessagePayload {
30+
collapseKey: string;
31+
data?: {
32+
[key: string]: string;
33+
};
34+
fcmOptions?: FcmOptions;
35+
from: string;
36+
notification?: NotificationPayload;
37+
}
38+
39+
export { NextFn }
40+
41+
// @public
42+
export interface NotificationPayload {
43+
body?: string;
44+
image?: string;
45+
title?: string;
46+
}
47+
48+
export { Observer }
49+
50+
// @public
51+
export function onBackgroundMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
52+
53+
export { Unsubscribe }
54+
55+
56+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "firebase-exp/messaging/sw",
3+
"main": "dist/index.cjs.js",
4+
"browser": "dist/index.esm.js",
5+
"module": "dist/index.esm.js",
6+
"typings": "dist/messaging/sw/index.d.ts"
7+
}
8+

packages-exp/firebase-exp/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114
"url": "https://github.com/firebase/firebase-js-sdk.git"
115115
},
116116
"scripts": {
117-
"build": "rollup -c && gulp firebase-js && yarn build:compat",
118-
"build:release": "rollup -c rollup.config.release.js && gulp firebase-js && yarn build:compat:release",
117+
"build": "rollup -c && yarn build:compat",
118+
"build:release": "rollup -c rollup.config.release.js && yarn build:compat:release",
119119
"build:compat": "rollup -c compat/rollup.config.js",
120120
"build:compat:release": "rollup -c compat/rollup.config.release.js",
121121
"dev": "rollup -c -w",
@@ -167,6 +167,7 @@
167167
"performance",
168168
"remote-config",
169169
"messaging",
170+
"messaging/sw",
170171
"database"
171172
]
172173
}

packages-exp/firebase-exp/rollup.config.js

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,14 @@ import resolveModule from '@rollup/plugin-node-resolve';
2424
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
2525
import sourcemaps from 'rollup-plugin-sourcemaps';
2626
import typescript from 'typescript';
27-
import { uglify } from 'rollup-plugin-uglify';
2827

2928
const external = Object.keys(pkg.dependencies || {});
30-
31-
/**
32-
* Global UMD Build
33-
*/
34-
const GLOBAL_NAME = 'firebase';
35-
36-
function createUmdOutputConfig(output, componentName) {
37-
return {
38-
file: output,
39-
format: 'umd',
40-
sourcemap: true,
41-
extend: true,
42-
name: `${GLOBAL_NAME}.${camelize(componentName)}`,
43-
globals: {
44-
'@firebase/app-exp': `${GLOBAL_NAME}.app`
45-
},
46-
47-
/**
48-
* use iife to avoid below error in the old Safari browser
49-
* SyntaxError: Functions cannot be declared in a nested block in strict mode
50-
* https://github.com/firebase/firebase-js-sdk/issues/1228
51-
*
52-
*/
53-
intro: `
54-
try {
55-
(function() {`,
56-
outro: `
57-
}).apply(this, arguments);
58-
} catch(err) {
59-
console.error(err);
60-
throw new Error(
61-
'Cannot instantiate ${output} - ' +
62-
'be sure to load firebase-app.js first.'
63-
);
64-
}`
65-
};
66-
}
67-
68-
function camelize(str) {
69-
const arr = str.split('-');
70-
const capital = arr.map((item, index) =>
71-
index > 0
72-
? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
73-
: item.toLowerCase()
74-
);
75-
return capital.join('');
76-
}
77-
7829
const plugins = [sourcemaps(), resolveModule(), json(), commonjs()];
7930

8031
const typescriptPlugin = rollupTypescriptPlugin({
8132
typescript
8233
});
8334

84-
const typescriptPluginUMD = rollupTypescriptPlugin({
85-
typescript,
86-
tsconfigOverride: {
87-
compilerOptions: {
88-
declaration: false
89-
}
90-
}
91-
});
92-
9335
/**
9436
* Individual Component Builds
9537
*/
@@ -105,19 +47,6 @@ const appBuilds = [
10547
],
10648
plugins: [...plugins, typescriptPlugin],
10749
external
108-
},
109-
/**
110-
* App UMD Builds
111-
*/
112-
{
113-
input: 'app/index.cdn.ts',
114-
output: {
115-
file: 'firebase-app.js',
116-
sourcemap: true,
117-
format: 'umd',
118-
name: `${GLOBAL_NAME}.app`
119-
},
120-
plugins: [...plugins, typescriptPluginUMD, uglify()]
12150
}
12251
];
12352

@@ -126,50 +55,6 @@ const componentBuilds = pkg.components
12655
.filter(component => component !== 'app')
12756
.map(component => {
12857
const pkg = require(`./${component}/package.json`);
129-
// It is needed for handling sub modules, for example firestore/lite which should produce firebase-firestore-lite.js
130-
// Otherwise, we will create a directory with '/' in the name.
131-
const componentName = component.replace('/', '-');
132-
133-
if (component === 'messaging') {
134-
return [
135-
{
136-
input: `${component}/index.ts`,
137-
output: [
138-
{
139-
file: resolve(component, pkg.main),
140-
format: 'cjs',
141-
sourcemap: true
142-
},
143-
{
144-
file: resolve(component, pkg.module),
145-
format: 'es',
146-
sourcemap: true
147-
}
148-
],
149-
plugins: [...plugins, typescriptPlugin],
150-
external
151-
},
152-
{
153-
input: `${component}/index.ts`,
154-
output: createUmdOutputConfig(
155-
`firebase-${componentName}.js`,
156-
componentName
157-
),
158-
plugins: [...plugins, typescriptPluginUMD, uglify()],
159-
external: ['@firebase/app-exp']
160-
},
161-
{
162-
input: `${component}/index.sw.ts`,
163-
output: createUmdOutputConfig(
164-
`firebase-${componentName}-sw.js`,
165-
componentName
166-
),
167-
plugins: [...plugins, typescriptPluginUMD, uglify()],
168-
external: ['@firebase/app-exp']
169-
}
170-
];
171-
}
172-
17358
return [
17459
{
17560
input: `${component}/index.ts`,
@@ -187,15 +72,6 @@ const componentBuilds = pkg.components
18772
],
18873
plugins: [...plugins, typescriptPlugin],
18974
external
190-
},
191-
{
192-
input: `${component}/index.ts`,
193-
output: createUmdOutputConfig(
194-
`firebase-${componentName}.js`,
195-
componentName
196-
),
197-
plugins: [...plugins, typescriptPluginUMD, uglify()],
198-
external: ['@firebase/app-exp']
19975
}
20076
];
20177
})

0 commit comments

Comments
 (0)