Skip to content
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

refactor: Remove bluebird from lib/classes #8943

Merged
merged 1 commit into from
Feb 19, 2021

Conversation

juanjoDiaz
Copy link
Contributor

Addresses: #7171

@pgrzesik
Copy link
Contributor

Hello @juanjoDiaz 👋 Thanks a lot for proposed changes. Before continuing with review, I have a question to @medikoo as I know you're currently working on refactoring variables resolution as a part of #8364 - is the refactor to Variables.js conflicting with your current work? Does it make sense to accept refactorings to that part at the moment or it's going to be removed soon anyway? Thanks 🙇

@medikoo
Copy link
Contributor

medikoo commented Feb 15, 2021

@medikoo as I know you're currently working on refactoring variables resolution as a part of #8364 - is the refactor to Variables.js conflicting with your current work?

@pgrzesik thanks for asking. I did not touch any part of old implementation. It's that new parser will simply take over, and older will only eventually serve as fallback, in case a new parser will report errors.

@juanjoDiaz juanjoDiaz force-pushed the remove_bluebird branch 3 times, most recently from c9b6df0 to 93fac95 Compare February 15, 2021 19:27
@codecov
Copy link

codecov bot commented Feb 15, 2021

Codecov Report

Merging #8943 (98d8928) into master (1e46dad) will decrease coverage by 0.00%.
The diff coverage is 99.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8943      +/-   ##
==========================================
- Coverage   87.69%   87.68%   -0.01%     
==========================================
  Files         268      268              
  Lines       10050    10045       -5     
==========================================
- Hits         8813     8808       -5     
  Misses       1237     1237              
Impacted Files Coverage Δ
lib/classes/Variables.js 99.72% <99.20%> (-0.01%) ⬇️
lib/classes/PluginManager.js 97.25% <100.00%> (+0.02%) ⬆️
lib/classes/Utils.js 95.65% <100.00%> (-0.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e46dad...0ff3ffb. Read the comment docs.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Hello @juanjoDiaz 👋 Thanks a lot - in general it looks good, but according to the original issue, in the first step we should address marking all promise-returning functions as async - here we have more refactoring, but not all promise-returning functions are marked as async. We also have a related PR that addreses that first part for Variables.js here: #8942

To keep things in order, I believe the above PR should be resolved first and then we can continue with that refactoring. What is your opinion here @juanjoDiaz ?

@juanjoDiaz
Copy link
Contributor Author

Oh I haven't seen that other PR.

I think that it makes sense to use async when you also use await.
I could review this PR and add async to any function that returns a promise but doesn't use async.

Apart from removing BbBluebird, this PR remove unnecessary promise wrappers and replace then.catch chains with async/await-style code.

If you rather waiting for the other PR and then check this, that's also fine.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

I agree that it makes sense - the problem with these changes is that they often can introduce bugs that are very hard to catch during review process (we already had a few of those caused by async/await refactors), especially when the scope of the PR is bigger, that's why we suggested to migrate it gradually by first marking functions as async, removing unnecessary promise wrapers and only then getting rid of all BbPromise usages. But to not re-do the work you already did I think we should wrap up the changes as a part of this PR - the only thing that would be good here is if you could review the methods that are returning a promise and mark them as async if they're not marked as such yet. I also added a few comments related to Promise.resolve usage that I think we could get rid of

@@ -607,7 +604,7 @@ class Variables {
if (requestedSlsVar === 'instanceId') {
valueToPopulate = this.serverless.instanceId;
}
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

@@ -619,23 +616,23 @@ class Variables {
} else {
valueToPopulate = process.env;
}
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

}

getValueFromString(variableString) {
// eslint-disable-line class-methods-use-this
const valueToPopulate = variableString.replace(/^['"]|['"]$/g, '');
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

}

getValueFromBool(variableString) {
const valueToPopulate = variableString === 'true';
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

}

getValueFromInt(variableString) {
const valueToPopulate = parseInt(variableString, 10);
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

@@ -646,7 +643,7 @@ class Variables {
} else {
valueToPopulate = this.options;
}
return BbPromise.resolve(valueToPopulate);
return Promise.resolve(valueToPopulate);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just mark it as async and return the value?

return BbPromise.reduce(
deepProperties,
(reducedValueParam, subProperty) => {
return Promise.resolve(
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's mark the function as async instead of using Promise.resolve construct

@juanjoDiaz
Copy link
Contributor Author

I've marked all the functions returning promises as async.

I have the feeling that quite a few of the async functions in Variables.js are synchronous functions and the whole thing could be simplified but I didn't want to go there.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thank you @juanjoDiaz - awesome job 🙌 However, I believe that I've made a mistake in my previous suggestions as I kinda missed the fact that these functions are not async at all - could you please check if we can just drop async from them? Other than that, we should be good to go 💯

As for any further refactoring - at this point I think we shouldn't really refactor Variables.js as @medikoo is working on introducing totally new variables parser, which should make this one obsolete at some point in the future.

@juanjoDiaz
Copy link
Contributor Author

Hi @pgrzesik,

The function as nor async but are called in a way that things break if you make them sync.

I was planning to raise a ticket about that once this PR is merged.
If the intention is to leave this as an obsolete class, I wouldn't really go into that change.

Copy link
Contributor

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

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

Thank you @juanjoDiaz for verifying if we can drop async - all looks great now 🙇

@pgrzesik pgrzesik changed the title refactor: Remove bluebird from classes refactor: Remove bluebird from lib/classes Feb 19, 2021
@pgrzesik pgrzesik merged commit 1a694ae into serverless:master Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants