Skip to content

Create FM CDN build #4264

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 16 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 12 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
18 changes: 18 additions & 0 deletions packages-exp/firebase-exp/messaging/index.sw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @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.
*/

export { onBackgroundMessage, getMessaging } from '@firebase/messaging-exp/sw';
1 change: 1 addition & 0 deletions packages-exp/firebase-exp/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from '@firebase/messaging-exp';
1 change: 0 additions & 1 deletion packages-exp/firebase-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@firebase/performance-exp": "0.0.900",
"@firebase/remote-config-exp": "0.0.900",
"@firebase/messaging-exp": "0.0.900"

},
"devDependencies": {
"rollup": "2.33.2",
Expand Down
51 changes: 46 additions & 5 deletions packages-exp/firebase-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
* limitations under the License.
*/

import appPkg from './app/package.json';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import pkg from './package.json';
import { resolve } from 'path';
import resolveModule from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import sourcemaps from 'rollup-plugin-sourcemaps';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'typescript';
import { uglify } from 'rollup-plugin-uglify';
import json from '@rollup/plugin-json';
import pkg from './package.json';
import appPkg from './app/package.json';

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

Expand Down Expand Up @@ -129,6 +129,47 @@ const componentBuilds = pkg.components
// 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 Down
84 changes: 77 additions & 7 deletions packages-exp/firebase-exp/rollup.config.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* limitations under the License.
*/

import alias from '@rollup/plugin-alias';
import appPkg from './app/package.json';
import commonjs from '@rollup/plugin-commonjs';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
import json from '@rollup/plugin-json';
import pkg from './package.json';
import { resolve } from 'path';
import resolveModule from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import sourcemaps from 'rollup-plugin-sourcemaps';
import rollupTypescriptPlugin from 'rollup-plugin-typescript2';
import alias from '@rollup/plugin-alias';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'typescript';
import { uglify } from 'rollup-plugin-uglify';
import json from '@rollup/plugin-json';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
import pkg from './package.json';
import appPkg from './app/package.json';

// remove -exp from dependencies name
const deps = Object.keys(pkg.dependencies || {}).map(name =>
Expand Down Expand Up @@ -125,6 +125,76 @@ const componentBuilds = pkg.components
// 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: id =>
deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
{
input: `${component}/index.ts`,
output: createUmdOutputConfig(
`firebase-${componentName}.js`,
componentName
),
plugins: [
...plugins,
typescriptPluginUMD,
/**
* Hack to bundle @firebase/installations-exp
*/
alias({
entries: [
{
find: '@firebase/installations',
replacement: '@firebase/installations-exp'
}
]
})
],
external: ['@firebase/app']
},
{
input: `${component}/index.sw.ts`,
output: createUmdOutputConfig(
`firebase-${componentName}-sw.js`,
componentName
),
plugins: [
...plugins,
typescriptPluginUMD,
/**
* Hack to bundle @firebase/installations-exp
*/
alias({
entries: [
{
find: '@firebase/installations',
replacement: '@firebase/installations-exp'
}
]
})
],
external: ['@firebase/app']
}
];
}

return [
{
input: `${component}/index.ts`,
Expand Down
8 changes: 4 additions & 4 deletions packages-exp/messaging-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"sw": "dist/index.sw.esm5.js",
"typings": "dist/index.d.ts",
"sw": "dist/index.sw.esm2017.js",
"files": [
"dist"
],
Expand Down Expand Up @@ -52,6 +53,5 @@
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/index.d.ts"
}
}
}
17 changes: 8 additions & 9 deletions packages-exp/messaging-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const es5BuildPlugins = [
];

const es5Builds = [
// window builds
{
input: 'src/index.ts',
output: [
Expand All @@ -44,14 +43,6 @@ const es5Builds = [
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},

// sw builds
{
input: 'src/index.sw.ts',
output: [{ file: pkg.sw, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

Expand Down Expand Up @@ -80,6 +71,14 @@ const es2017Builds = [
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},

// sw builds
{
input: 'src/index.sw.ts',
output: { file: pkg.sw, format: 'es', sourcemap: true },
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

Expand Down
24 changes: 13 additions & 11 deletions packages-exp/messaging-exp/rollup.config.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const es5BuildPlugins = [
];

const es5Builds = [
// window builds
{
input: 'src/index.ts',
output: [
Expand All @@ -48,17 +47,9 @@ const es5Builds = [
],
plugins: es5BuildPlugins,
treeshake: {
moduleSideEffects: false
moduleSideEffects: (id, external) => id === '@firebase/installations'
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},

// sw builds
{
input: 'src/index.sw.ts',
output: [{ file: pkg.sw, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

Expand Down Expand Up @@ -90,9 +81,20 @@ const es2017Builds = [
},
plugins: es2017BuildPlugins,
treeshake: {
moduleSideEffects: false
moduleSideEffects: (id, external) => id === '@firebase/installations'
},
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},

// sw builds
{
input: 'src/index.sw.ts',
output: { file: pkg.sw, format: 'es', sourcemap: true },
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: (id, external) => id === '@firebase/installations'
}
}
];

Expand Down
2 changes: 1 addition & 1 deletion packages-exp/messaging-exp/src/api/onBackgroundMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function onBackgroundMessage(
messaging: MessagingService,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
): Unsubscribe {
if (!!navigator) {
if (self.document !== undefined) {
throw ERROR_FACTORY.create(ErrorCode.AVAILABLE_IN_SW);
}

Expand Down
1 change: 1 addition & 0 deletions packages-exp/messaging-exp/src/index.sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { FirebaseMessaging } from '@firebase/messaging-types-exp';
import { registerMessaging } from './helpers/register';
import '@firebase/installations-exp';

export { onBackgroundMessage, getMessaging } from './api';

Expand Down
1 change: 1 addition & 0 deletions packages-exp/messaging-exp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { FirebaseMessaging } from '@firebase/messaging-types-exp';
import { registerMessaging } from './helpers/register';
import '@firebase/installations-exp';

export { getToken, deleteToken, onMessage, getMessaging } from './api';

Expand Down
3 changes: 1 addition & 2 deletions packages-exp/messaging-exp/src/internals/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { SubscriptionOptions, TokenDetails } from '../interfaces/token-details';

import { AppConfig } from '../interfaces/app-config';
import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
import { getToken } from '@firebase/installations-exp';

export interface ApiResponse {
token?: string;
Expand Down Expand Up @@ -155,7 +154,7 @@ async function getHeaders({
appConfig,
installations
}: FirebaseInternalDependencies): Promise<Headers> {
const authToken = await getToken(installations);
const authToken = await installations.getToken();

return new Headers({
'Content-Type': 'application/json',
Expand Down
12 changes: 12 additions & 0 deletions packages-exp/messaging-exp/sw/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@firebase/messaging-exp",
"private": true,
"version": "0.0.900",
"description": "",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"module": "../dist/index.sw.esm2017.js",
"typings": "../dist/index.sw.d.ts",
"files": [
"dist"
]
}