Explicitly export factory functions (#2013)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent 58820a4 · Browse files · 3 files·+114 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Wee Bit <aweebit64@gmail.com>
Diff stats
3 files+114 added−33 removed
- tests:+95 added−27 removed
- other:+19 added−6 removed
Provenance
- Commit
384f17b- Tree
d0edc24- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
58820a4
3 files changed+114 added−33 removed
modified:tests/ts-imports.test.ts+95 added-27 removed
11234567891011121314315161718192 unmodified lines22232425261415162728293018192031323334222324353637382627283940414230313243444546343536474849503839405152535442435556575859606162636465666768697071727374757677787980818283848586878846478990919293949596979899100101102103104105106107108109110111112113114115116import { program, Command, Option, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Help, createCommand } from '../';import { program, Command, Option, Argument, Help, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, createCommand, createOption, createArgument} from '../';
import * as commander from '../';import * as commander from '../'; // This does interesting things when esModuleInterop is true!
// Do some simple checks that expected imports are available at runtime.// Similar tests to esm-imports-test.js
2 unmodified lines expect(typeof obj).toEqual('object'); expect(obj.constructor.name).toEqual(name);}
describe('named imports', () => {test('legacy default export of global Command', () => { checkClass(commander, 'Command');}); test('program', () => { checkClass(program, 'Command'); });
test('program', () => { checkClass(program, 'Command');}); test('Command', () => { checkClass(new Command('name'), 'Command'); });
test('createCommand', () => { checkClass(createCommand(), 'Command');}); test('Option', () => { checkClass(new Option('-e, --example', 'description'), 'Option'); });
test('Command', () => { checkClass(new Command('name'), 'Command');}); test('Argument', () => { checkClass(new Argument('<foo>', 'description'), 'Argument'); });
test('Option', () => { checkClass(new Option('-e, --example', 'description'), 'Option');}); test('Help', () => { checkClass(new Help(), 'Help'); });
test('CommanderError', () => { checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError');}); test('CommanderError', () => { checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError'); });
test('InvalidArgumentError', () => { checkClass(new InvalidArgumentError('failed'), 'InvalidArgumentError');}); test('InvalidArgumentError', () => { checkClass(new InvalidArgumentError('failed'), 'InvalidArgumentError'); });
test('InvalidOptionArgumentError', () => { // Deprecated checkClass(new InvalidOptionArgumentError('failed'), 'InvalidArgumentError'); test('InvalidOptionArgumentError', () => { // Deprecated checkClass(new InvalidOptionArgumentError('failed'), 'InvalidArgumentError'); });
test('createCommand', () => { checkClass(createCommand('foo'), 'Command'); });
test('createOption', () => { checkClass(createOption('-e, --example', 'description'), 'Option'); });
test('createArgument', () => { checkClass(createArgument('<foo>', 'description'), 'Argument'); });});
describe('import * as commander', () => { test('program', () => { checkClass(commander.program, 'Command'); });
test('Command', () => { checkClass(new commander.Command('name'), 'Command'); });
test('Option', () => { checkClass(new commander.Option('-e, --example', 'description'), 'Option'); });
test('Argument', () => { checkClass(new commander.Argument('<foo>', 'description'), 'Argument'); });
test('Help', () => { checkClass(new Help(), 'Help'); test('Help', () => { checkClass(new commander.Help(), 'Help'); });
test('CommanderError', () => { checkClass(new commander.CommanderError(1, 'code', 'failed'), 'CommanderError'); });
test('InvalidArgumentError', () => { checkClass(new commander.InvalidArgumentError('failed'), 'InvalidArgumentError'); });
test('InvalidOptionArgumentError', () => { // Deprecated checkClass(new commander.InvalidOptionArgumentError('failed'), 'InvalidArgumentError'); });
test('createCommand', () => { checkClass(commander.createCommand('foo'), 'Command'); });
test('createOption', () => { checkClass(commander.createOption('-e, --example', 'description'), 'Option'); });
test('createArgument', () => { checkClass(commander.createArgument('<foo>', 'description'), 'Argument'); });});modified:index.js+18 added-6 removed
8 unmodified lines91011121314151314151617181920212123222324252627282729303132333435363738398 unmodified lines/** * Expose the root command. */
exports = module.exports = new Command();exports.program = exports; // More explicit access to global command.// Implicit export of createArgument, createCommand, and createOption.const program = new Command();exports = module.exports = program; // default export (deprecated)exports.program = program; // more explicit access to global command
/** * Expose classes */
exports.Argument = Argument;exports.Command = Command;exports.CommanderError = CommanderError;exports.Option = Option;exports.Argument = Argument;exports.Help = Help;
exports.CommanderError = CommanderError;exports.InvalidArgumentError = InvalidArgumentError;exports.InvalidOptionArgumentError = InvalidArgumentError; // Deprecatedexports.Option = Option;
/** * 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;modified:tsconfig.json+1 added
9 unmodified lines101112131415161718199 unmodified lines "types": [ "node", "jest" ], "esModuleInterop": true, // Mainly so can test an import problem which only occurs with this option on! "noEmit": true, "forceConsistentCasingInFileNames": true }, "include": ["**/*.ts"],}