Remove default export of global program (#2017)
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 f570b08 · Browse files · 8 files·+68 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+68 added−28 removed
- tests:+63 added−22 removed
- other:+5 added−6 removed
Provenance
- Commit
c876dee- Tree
28a6727- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
f570b08
8 files changed+68 added−28 removed
modified:docs/deprecated.md+1 added
56 unmodified lines57 58 - Removed from README in Commander v5.59 - Deprecated from Commander v7.60 - Removed from TypeScript declarations in Commander v8.61+- Removed from CommonJS in Commander v12. Deprecated and gone!62 63 ## Callback to .help() and .outputHelp()64 65 These routines allowed a callback parameter to process the built-in help before display.145 unmodified linesmodified:tests/fixtures/inspect.js+1 added-1 removed
12334567#!/usr/bin/env node
const program = require('../../');const { program } = require('../../');
program .command('sub', 'install one or more packages') .parse(process.argv);modified:tests/fixtures/pm+1 added-1 removed
1 #!/usr/bin/env node2 3-var program = require('../../');3+var { program } = require('../../');4 5 program6 .version('0.0.1')7 .command('install [name]', 'install one or more packages').alias('i')11 unmodified linesmodified:tests/fixtures/pm-cache.js+1 added-1 removed
1123456const program = require('../../');const { program } = require('../../');
program .command('clear', 'clear the cache') .command('validate', 'validate the cache', { isDefault: true }) .parse(process.argv);modified:tests/fixtures-extensions/pm.js+1 added-1 removed
123345672 unmodified lines#!/usr/bin/env node
const program = require('../../');const { program } = require('../../');
program .command('try-ts', 'test file extension lookup') .command('try-cjs', 'test file extension lookup')2 unmodified linesmodified:tests/program.test.js+59 added-12 removed
112345678910111213141516175678181920212223242526272811121314293031321718193334353637383940414243444546474849505152535455565758596061626364656667const commander = require('../');const { program, Command, Option, Argument, Help, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, createCommand, createOption, createArgument} = require('../index.js');
// Do some testing of the default export(s).// Similar tests to ts-imports.test.ts and esm-imports-test.js.
test('when require commander then is a Command (default export of global)', () => { // Deprecated global command const program = commander; expect(program.constructor.name).toBe('Command');/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "checkClass"] }] */
function checkClass(obj, name) { expect(typeof obj).toEqual('object'); expect(obj.constructor.name).toEqual(name);}
test('program', () => { checkClass(program, 'Command');});
test('when require commander then has program (named export of global)', () => { // program added in v5 const program = commander.program; expect(program.constructor.name).toBe('Command');test('Command', () => { checkClass(new Command('name'), 'Command');});
test('when require commander then has newable Command', () => { const cmd = new commander.Command(); expect(cmd.constructor.name).toBe('Command');test('Option', () => { checkClass(new Option('-e, --example', 'description'), 'Option');});
test('Argument', () => { checkClass(new Argument('<foo>', 'description'), 'Argument');});
test('Help', () => { checkClass(new Help(), 'Help');});
test('CommanderError', () => { checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError');});
test('InvalidArgumentError', () => { checkClass(new InvalidArgumentError('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');});modified:tests/ts-imports.test.ts-6 removed
123434567891011141516171213141527 unmodified linesimport { program, Command, Option, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Help, createCommand } from '../';
import * as commander from '../';
// Do some simple checks that expected imports are available at runtime.// Similar tests to esm-imports-test.js
// eslint-disable-next-line @typescript-eslint/ban-typesfunction checkClass(obj: object, name: string): void { expect(typeof obj).toEqual('object'); expect(obj.constructor.name).toEqual(name);}
test('legacy default export of global Command', () => { checkClass(commander, 'Command');});
test('program', () => { checkClass(program, 'Command');});
27 unmodified linesmodified:index.js+4 added-6 removed
4 unmodified lines567891011910131415111213141516178 unmodified lines4 unmodified linesconst { Option } = require('./lib/option.js');
// @ts-check
/** * Expose the root command. */exports.program = new Command();
exports = module.exports = new Command();exports.program = exports; // More explicit access to global command.// Implicit export of createArgument, createCommand, and createOption.exports.createCommand = (name) => new Command(name);exports.createOption = (flags, description) => new Option(flags, description);exports.createArgument = (name, description) => new Argument(name, description);
/** * Expose classes */8 unmodified lines