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

Commander Package does not work with Bun. #1369

Closed
eli-rich opened this issue Oct 22, 2022 · 8 comments
Closed

Commander Package does not work with Bun. #1369

eli-rich opened this issue Oct 22, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@eli-rich
Copy link

What version of Bun is running?

0.2.1 (canary)

What platform is your computer?

Darwin 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64 i386

What steps can reproduce the bug?

  1. Create a new directory.
  2. Run bun init
  3. Run bun add commander
  4. Open index.ts
  5. Set contents to the example from the commander github
    This example has been change to the ESM import syntax. I get the same result with both.
import { program } from 'commander';

program.option('--first').option('-s, --separator <char>');

program.parse();

const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
  1. Run bun index.ts

How often does it reproduce? Is there a required condition?

Every time. There seems to be no required condition.

What is the expected behavior?

The program executes without error.

What do you see instead?

error: Cannot find package "child_process" from "/Users/elirichardson/bun/node_modules/commander/lib/command.js"

screenshot

Additional information

No response

@eli-rich eli-rich added bug Something isn't working needs repro Needs an example to reproduce labels Oct 22, 2022
@eli-rich
Copy link
Author

Confirmed on Ubuntu in virtual machine:
Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64

@Electroid Electroid removed the needs repro Needs an example to reproduce label Oct 22, 2022
@Electroid
Copy link
Contributor

This should be resolved once we support child_process, #595

@Electroid
Copy link
Contributor

@robobun

import { program } from 'commander';

program.option('--first').option('-s, --separator <char>');

program.parse();

const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));

@robobun
Copy link

robobun commented Dec 7, 2022

@Electroid here you go!

2 | program.option("--first").option("-s, --separator <char>");
3 | program.parse();
3 | const options = program.opts();
4 | const limit = options.first ? 1 : undefined;
5 |
6 | console.log(program.args[0].split(options.separator, limit));
               ^
TypeError: undefined is not an object (evaluating 'program.args[0].split')
      at /tmp/bun-vHJi59/index.js:9:12
Code
import { program } from 'commander';

program.option('--first').option('-s, --separator <char>');

program.parse();

const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

@Electroid
Copy link
Contributor

@robobun

const { program } = require('commander');

program
  .option('--first')
  .option('-s, --separator <char>');

program.parse();

const options = program.opts();
console.log("Options:", options);
console.log("Program:", program);

@robobun
Copy link

robobun commented Dec 7, 2022

