Skip to content

Commit

Permalink
WIP: Modularize functions (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Jun 20, 2020
1 parent 0b9ef3a commit d470f49
Show file tree
Hide file tree
Showing 29 changed files with 1,882 additions and 4 deletions.
24 changes: 24 additions & 0 deletions common/api-review/functions-exp.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## API Report File for "@firebase/functions-exp"

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

import { FirebaseApp } from '@firebase/app-types-exp';
import { Functions } from '@firebase/functions-types-exp';
import { HttpsCallable } from '@firebase/functions-types-exp';
import { HttpsCallableOptions } from '@firebase/functions-types-exp';

// @public
export function getFunctions(app: FirebaseApp, region?: string): Functions;

// @public
export function httpsCallable(functionsInstance: Functions, name: string, options?: HttpsCallableOptions): HttpsCallable;

// @public
export function useFunctionsEmulator(functionsInstance: Functions, origin: string): void;


// (No @packageDocumentation comment for this package)

```
4 changes: 2 additions & 2 deletions packages-exp/app-exp/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import { name as appName } from '../package.json';
import { name as analyticsName } from '../../../packages/analytics/package.json';
import { name as authName } from '../../../packages/auth/package.json';
import { name as databaseName } from '../../../packages/database/package.json';
import { name as functionsName } from '../../../packages/functions/package.json';
import { name as functionsName } from '../../../packages-exp/functions-exp/package.json';
import { name as installationsName } from '../../../packages/installations/package.json';
import { name as messagingName } from '../../../packages/messaging/package.json';
import { name as performanceName } from '../../../packages/performance/package.json';
import { name as remoteConfigName } from '../../../packages/remote-config/package.json';
import { name as storageName } from '../../../packages/storage/package.json';
import { name as firestoreName } from '../../../packages/firestore/package.json';
import { name as packageName } from '../../../packages/firebase/package.json';
import { name as packageName } from '../../../packages-exp/firebase-exp/package.json';

export const DEFAULT_ENTRY_NAME = '[DEFAULT]';

Expand Down
37 changes: 37 additions & 0 deletions packages-exp/functions-exp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/**
* @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.
*/
const path = require('path');

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
project: 'tsconfig.json',
// to make vscode-eslint work with monorepo
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
tsconfigRootDir: __dirname
},
rules: {
'import/no-extraneous-dependencies': [
'error',
{
'packageDir': [path.resolve(__dirname, '../../'), __dirname],
devDependencies: true
}
]
}
};
5 changes: 5 additions & 0 deletions packages-exp/functions-exp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `@firebase/functions`

This is the Firebase Functions component of the Firebase JS SDK.

**This package is not intended for direct usage, and should only be used via the officially supported [firebase](https://www.npmjs.com/package/firebase) package.**
10 changes: 10 additions & 0 deletions packages-exp/functions-exp/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../config/api-extractor.json",
// Point it to your entry point d.ts file.
"mainEntryPointFilePath": "<projectFolder>/dist/src/index.d.ts",
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
"publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts"
}
}
34 changes: 34 additions & 0 deletions packages-exp/functions-exp/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2017 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.
*/

const karmaBase = require('../../config/karma.base');

const files = [`src/**/*.test.ts`];

module.exports = function(config) {
const karmaConfig = Object.assign({}, karmaBase, {
// files to load into karma
files,
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha']
});

config.set(karmaConfig);
};

module.exports.files = files;
68 changes: 68 additions & 0 deletions packages-exp/functions-exp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "@firebase/functions-exp",
"version": "0.0.800",
"description": "",
"private": true,
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"main": "dist/index.node.cjs.js",
"browser": "dist/index.esm.js",
"module": "dist/index.esm.js",
"esm2017": "dist/index.esm2017.js",
"files": [
"dist"
],
"scripts": {
"lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
"build": "rollup -c && yarn api-report",
"build:deps": "lerna run --scope @firebase/functions-exp --include-dependencies build",
"dev": "rollup -c -w",
"test": "yarn type-check && run-p lint test:browser test:node",
"test:ci": "node ../../scripts/run_tests_in_ci.js",
"type-check": "tsc -p . --noEmit",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"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",
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p test:node",
"prepare": "yarn build",
"api-report": "api-extractor run --local --verbose",
"predoc": "node ../../scripts/exp/remove-exp.js temp",
"doc": "api-documenter markdown --input temp --output docs",
"build:doc": "yarn build && yarn doc"
},
"license": "Apache-2.0",
"peerDependencies": {
"@firebase/app-exp": "0.x",
"@firebase/app-types-exp": "0.x"
},
"devDependencies": {
"@firebase/app-exp": "0.0.800",
"rollup": "2.7.6",
"rollup-plugin-typescript2": "0.27.0",
"typescript": "3.8.3"
},
"repository": {
"directory": "packages/functions",
"type": "git",
"url": "https://github.com/firebase/firebase-js-sdk.git"
},
"bugs": {
"url": "https://github.com/firebase/firebase-js-sdk/issues"
},
"typings": "dist/index.d.ts",
"dependencies": {
"@firebase/component": "0.1.14",
"@firebase/functions-types-exp": "0.0.800",
"@firebase/messaging": "0.6.18",
"@firebase/messaging-types": "0.4.5",
"@firebase/util": "0.2.49",
"isomorphic-fetch": "2.2.1",
"tslib": "1.11.1"
},
"nyc": {
"extension": [
".ts"
],
"reportDir": "./coverage/node"
}
}
92 changes: 92 additions & 0 deletions packages-exp/functions-exp/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @license
* Copyright 2018 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.
*/

import json from 'rollup-plugin-json';
import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import pkg from './package.json';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript
}),
json()
];

const es5Builds = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
/**
* Node.js Build
*/
{
input: 'src/index.node.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
}
}),
json({ preferConst: true })
];

/**
* ES2017 Builds
*/
const es2017Builds = [
{
/**
* Browser Build
*/
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
}
];

export default [...es5Builds, ...es2017Builds];
82 changes: 82 additions & 0 deletions packages-exp/functions-exp/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @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.
*/

import { _getProvider } from '@firebase/app-exp';
import { FirebaseApp } from '@firebase/app-types-exp';
import { FUNCTIONS_TYPE } from './constants';

import { Provider } from '@firebase/component';
import {
Functions,
HttpsCallableOptions,
HttpsCallable
} from '@firebase/functions-types-exp';
import {
FunctionsService,
DEFAULT_REGION,
useFunctionsEmulator as _useFunctionsEmulator,
httpsCallable as _httpsCallable
} from './service';

/**
* Returns a Functions instance for the given app.
* @param app - The FirebaseApp to use.
* @param region - The region the callable functions are located in.
* @public
*/
export function getFunctions(
app: FirebaseApp,
region: string = DEFAULT_REGION
): Functions {
// Dependencies
const functionsProvider: Provider<'functions'> = _getProvider(
app,
FUNCTIONS_TYPE
);
const functionsInstance = functionsProvider.getImmediate({
identifier: region
});
return functionsInstance;
}

/**
* Changes this instance to point to a Cloud Functions emulator running
* locally. See https://firebase.google.com/docs/functions/local-emulator
*
* @param origin - The origin of the local emulator, such as
* "http://localhost:5005".
* @public
*/
export function useFunctionsEmulator(
functionsInstance: Functions,
origin: string
): void {
_useFunctionsEmulator(functionsInstance as FunctionsService, origin);
}

/**
* Returns a reference to the callable https trigger with the given name.
* @param name - The name of the trigger.
* @public
*/
export function httpsCallable(
functionsInstance: Functions,
name: string,
options?: HttpsCallableOptions
): HttpsCallable {
return _httpsCallable(functionsInstance as FunctionsService, name, options);
}

0 comments on commit d470f49

Please sign in to comment.