Skip to content

Commit cb24d72

Browse files
committed
Continue implementation
1 parent fb10816 commit cb24d72

12 files changed

+309
-14
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports */
2+
/**
3+
* @license
4+
* Copyright 2020 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
const path = require('path');
19+
20+
module.exports = {
21+
extends: '../../config/.eslintrc.js',
22+
parserOptions: {
23+
project: 'tsconfig.json',
24+
// to make vscode-eslint work with monorepo
25+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
26+
tsconfigRootDir: __dirname
27+
},
28+
rules: {
29+
'import/no-extraneous-dependencies': [
30+
'error',
31+
{
32+
'packageDir': [path.resolve(__dirname, '../../'), __dirname],
33+
devDependencies: true
34+
}
35+
]
36+
}
37+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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+
const karmaBase = require('../../config/karma.base');
19+
20+
const files = ['test/**/*', 'src/**/*.test.ts'];
21+
22+
module.exports = function (config) {
23+
const karmaConfig = Object.assign({}, karmaBase, {
24+
// files to load into karma
25+
files: files,
26+
// frameworks to use
27+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
28+
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
29+
frameworks: ['mocha']
30+
});
31+
32+
config.set(karmaConfig);
33+
};
34+
35+
module.exports.files = files;

packages-exp/functions-compat/package.json

