Skip to content

Commit

Permalink
Workaround yargs/yargs#783
Browse files Browse the repository at this point in the history
Pretend that the file calling Yargs is the one that was invoked, even if
it was not.  This way the Yargs configuration will always be loaded from
package.json.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
  • Loading branch information
kevinoid committed Feb 15, 2017
1 parent 68ae670 commit cac8a72
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/cmd.js
Expand Up @@ -125,7 +125,9 @@ function modulenameCmd(args, options, callback) {
return undefined;
}

var yargs = new Yargs()
// Workaround for https://github.com/yargs/yargs/issues/783
require.main = module;
var yargs = new Yargs(null, null, require)
.usage('Usage: $0 [options] [args...]')
.help()
.alias('help', 'h')
Expand Down

2 comments on commit cac8a72

@bennettellis
Copy link

Choose a reason for hiding this comment

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

don't believe this works in the latest version of yargs.
See also: yargs/yargs#828

@kevinoid
Copy link
Owner Author

Choose a reason for hiding this comment

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

@bennettellis It works for me with yargs 7.0.2.

For example, appveyor-status uses it. You can try commenting it out to observe the tests for that project failing.

Please sign in to comment.