Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

allow for nested functions from firebase #191

Merged
merged 10 commits into from
Mar 1, 2018

Conversation

tinaliang
Copy link
Contributor

@tinaliang tinaliang commented Feb 23, 2018

Companion to firebase/firebase-tools#677.

Fixes firebase/firebase-tools#481

  • Tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@jmdobry
Copy link
Contributor

jmdobry commented Feb 24, 2018

Has some conflicts that need to be resolved.

return this.client.generateUploadUrl(this.config)
.then(([body]) => {
cloudfunction.sourceUploadUrl = body.uploadUrl;
CloudFunction.addLocaldir(cloudfunction, opts.source);

return new Promise((resolve, reject) => {
// Parse the user's code to find the names of the exported functions
if (opts.firebase) {
resolve(name.replace(/\-/g, '.'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're resolving the promise right here, do you also want to add a return statement to avoid the exec call on line 120?

@@ -73,7 +74,12 @@ function main () {

// Require the target module to load the function for invocation
const functionModule = require(localdir);
const handler = functionModule[cloudfunction.entryPoint || name];
const bracketedName = name.split('-');
const nestedFunctionModule = _.reduce(bracketedName, function(funcMod, item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to:

const nestedFunctionModule = bracketedName.reduce((funcMod, item) => funcMod[item], functionModule);

@jmdobry
Copy link
Contributor

jmdobry commented Feb 27, 2018

Are you ready for this to be merged?

@@ -73,7 +74,7 @@ function main () {

// Require the target module to load the function for invocation
const functionModule = require(localdir);
const handler = functionModule[cloudfunction.entryPoint || name];
const handler = _.get(functionModule, cloudfunction.entryPoint, name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should change this to:
const handler = _.get(functionModule, cloudfunction.entryPoint, functionModule[name]);
or
const handler = _.get(functionModule, cloudfunction.entryPoint) || functionModule[name];

@@ -114,6 +114,10 @@ class Controller {

return new Promise((resolve, reject) => {
// Parse the user's code to find the names of the exported functions
if (opts.firebase) {
// If call is coming from Firebase, assume functions have already been parsed
return resolve(name.replace(/\-/g, '.'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you have to do the replace, since the Firebase CLI would have already done the dash to dot substitution during the trigger parsing step. Can replace this line with:
return resolve(name)

But you should test to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI does not do the dot substitution. We could also go with opts.entryPoint here, instead of replacing the dashes with dots in the name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I got confused. What I meant is that it is fine to leave the name with dashes in them. You do not need to put the dots back. When the Firebase CLI deploys functions to the real GCF API, the name of each function stays the "dashed" version, since the API doesn't actually allow dots in the name of functions. So you should still replace this line with: return resolve(name)

@@ -73,7 +74,7 @@ function main () {

// Require the target module to load the function for invocation
const functionModule = require(localdir);
const handler = functionModule[cloudfunction.entryPoint || name];
const handler = _.get(functionModule, cloudfunction.entryPoint, functionModule[name]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this would be cleaner as:
const handler = _.get(functionModule, cloudfunction.entryPoint || name);

@jmdobry
Copy link
Contributor

jmdobry commented Feb 28, 2018

@laurenzlong approval?

@laurenzlong
Copy link
Contributor

Yep.

@jmdobry jmdobry merged commit ab5f65a into googlearchive:master Mar 1, 2018
@vjoao
Copy link

vjoao commented Mar 2, 2018

Is this ready on @latest ?

@tinaliang tinaliang deleted the nested branch March 2, 2018 23:11
@jmdobry
Copy link
Contributor

jmdobry commented Mar 3, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants