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

Fix promise check to accept any spec conform object #1424

Merged
merged 1 commit into from Sep 18, 2019

Conversation

micha149
Copy link
Contributor

I came across this problem when I was creating a CLI tool which uses NodeGit internally. NodeGit is using its own fork of es6 promises and so yargs failed to handle my async code because it didn't return an instance of Promise. But yargs should accept all promises as long as they are spec conform, regardless if its an native promise, a polyfill, a bluebird promise or any custom implementation.

So, I fixed the code to look for thenable objects instead of making an instanceof check.

@micha149
Copy link
Contributor Author

😞Pipeline failed because of an timeout… Can somebody rebuild it?

Copy link
Member

@mleguen mleguen left a comment

Choose a reason for hiding this comment

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

Thanks @micha149

Could you please add the missing test?

test/is-promise.js Show resolved Hide resolved
@mleguen
Copy link
Member

mleguen commented Sep 18, 2019

Travis CI build restarted

An instanceof check only accept promises which are created using the `Promise`
constructor. But there are other libraries which their own contructors. These
promises should also work as long as they adhere to the spec.
@mleguen mleguen merged commit 0be43d2 into yargs:master Sep 18, 2019
@mleguen
Copy link
Member

mleguen commented Sep 18, 2019

Thanks @micha149

@micha149
Copy link
Contributor Author

My pleasure.

@bcoe
Copy link
Member

bcoe commented Oct 7, 2019

@micha149 thanks for the contribution 🎉 this should now be available in yargs@14.2.0.

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

Successfully merging this pull request may close these issues.

None yet

3 participants