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
Middleware does not accept a single function #1214
Comments
`if (typeof callback === 'object')` should be `if (typeof callback === 'function')` See Issue yargs#1214 for details
According to [the docs for the `.middleware()` method](http://yargs.js.org/docs/#api-middlewarecallbacks): > The `callbacks` parameter can be a function or a list of functions See Issue yargs#1214 for more details
Confirmed. Currently, if you need to pass a single function, it's mandatory to add it to an What I don't get either, is why and when a /cc @aorinevo |
@JimiC - Agreed. I think the |
Hi @BigstickCarpet thank you for raising this issue; looking forward to the PR. @JimiC thank you for validating. It was a misunderstanding. Although functions are objects, typeof function returns @BigstickCarpet: As part of your PR, can you add a unit test for this to /test/middleware.js? |
And the related test is also adjusted. |
* Fixed type check in .middleware() method `if (typeof callback === 'object')` should be `if (typeof callback === 'function')` See Issue #1214 for details * middewareFactory accepts a function, not an object According to [the docs for the `.middleware()` method](http://yargs.js.org/docs/#api-middlewarecallbacks): > The `callbacks` parameter can be a function or a list of functions See Issue #1214 for more details * Added/Updated middleware tests I added a new test to verify that the `.middleware()` method works when a single function is passed, rather than an array of functions. Also enhanced an existing test to ensure that _all_ middleware is run before commands, regardless of whether it was added as an array of functions or a single function.
@JamesMessinger @JimiC please try |
LGTM 👍 |
Seems like this should be closed? |
@arkon thanks for helping us groom some of our old issues 👍 |
According to the docs for the
.middleware()
method:However, it currently (as of v12.0.2) only works with an array of functions. Passing a single function does nothing.
Here is a reproduction of the issue on RunKit.
The problem is caused by this block of code:
yargs/lib/middleware.js
Lines 3 to 7 in 6c6c27d
I believe that
if (typeof callback === 'object')
should beif (typeof callback === 'function')
.I will submit a PR for this momentarily
The text was updated successfully, but these errors were encountered: