Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const program = new Command();
exports = module.exports = program; // default export (deprecated)
exports.program = program; // more explicit access to global command

// createArgument, createCommand, and createOption are implicitly available as they are methods on program.

/**
* Expose classes
*/
Expand All @@ -26,14 +28,3 @@ exports.Help = Help;
exports.CommanderError = CommanderError;
exports.InvalidArgumentError = InvalidArgumentError;
exports.InvalidOptionArgumentError = InvalidArgumentError; // Deprecated

/**
* Expose object factory functions.
*
* These are present implicitly, but need to be explicit
* to work with TypeScript whole module import (import * as foo) when esModuleInterop: true.
*/

exports.createCommand = program.createCommand;
exports.createArgument = program.createArgument;
exports.createOption = program.createOption;
21 changes: 12 additions & 9 deletions tests/ts-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ describe('import * as commander', () => {
checkClass(new commander.InvalidOptionArgumentError('failed'), 'InvalidArgumentError');
});

test('createCommand', () => {
checkClass(commander.createCommand('foo'), 'Command');
});
// Factory functions are not found if esModuleInterop is true, so comment out tests for now.
// Can uncomment these again when we drop the default export of global program and add the factory functions explicitly.

test('createOption', () => {
checkClass(commander.createOption('-e, --example', 'description'), 'Option');
});
// test('createCommand', () => {
// checkClass(commander.createCommand('foo'), 'Command');
// });

test('createArgument', () => {
checkClass(commander.createArgument('<foo>', 'description'), 'Argument');
});
// test('createOption', () => {
// checkClass(commander.createOption('-e, --example', 'description'), 'Option');
// });

// test('createArgument', () => {
// checkClass(commander.createArgument('<foo>', 'description'), 'Argument');
// });
});