+23-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
"private": true,
66
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
77
"main": "dist/index.node.cjs.js",
8-
"browser": "dist/index.esm.js",
9-
"module": "dist/index.esm.js",
8+
"browser": "dist/index.esm5.js",
9+
"module": "dist/index.esm5.js",
1010
"esm2017": "dist/index.esm2017.js",
1111
"files": ["dist"],
1212
"license": "Apache-2.0",
1313
"peerDependencies": {
14+
"@firebase/app-compat": "0.x",
1415
"@firebase/app-exp": "0.x",
1516
"@firebase/app-types-exp": "0.x"
1617
},
1718
"devDependencies": {
19+
"@firebase/app-compat": "0.0.800",
1820
"@firebase/app-exp": "0.0.800",
1921
"rollup": "2.26.7",
22+
"rollup-plugin-json": "4.0.0",
2023
"rollup-plugin-typescript2": "0.27.2",
2124
"typescript": "4.0.2"
2225
},
@@ -28,9 +31,26 @@
2831
"bugs": {
2932
"url": "https://github.com/firebase/firebase-js-sdk/issues"
3033
},
31-
"typings": "dist/functions-exp-public.d.ts",
34+
"scripts": {
35+
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
36+
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
37+
"build": "rollup -c",
38+
"build:deps": "lerna run --scope @firebase/functions-compat --include-dependencies build",
39+
"build:release": "rollup -c rollup.config.release.js",
40+
"dev": "rollup -c -w",
41+
"test": "run-p lint test:all",
42+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
43+
"test:all": "run-p test:browser test:node",
44+
"test:browser": "karma start --single-run",
45+
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
46+
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
47+
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p test:node",
48+
"prepare": "yarn build:release"
49+
},
50+
"typings": "dist/functions-compat-public.d.ts",
3251
"dependencies": {
3352
"@firebase/component": "0.1.18",
53+
"@firebase/functions-exp": "0.0.800",
3454
"@firebase/functions-types-exp": "0.0.800",
3555
"@firebase/messaging-types": "0.5.0",
3656
"@firebase/util": "0.3.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 json from 'rollup-plugin-json';
19+
import typescriptPlugin from 'rollup-plugin-typescript2';
20+
import typescript from 'typescript';
21+
import pkg from './package.json';
22+
23+
const deps = Object.keys(
24+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
25+
);
26+
27+
/**
28+
* ES5 Builds
29+
*/
30+
export function getEs5Builds(additionalTypescriptPlugins = {}) {
31+
const es5BuildPlugins = [
32+
typescriptPlugin({
33+
typescript,
34+
abortOnError: false,
35+
...additionalTypescriptPlugins
36+
}),
37+
json()
38+
];
39+
return [
40+
/**
41+
* Browser Builds
42+
*/
43+
{
44+
input: 'src/index.ts',
45+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
46+
plugins: es5BuildPlugins,
47+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
48+
},
49+
/**
50+
* Node.js Build
51+
*/
52+
{
53+
input: 'src/index.node.ts',
54+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
55+
plugins: es5BuildPlugins,
56+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
57+
}
58+
];
59+
}
60+
61+
/**
62+
* ES2017 Builds
63+
*/
64+
export function getEs2017Builds(additionalTypescriptPlugins = {}) {
65+
const es2017BuildPlugins = [
66+
typescriptPlugin({
67+
typescript,
68+
abortOnError: false,
69+
tsconfigOverride: {
70+
compilerOptions: {
71+
target: 'es2017'
72+
}
73+
},
74+
...additionalTypescriptPlugins
75+
}),
76+
json({ preferConst: true })
77+
];
78+
return [
79+
{
80+
/**
81+
* Browser Build
82+
*/
83+
input: 'src/index.ts',
84+
output: {
85+
file: pkg.esm2017,
86+
format: 'es',
87+
sourcemap: true
88+
},
89+
plugins: es2017BuildPlugins,
90+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
91+
}
92+
];
93+
}
94+
95+
export function getAllBuilds(additionalTypescriptPlugins = {}) {
96+
return [
97+
...getEs5Builds(additionalTypescriptPlugins),
98+
...getEs2017Builds(additionalTypescriptPlugins)
99+
];
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 { getAllBuilds } from './rollup.config.base';
19+
20+
// eslint-disable-next-line import/no-default-export
21+
export default getAllBuilds({});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
19+
import { getAllBuilds } from './rollup.config.base';
20+
21+
// eslint-disable-next-line import/no-default-export
22+
export default getAllBuilds({
23+
clean: true,
24+
transformers: [importPathTransformer]
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 { registerVersion } from '@firebase/app-exp';
19+
import { name, version } from '../package.json';
20+
import { registerFunctions } from './register';
21+
22+
registerFunctions();
23+
registerVersion(name, version, 'node');
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
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 { registerVersion } from '@firebase/app-exp';
19+
import { name, version } from '../package.json';
20+
import { registerFunctions } from './register';
21+
22+
registerFunctions();
23+
registerVersion(name, version);

packages-exp/functions-compat/index.ts renamed to packages-exp/functions-compat/src/register.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18+
import firebase from '@firebase/app-compat';
1819
import { _FirebaseNamespace } from '@firebase/app-types/private';
19-
import { registerVersion, _registerComponent } from '@firebase/app-exp';
20-
import { name, version } from './package.json';
20+
import { registerVersion } from '@firebase/app-exp';
21+
import { name, version } from '../package.json';
2122
import { FunctionsService } from './service';
2223
import {
2324
Component,
@@ -39,12 +40,12 @@ const factory: InstanceFactory<'functions'> = (
3940
return new FunctionsService(app as FirebaseApp, region);
4041
};
4142

42-
export function registerFunctions(instance: _FirebaseNamespace): void {
43+
export function registerFunctions(): void {
4344
const namespaceExports = {
4445
// no-inline
4546
Functions: FunctionsService
4647
};
47-
instance.INTERNAL.registerComponent(
48+
(firebase as _FirebaseNamespace).INTERNAL.registerComponent(
4849
new Component('functions', factory, ComponentType.PUBLIC)
4950
.setServiceProps(namespaceExports)
5051
.setMultipleInstances(true)

packages-exp/functions-compat/service.ts renamed to packages-exp/functions-compat/src/service.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ import {
2020
useFunctionsEmulator as useFunctionsEmulatorExp,
2121
getFunctions
2222
} from '@firebase/functions-exp';
23-
import { FirebaseFunctions } from '@firebase/functions-types';
24-
import { HttpsCallableOptions } from '@firebase/functions-types-exp';
23+
import { FirebaseFunctions, HttpsCallable } from '@firebase/functions-types';
24+
import { HttpsCallableOptions, Functions } from '@firebase/functions-types-exp';
2525
import { FirebaseApp } from '@firebase/app-types';
2626

2727
export class FunctionsService implements FirebaseFunctions {
28-
private functionsInstance;
29-
constructor(public app: FirebaseApp, public region: string) {
30-
this.functionsInstance = getFunctions(app);
28+
private functionsInstance: Functions;
29+
constructor(public app: FirebaseApp, public region?: string) {
30+
this.functionsInstance = getFunctions(app, region);
3131
}
32-
httpsCallable(name: string, options: HttpsCallableOptions) {
32+
httpsCallable(name: string, options: HttpsCallableOptions): HttpsCallable {
3333
return httpsCallableExp(this.functionsInstance, name, options);
3434
}
35-
useFunctionsEmulator(origin: string) {
35+
useFunctionsEmulator(origin: string): void {
3636
return useFunctionsEmulatorExp(this.functionsInstance, origin);
3737
}
3838
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../config/tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "dist"
5+
},
6+
"exclude": [
7+
"dist/**/*"
8+
]
9+
}

packages-exp/functions-exp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"devDependencies": {
3838
"@firebase/app-exp": "0.0.800",
3939
"rollup": "2.29.0",
40+
"rollup-plugin-json": "4.0.0",
4041
"rollup-plugin-typescript2": "0.27.3",
4142
"typescript": "4.0.2"
4243
},

0 commit comments

Comments
 (0)