@Electroid here you go!

  CommanderError: [Function: CommanderError],
  Help: [Function: Help],
  InvalidArgumentError: [Function: InvalidArgumentError],
  InvalidOptionArgumentError: [Function: InvalidArgumentError],
  Option: [Function: Option],
  [Symbol(CommonJSTransformed)]: true,
  copyInheritedSettings: [Function: copyInheritedSettings],
  command: [Function: command],
  createCommand: [Function: createCommand],
  createHelp: [Function: createHelp],
  configureHelp: [Function: configureHelp],
  configureOutput: [Function: configureOutput],
  showHelpAfterError: [Function: showHelpAfterError],
  showSuggestionAfterError: [Function: showSuggestionAfterError],
  addCommand: [Function: addCommand],
  createArgument: [Function: createArgument],
  argument: [Function: argument],
  arguments: [Function: arguments],
  addArgument: [Function: addArgument],
  addHelpCommand: [Function: addHelpCommand],
  _hasImplicitHelpCommand: [Function: _hasImplicitHelpCommand],
  hook: [Function: hook],
  exitOverride: [Function: exitOverride],
  _exit: [Function: _exit],
  action: [Function: action],
  createOption: [Function: createOption],
  addOption: [Function: addOption],
  _optionEx: [Function: _optionEx],
  option: [Function: option],
  requiredOption: [Function: requiredOption],
  combineFlagAndOptionalValue: [Function: combineFlagAndOptionalValue],
  allowUnknownOption: [Function: allowUnknownOption],
  allowExcessArguments: [Function: allowExcessArguments],
  enablePositionalOptions: [Function: enablePositionalOptions],
  passThroughOptions: [Function: passThroughOptions],
  storeOptionsAsProperties: [Function: storeOptionsAsProperties],
  getOptionValue: [Function: getOptionValue],
  setOptionValue: [Function: setOptionValue],
  setOptionValueWithSource: [Function: setOptionValueWithSource],
  getOptionValueSource: [Function: getOptionValueSource],
  _prepareUserArgs: [Function: _prepareUserArgs],
  parse: [Function: parse],
  parseAsync: [Function: parseAsync],
  _executeSubCommand: [Function: _executeSubCommand],
  _dispatchSubcommand: [Function: _dispatchSubcommand],
  _checkNumberOfArguments: [Function: _checkNumberOfArguments],
  _processArguments: [Function: _processArguments],
  _chainOrCall: [Function: _chainOrCall],
  _chainOrCallHooks: [Function: _chainOrCallHooks],
  _chainOrCallSubCommandHook: [Function: _chainOrCallSubCommandHook],
  _parseCommand: [Function: _parseCommand],
  _findCommand: [Function: _findCommand],
  _findOption: [Function: _findOption],
  _checkForMissingMandatoryOptions: [Function: _checkForMissingMandatoryOptions],
  _checkForConflictingLocalOptions: [Function: _checkForConflictingLocalOptions],
  _checkForConflictingOptions: [Function: _checkForConflictingOptions],
  parseOptions: [Function: parseOptions],
  opts: [Function: opts],
  optsWithGlobals: [Function: optsWithGlobals],
  error: [Function: error],
  _parseOptionsEnv: [Function: _parseOptionsEnv],
  _parseOptionsImplied: [Function: _parseOptionsImplied],
  missingArgument: [Function: missingArgument],
  optionMissingArgument: [Function: optionMissingArgument],
  missingMandatoryOptionValue: [Function: missingMandatoryOptionValue],
  _conflictingOption: [Function: _conflictingOption],
  unknownOption: [Function: unknownOption],
  _excessArguments: [Function: _excessArguments],
  unknownCommand: [Function: unknownCommand],
  version: [Function: version],
  description: [Function: description],
  summary: [Function: summary],
  alias: [Function: alias],
  aliases: [Function: aliases],
  usage: [Function: usage],
  nameFromFilename: [Function: nameFromFilename],
  executableDir: [Function: executableDir],
  helpInformation: [Function: helpInformation],
  _getHelpContext: [Function: _getHelpContext],
  outputHelp: [Function: outputHelp],
  helpOption: [Function: helpOption],
  help: [Function: help],
  addHelpText: [Function: addHelpText],
  addListener: [Function: addListener],
  on: [Function: on],
  once: [Function: once],
  prepend: [Function: prepend],
  prependOnce: [Function: prependOnce],
  removeListener: [Function: removeListener],
  off: [Function: off],
  removeAllListeners: [Function: removeAllListeners],
  emit: [Function: emit],
  eventNames: [Function: eventNames],
  listenerCount: [Function: listenerCount],
  listeners: [Function: listeners],
  rawListeners: [Function: rawListeners],
  setMaxListeners: [Function: setMaxListeners],
  getMaxListeners: [Function: getMaxListeners]
}
Code
const { program } = require('commander');

program
  .option('--first')
  .option('-s, --separator <char>');

program.parse();

const options = program.opts();
console.log("Options:", options);
console.log("Program:", program);

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

@Electroid
Copy link
Contributor

It looks like commander should work as of Bun v0.3.0 🎉

If you're still having issue, please feel free to open another issue.

@robobun
Copy link

robobun commented Dec 7, 2022

@Electroid here you go!

1 | commander;
Refe
ReferenceError: Can't find variable: commander
      at /tmp/bun-IABuhM/index.tsx:1:0
Code
commander

Ran using the latest build of Bun, an all-in-one JavaScript runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants