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

Global middleware don't work in 12.0.1 #1178

Closed
jaguilar87 opened this issue Jul 5, 2018 · 4 comments · Fixed by #1180
Closed

Global middleware don't work in 12.0.1 #1178

jaguilar87 opened this issue Jul 5, 2018 · 4 comments · Fixed by #1180
Assignees
Labels

Comments

@jaguilar87
Copy link

I've tried this code:

const yargs = require('yargs');

const mwFunc1 = argv => console.log('I\'m a middleware function');
const mwFunc2 = argv => console.log('I\'m another middleware function');

yargs
  .command('myCommand', 'some command', {}, function(argv){
    console.log('Running myCommand!');
  })
  .middleware([mwFunc1, mwFunc2]).argv;

OUTPUT:

Running myCommand!

No trace of the middlewares :(

@aorinevo
Copy link
Contributor

aorinevo commented Jul 5, 2018

Hi @jaguilar87, I was able to reproduce the issue. I resolved it by calling middleware first before the command method.

#!/usr/bin/env node
const yargs = require('yargs');

const mwFunc1 = argv => console.log('I\'m a middleware function');
const mwFunc2 = argv => console.log('I\'m another middleware function');

console.log('test');
yargs
  .middleware([mwFunc1, mwFunc2])
  .command('myCommand', 'some command', {}, function(argv){
    console.log(argv);
    console.log('Running myCommand!');
  })
  .argv;

screen shot 2018-07-05 at 12 44 14 pm

@bcoe bcoe added the bug label Jul 5, 2018
@bcoe
Copy link
Member

bcoe commented Jul 5, 2018

the order of the middleware definition, vs., the order of the command definition shouldn't matter. Definitely a bug we'll dig into.

@aorinevo
Copy link
Contributor

aorinevo commented Jul 6, 2018

PR #1180 fixes this issue.

@bcoe
Copy link
Member

bcoe commented Oct 6, 2018

@jaguilar87 @aorinevo please try npm i yargs@next which should correct this issue; if it's looking good, I can promote a new release early next week.

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