chore: remove bluebird dependency to packages/config for better Yarn 3 compat #26570
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additional details
I wrote this with the assistance of ChatGPT. Check it out!
Interesting enough, some of the earlier versions of the ChatGPT rewrite are actually more to my coding taste, but they moved too much code around. After some poking and prodding, I got to a good place where the code still resembles the original code, but also makes us of the modern async/await syntax.
Without good test coverage, I wouldn't be nearly as confidence to use a tool like GPT to refactor. Begs the question; how reliable are code bases using GPT to write tests in the first place? Can we rely on GPT to write tests for code it maybe have even wrote?
Human: Hi, can you help me convert some Javascript code using bluebird to use a native promise?
ChatGPT: Yes, of course! Please share the Javascript code using Bluebird that you would like to convert to native promises.
Human:
ChatGPT: Certainly! Here is the same code using native Promises:scssCopy code
The main difference is the use of Promise.resolve() to start the chain of promises and the removal of the catch method from Bluebird, as it is not available in native Promises. Instead, we use a regular catch block to catch the rejection with the specified code.
Human: Can we use try/catch and await instead?
ChatGPT: Yes, we can! Here's the same code converted to use async/await:
The main changes involve wrapping the code in a try/catch block and replacing .then() with await. We can also eliminate the need for a separate .catch() block by catching the error within the try block with an if statement.
Human: Can you write this using try/catch, but with as minimal changes as possible to the original code?
ChatGPT: Sure, here is the code converted to use try/catch with minimal changes
The main change is that the entire block of code is now wrapped in a try/catch statement. The .catch() block has been replaced with an if statement inside the try block that checks for the MODULE_NOT_FOUND error. If this error is caught, the code in the .catch() block is executed, otherwise the error is thrown. Since the .catch() block was only handling this specific error, we can eliminate it entirely and instead handle the error inside the try block.
Human: debug does not return a promise - please keep this in mind and try again.
ChatGPT: Sorry about that. Here's the revised code that keeps in mind that debug() does not return a promise
In this version, the first call to debug() is not wrapped in a then() block since it doesn't return a promise. Instead, we just call it directly and proceed to the conditional statements. The rest of the code follows a similar structure as the previous version with some minor adjustments to ensure that the final return statement is inside the try block.
Human: Still a lot of
then
. Can we make those intoawait
?ChatGPT: Sure, here's the modified code using await
In this version, we replaced the then() calls with await statements inside the if blocks. We also simplified the error handling by using a try/catch block instead of a .catch() method.
Steps to test
How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?