Skip to content

Commit b38aa3b

Browse files
committed
create a build pipeline for the modular APIs
1 parent d9c9e1c commit b38aa3b

File tree

6 files changed

+187
-158
lines changed

6 files changed

+187
-158
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@firebase/app/next/internal",
3+
"main": "../../dist/cjs/next/internal.js",
4+
"browser": "../../dist/cjs/next/internal.js",
5+
"module": "../../dist/esm5/next/internal.js",
6+
"esm2017": "../../dist/esm2017/next/internal.js",
7+
"typings": "../../dist/packages/app/src/next/internal.d.ts"
8+
}

packages/app/next/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@firebase/app/next",
3+
"main": "../dist/cjs/next.js",
4+
"browser": "../dist/cjs/next.js",
5+
"module": "../dist/esm5/next.js",
6+
"esm2017": "../dist/esm2017/next.js",
7+
"typings": "../ådist/packages/app/src/next/index.d.ts"
8+
}

packages/app/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "The primary entrypoint to the Firebase JS SDK",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.node.cjs.js",
7-
"browser": "dist/index.cjs.js",
8-
"module": "dist/index.esm.js",
7+
"browser": "dist/cjs/index.js",
8+
"module": "dist/esm5/index.js",
99
"react-native": "dist/index.rn.cjs.js",
10-
"esm2017": "dist/index.esm2017.js",
10+
"esm2017": "dist/esm2017/index.js",
1111
"lite": "dist/index.lite.js",
1212
"lite-esm2017": "dist/index.lite.esm2017.js",
1313
"files": [
@@ -23,7 +23,8 @@
2323
"test:browser": "karma start --single-run",
2424
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
2525
"test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha test/**/*.test.* --opts ../../config/mocha.node.opts",
26-
"prepare": "yarn build"
26+
"prepare": "yarn build",
27+
"compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json"
2728
},
2829
"license": "Apache-2.0",
2930
"dependencies": {

packages/app/rollup.config.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ const es5BuildPlugins = [
3636

3737
const es5Builds = [
3838
{
39-
input: 'index.ts',
39+
input: {
40+
index: 'index.ts',
41+
next: 'src/next/index.ts',
42+
"next/internal": 'src/next/internal.ts'
43+
},
4044
output: [
41-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
42-
{ file: pkg.module, format: 'es', sourcemap: true }
45+
{ dir: 'dist/cjs', format: 'cjs', sourcemap: true },
46+
{ dir: 'dist/esm5', format: 'es', sourcemap: true }
4347
],
4448
plugins: es5BuildPlugins,
4549
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
@@ -101,9 +105,13 @@ const es2017Builds = [
101105
* Browser Builds
102106
*/
103107
{
104-
input: 'index.ts',
108+
input: {
109+
index: 'index.ts',
110+
next: 'src/next/index.ts',
111+
"next/internal": 'src/next/internal.ts'
112+
},
105113
output: {
106-
file: pkg.esm2017,
114+
dir: 'dist/esm2017',
107115
format: 'es',
108116
sourcemap: true
109117
},
@@ -123,3 +131,4 @@ const es2017Builds = [
123131
];
124132

125133
export default [...es5Builds, ...es2017Builds];
134+
// export default [...es2017Builds];

packages/app/src/next/apis.ts

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {
19+
FirebaseAppNext,
20+
FirebaseOptionsNext,
21+
FirebaseAppConfigNext,
22+
FirebaseAppInternalNext
23+
} from './types';
24+
import { DEFAULT_ENTRY_NAME, PLATFORM_LOG_STRING } from '../constants';
25+
import { ERROR_FACTORY, AppError } from '../errors';
26+
import {
27+
ComponentContainer,
28+
Component,
29+
Name,
30+
ComponentType
31+
} from '@firebase/component';
32+
import { version } from '../../../firebase/package.json';
33+
import { FirebaseAppImplNext } from './firebaseApp';
34+
import { apps, components, registerComponent } from './internal';
35+
import { logger } from '../logger';
36+
37+
export const SDK_VERSION = version;
38+
39+
// TODO: add tests
40+
export function initializeApp(
41+
options: FirebaseOptionsNext,
42+
config?: FirebaseAppConfigNext
43+
): FirebaseAppNext;
44+
export function initializeApp(
45+
options: FirebaseOptionsNext,
46+
name?: string
47+
): FirebaseAppNext;
48+
export function initializeApp(
49+
options: FirebaseOptionsNext,
50+
rawConfig = {}
51+
): FirebaseAppNext {
52+
if (typeof rawConfig !== 'object') {
53+
const name = rawConfig;
54+
rawConfig = { name };
55+
}
56+
57+
const config: Required<FirebaseAppConfigNext> = {
58+
name: DEFAULT_ENTRY_NAME,
59+
automaticDataCollectionEnabled: false,
60+
...rawConfig
61+
};
62+
const name = config.name;
63+
64+
if (typeof name !== 'string' || !name) {
65+
throw ERROR_FACTORY.create(AppError.BAD_APP_NAME, {
66+
appName: String(name)
67+
});
68+
}
69+
70+
if (apps.has(name)) {
71+
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { appName: name });
72+
}
73+
74+
const container = new ComponentContainer(name);
75+
for (const component of components.values()) {
76+
container.addComponent(component);
77+
}
78+
79+
const newApp = new FirebaseAppImplNext(options, config, container);
80+
81+
apps.set(name, newApp);
82+
83+
return newApp;
84+
}
85+
86+
export function getApp(name: string = DEFAULT_ENTRY_NAME): FirebaseAppNext {
87+
const app = apps.get(name);
88+
if (!app) {
89+
throw ERROR_FACTORY.create(AppError.NO_APP, { appName: name });
90+
}
91+
92+
return app;
93+
}
94+
95+
export function getApps(): FirebaseAppNext[] {
96+
return Array.from(apps.values());
97+
}
98+
99+
export function deleteApp(app: FirebaseAppNext): Promise<void> {
100+
const name = app.name;
101+
if (apps.has(name)) {
102+
apps.delete(name);
103+
(app as FirebaseAppInternalNext).isDeleted = true;
104+
// TODO: what to do with other SDKs?
105+
}
106+
107+
return Promise.resolve();
108+
}
109+
110+
export function registerVersion(
111+
libraryKeyOrName: string,
112+
version: string,
113+
variant?: string
114+
): void {
115+
// TODO: We can use this check to whitelist strings when/if we set up
116+
// a good whitelist system.
117+
let library = PLATFORM_LOG_STRING[libraryKeyOrName] ?? libraryKeyOrName;
118+
if (variant) {
119+
library += `-${variant}`;
120+
}
121+
const libraryMismatch = library.match(/\s|\//);
122+
const versionMismatch = version.match(/\s|\//);
123+
if (libraryMismatch || versionMismatch) {
124+
const warning = [
125+
`Unable to register library "${library}" with version "${version}":`
126+
];
127+
if (libraryMismatch) {
128+
warning.push(
129+
`library name "${library}" contains illegal characters (whitespace or "/")`
130+
);
131+
}
132+
if (libraryMismatch && versionMismatch) {
133+
warning.push('and');
134+
}
135+
if (versionMismatch) {
136+
warning.push(
137+
`version name "${version}" contains illegal characters (whitespace or "/")`
138+
);
139+
}
140+
logger.warn(warning.join(' '));
141+
return;
142+
}
143+
registerComponent(
144+
new Component(
145+
`${library}-version` as Name,
146+
() => ({ library, version }),
147+
ComponentType.VERSION
148+
)
149+
);
150+
}
151+

packages/app/src/next/index.ts

Lines changed: 1 addition & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1 @@
1-
/**
2-
* @license
3-
* Copyright 2019 Google Inc.
4-
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
18-
import {
19-
FirebaseAppNext,
20-
FirebaseOptionsNext,
21-
FirebaseAppConfigNext,
22-
FirebaseAppInternalNext
23-
} from './types';
24-
import { DEFAULT_ENTRY_NAME, PLATFORM_LOG_STRING } from '../constants';
25-
import { ERROR_FACTORY, AppError } from '../errors';
26-
import {
27-
ComponentContainer,
28-
Component,
29-
Name,
30-
ComponentType
31-
} from '@firebase/component';
32-
import { version } from '../../../firebase/package.json';
33-
import { FirebaseAppImplNext } from './firebaseApp';
34-
import { apps, components, registerComponent } from './internal';
35-
import { logger } from '../logger';
36-
37-
export const SDK_VERSION = version;
38-
39-
export function initializeApp(
40-
options: FirebaseOptionsNext,
41-
config?: FirebaseAppConfigNext
42-
): FirebaseAppNext;
43-
export function initializeApp(
44-
options: FirebaseOptionsNext,
45-
name?: string
46-
): FirebaseAppNext;
47-
export function initializeApp(
48-
options: FirebaseOptionsNext,
49-
rawConfig = {}
50-
): FirebaseAppNext {
51-
if (typeof rawConfig !== 'object') {
52-
const name = rawConfig;
53-
rawConfig = { name };
54-
}
55-
56-
const config: Required<FirebaseAppConfigNext> = {
57-
name: DEFAULT_ENTRY_NAME,
58-
automaticDataCollectionEnabled: false,
59-
...rawConfig
60-
};
61-
const name = config.name;
62-
63-
if (typeof name !== 'string' || !name) {
64-
throw ERROR_FACTORY.create(AppError.BAD_APP_NAME, {
65-
appName: String(name)
66-
});
67-
}
68-
69-
if (apps.has(name)) {
70-
throw ERROR_FACTORY.create(AppError.DUPLICATE_APP, { appName: name });
71-
}
72-
73-
const container = new ComponentContainer(name);
74-
for (const component of components.values()) {
75-
container.addComponent(component);
76-
}
77-
78-
const newApp = new FirebaseAppImplNext(options, config, container);
79-
80-
apps.set(name, newApp);
81-
82-
return newApp;
83-
}
84-
85-
export function getApp(name: string = DEFAULT_ENTRY_NAME): FirebaseAppNext {
86-
const app = apps.get(name);
87-
if (!app) {
88-
throw ERROR_FACTORY.create(AppError.NO_APP, { appName: name });
89-
}
90-
91-
return app;
92-
}
93-
94-
export function getApps(): FirebaseAppNext[] {
95-
return Array.from(apps.values());
96-
}
97-
98-
export function deleteApp(app: FirebaseAppNext): Promise<void> {
99-
const name = app.name;
100-
if (apps.has(name)) {
101-
apps.delete(name);
102-
(app as FirebaseAppInternalNext).isDeleted = true;
103-
// TODO: what to do with other SDKs?
104-
}
105-
106-
return Promise.resolve();
107-
}
108-
109-
export function registerVersion(
110-
libraryKeyOrName: string,
111-
version: string,
112-
variant?: string
113-
): void {
114-
// TODO: We can use this check to whitelist strings when/if we set up
115-
// a good whitelist system.
116-
let library = PLATFORM_LOG_STRING[libraryKeyOrName] ?? libraryKeyOrName;
117-
if (variant) {
118-
library += `-${variant}`;
119-
}
120-
const libraryMismatch = library.match(/\s|\//);
121-
const versionMismatch = version.match(/\s|\//);
122-
if (libraryMismatch || versionMismatch) {
123-
const warning = [
124-
`Unable to register library "${library}" with version "${version}":`
125-
];
126-
if (libraryMismatch) {
127-
warning.push(
128-
`library name "${library}" contains illegal characters (whitespace or "/")`
129-
);
130-
}
131-
if (libraryMismatch && versionMismatch) {
132-
warning.push('and');
133-
}
134-
if (versionMismatch) {
135-
warning.push(
136-
`version name "${version}" contains illegal characters (whitespace or "/")`
137-
);
138-
}
139-
logger.warn(warning.join(' '));
140-
return;
141-
}
142-
registerComponent(
143-
new Component(
144-
`${library}-version` as Name,
145-
() => ({ library, version }),
146-
ComponentType.VERSION
147-
)
148-
);
149-
}
1+
export * from './apis';

0 commit comments

Comments
 (0)