message: Fix type error with handler method
diff: @@ -54,13 +54,25 @@ export async function runCLI(cwd: string) {
  // eslint-disable-next-line no-unused-expressions
  yargs
  + // Use yargs.commandDir method to initialize a directory of commands
  + // Ref: https://github.com/yargs/yargs/blob/e87f4873012e3541325e7ec6dafb11a93b5717e0/docs/advanced.md#commanddirdirectory-opts
  .commandDir('commands', {
  + // Use the visit option (of `node-require-directory`) to provide a visitor function
  + // Ref: https://github.com/yargs/yargs/blob/0942a1518aad77656c135439194f8f825bd8b33a/test/command.js#L570-L599
  + // Ref (node-require-directory): https://github.com/troygoode/node-require-directory#visiting-objects-as-theyre-loaded
  + // Ref (node-require-directory): https://github.com/troygoode/node-require-directory/blob/f043664108f4a4cdb9a1c10e42268d6db754c855/test/test.js#L161-L171
  visit(cmd: CommandModule) {
  - const uncurriedCommandHandler = cmd.handler;
  -
  - // eslint-disable-next-line no-param-reassign
  - cmd.handler = argv =>
  - uncurriedCommandHandler({
  + return JSON.stringify(cmd) === '{}'
  + ? // If the cmd module is an empty object, just return the object
  + cmd
  + : // If the cmd module isn't empty, modify the handler function by currying in some
  + // parameters that we need and providing fulfillment and rejection callback
  + // functions for the promise.
  + {
  + ...cmd,
  + handler: argv =>
  + cmd
  + .handler({
  ...argv,
  cwd,
  config,
  @@ -68,10 +80,12 @@ export async function runCLI(cwd: string) {
  cerr: console.error,
  })
  .catch(err =>
  - errorQuit(err, `Uncaught error in ${cmd.command} command:`))
  - .then(code => process.exit(code));
  -
  - return cmd;
  + errorQuit(
  + err,
  + `Uncaught error in ${cmd.command} command:`,
  + ))
  + .then(code => process.exit(code)),
  + };
  },
  })
  .demandCommand()
  