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

Subclassing Help in a JavaScript project throws errors #67

Closed
tarkatronic opened this issue Jun 1, 2020 · 4 comments · Fixed by #68
Closed

Subclassing Help in a JavaScript project throws errors #67

tarkatronic opened this issue Jun 1, 2020 · 4 comments · Fixed by #68

Comments

@tarkatronic
Copy link

Steps to reproduce:

  1. Create a new JavaScript project
    $ npx oclif multi test-command
  2. Create test-command/src/help.js
     const { Help } = require('@oclif/plugin-help');
     
     module.exports = class TestHelp extends Help {
       showHelp(args) {
         console.log('Hello, world! I am customized help!');
         super.showHelp(args);
       }
     };
  3. Add oclif.helpClass key to package.json:
    {
      "oclif": {
        "helpClass": "./src/help"
      }
    }
  4. Run command:
    $ node bin/run
    Error: Unable to load configured help class "./src/help", failed with message:
    Class extends value undefined is not a constructor or null
        at Object.getHelpClass (~/workspace/test-command/node_modules/@oclif/plugin-help/lib/util.js:66:19)
        at Main._help (~/workspace/test-command/node_modules/@oclif/command/lib/main.js:40:41)
        at Main.init (~/workspace/test-command/node_modules/@oclif/command/lib/command.js:81:25)
        at Main.init (~/workspace/test-command/node_modules/@oclif/command/lib/main.js:12:22)
        at async Main._run (~/workspace/test-command/node_modules/@oclif/command/lib/command.js:42:13)

The documentation currently only shows extending HelpBase in JavaScript projects, although the second example appears to be showing an example which would be extending Help. If I change my example to extend HelpBase, it fails in a different yet predictable fashion:

$ node bin/run
Hello, world! I am customized help!
TypeError: (intermediate value).showHelp is not a function
    at TestHelp.showHelp (~/workspace/test-command/src/help.js:6:11)
    at Main._help (~/workspace/test-command/node_modules/@oclif/command/lib/main.js:42:14)
    at Main.init (~/workspace/test-command/node_modules/@oclif/command/lib/command.js:81:25)
    at Main.init (~/workspace/test-command/node_modules/@oclif/command/lib/main.js:12:22)
    at async Main._run (~/workspace/test-command/node_modules/@oclif/command/lib/command.js:42:13)
@childish-sambino
Copy link
Contributor

Think this is similar to oclif/plugin-plugins#97. Temporary fix/hack is to pin tslib to 1.11.2.

@tarkatronic
Copy link
Author

@childish-sambino Sadly, that had no effect. I still get the same errors, even with tslib pinned.

@tarkatronic
Copy link
Author

I have found a solution to this thanks to @bcbailey. There seems to be a problem with the fact that the Help class is an export default, and we are using require(...). The fix was to change my code to:

const Help = require('@oclif/plugin-help').default;

And now I get the expected:

$ node bin/run
Hello, world! I am customized help!
VERSION
  test-command/0.0.0 linux-x64 node-v12.16.2

USAGE
  $ test-command [COMMAND]

COMMANDS
  hello  Describe the command here
  help   display help for test-command

@RasPhilCo
Copy link
Contributor

Thanks for bringing this to our attention!

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