Skip to content

Commit

Permalink
Revert factory function reexport (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored Sep 12, 2023
1 parent 384f17b commit 14edbca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
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');
// });
});

0 comments on commit 14edbca

Please sign in to comment.