diff --git a/estest/index.js b/estest/index.js index 3c85bc0..1a87119 100644 --- a/estest/index.js +++ b/estest/index.js @@ -17,8 +17,8 @@ meow( flags: { rainbow: { type: 'boolean', - alias: 'r' - } - } - } + alias: 'r', + }, + }, + }, ); diff --git a/index.d.ts b/index.d.ts index be8c485..00054f6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -313,5 +313,4 @@ foo(cli.input[0], cli.flags); ``` */ export default function meow(helpMessage: string, options?: Options): Result; -// eslint-disable-next-line no-redeclare export default function meow(options?: Options): Result; diff --git a/index.js b/index.js index 8d3d76f..894ff2d 100644 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ const validateOptions = ({flags}) => { const reportUnknownFlags = unknownFlags => { console.error([ `Unknown flag${unknownFlags.length > 1 ? 's' : ''}`, - ...unknownFlags + ...unknownFlags, ].join('\n')); }; @@ -72,9 +72,9 @@ const buildParserFlags = ({flags, booleanDefault}) => { const flag = {...flagValue}; if ( - typeof booleanDefault !== 'undefined' && - flag.type === 'boolean' && - !Object.prototype.hasOwnProperty.call(flag, 'default') + typeof booleanDefault !== 'undefined' + && flag.type === 'boolean' + && !Object.prototype.hasOwnProperty.call(flag, 'default') ) { flag.default = flag.isMultiple ? [booleanDefault] : booleanDefault; } @@ -111,7 +111,7 @@ const meow = (helpText, options = {}) => { const foundPackage = readPackageUpSync({ cwd: dirname(fileURLToPath(options.importMeta.url)), - normalize: false + normalize: false, }); options = { @@ -126,7 +126,7 @@ const meow = (helpText, options = {}) => { booleanDefault: false, hardRejection: true, allowUnknownFlags: true, - ...options + ...options, }; if (options.hardRejection) { @@ -136,7 +136,7 @@ const meow = (helpText, options = {}) => { validateOptions(options); let parserOptions = { arguments: options.input, - ...buildParserFlags(options) + ...buildParserFlags(options), }; parserOptions = decamelizeKeys(parserOptions, '-', {exclude: ['stopEarly', '--']}); @@ -149,7 +149,7 @@ const meow = (helpText, options = {}) => { parserOptions.configuration = { ...parserOptions.configuration, - 'greedy-arrays': false + 'greedy-arrays': false, }; if (parserOptions['--']) { @@ -227,7 +227,7 @@ const meow = (helpText, options = {}) => { pkg: package_, help, showHelp, - showVersion + showVersion, }; }; diff --git a/index.test-d.ts b/index.test-d.ts index 6e0e848..81463b3 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -7,31 +7,31 @@ const importMeta = import.meta; expectType>(meow('Help text')); expectType>(meow('Help text', {importMeta, hardRejection: false})); expectAssignable<{flags: {foo: number}}>( - meow({importMeta: import.meta, flags: {foo: {type: 'number', isRequired: true}}}) + meow({importMeta: import.meta, flags: {foo: {type: 'number', isRequired: true}}}), ); expectAssignable<{flags: {foo: string}}>( - meow({importMeta, flags: {foo: {type: 'string', isRequired: true}}}) + meow({importMeta, flags: {foo: {type: 'string', isRequired: true}}}), ); expectAssignable<{flags: {foo: boolean}}>( - meow({importMeta, flags: {foo: {type: 'boolean', isRequired: true}}}) + meow({importMeta, flags: {foo: {type: 'boolean', isRequired: true}}}), ); expectAssignable<{flags: {foo: number | undefined}}>( - meow({importMeta, flags: {foo: {type: 'number'}}}) + meow({importMeta, flags: {foo: {type: 'number'}}}), ); expectAssignable<{flags: {foo: string | undefined}}>( - meow({importMeta, flags: {foo: {type: 'string'}}}) + meow({importMeta, flags: {foo: {type: 'string'}}}), ); expectAssignable<{flags: {foo: boolean | undefined}}>( - meow({importMeta, flags: {foo: {type: 'boolean'}}}) + meow({importMeta, flags: {foo: {type: 'boolean'}}}), ); expectAssignable<{flags: {foo: number[] | undefined}}>( - meow({importMeta, flags: {foo: {type: 'number', isMultiple: true}}}) + meow({importMeta, flags: {foo: {type: 'number', isMultiple: true}}}), ); expectAssignable<{flags: {foo: string[] | undefined}}>( - meow({importMeta, flags: {foo: {type: 'string', isMultiple: true}}}) + meow({importMeta, flags: {foo: {type: 'string', isMultiple: true}}}), ); expectAssignable<{flags: {foo: boolean[] | undefined}}>( - meow({importMeta, flags: {foo: {type: 'boolean', isMultiple: true}}}) + meow({importMeta, flags: {foo: {type: 'boolean', isMultiple: true}}}), ); expectType>(meow({importMeta, description: 'foo'})); expectType>(meow({importMeta, description: false})); @@ -55,8 +55,8 @@ const result = meow('Help text', { foo: {type: 'boolean', alias: 'f'}, 'foo-bar': {type: 'number'}, bar: {type: 'string', default: ''}, - abc: {type: 'string', isMultiple: true} - } + abc: {type: 'string', isMultiple: true}, + }, }); expectType(result.input); @@ -82,9 +82,9 @@ const options = { flags: { rainbow: { type: 'boolean', - alias: 'r' - } - } + alias: 'r', + }, + }, } as const; meow('', options); diff --git a/package.json b/package.json index d23e81a..11db150 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "console" ], "dependencies": { - "@types/minimist": "^1.2.1", - "camelcase-keys": "^6.2.2", + "@types/minimist": "^1.2.2", + "camelcase-keys": "^7.0.0", "decamelize": "^5.0.0", "decamelize-keys": "^1.1.0", "hard-rejection": "^2.1.0", @@ -51,17 +51,17 @@ "normalize-package-data": "^3.0.2", "read-pkg-up": "^8.0.0", "redent": "^4.0.0", - "trim-newlines": "^4.0.1", - "type-fest": "^1.0.2", - "yargs-parser": "^20.2.7" + "trim-newlines": "^4.0.2", + "type-fest": "^1.2.2", + "yargs-parser": "^20.2.9" }, "devDependencies": { "ava": "^3.15.0", - "execa": "^5.0.0", + "execa": "^5.1.1", "indent-string": "^5.0.0", "read-pkg": "^6.0.0", - "tsd": "^0.14.0", - "xo": "^0.39.1" + "tsd": "^0.17.0", + "xo": "^0.41.0" }, "xo": { "rules": { diff --git a/test/allow-unkonwn-flags.js b/test/allow-unkonwn-flags.js index fc723df..609a161 100644 --- a/test/allow-unkonwn-flags.js +++ b/test/allow-unkonwn-flags.js @@ -10,8 +10,8 @@ test('spawn CLI and test specifying unknown flags', async t => { const error = await t.throwsAsync( execa(fixtureAllowUnknownFlags, ['--foo', 'bar', '--unspecified-a', '--unspecified-b', 'input-is-allowed']), { - message: /^Command failed with exit code 2/ - } + message: /^Command failed with exit code 2/, + }, ); const {stderr} = error; t.regex(stderr, /Unknown flags/); diff --git a/test/fixtures/fixture-allow-unknown-flags.js b/test/fixtures/fixture-allow-unknown-flags.js index e14de67..3374b4f 100755 --- a/test/fixtures/fixture-allow-unknown-flags.js +++ b/test/fixtures/fixture-allow-unknown-flags.js @@ -11,9 +11,9 @@ const cli = meow({ allowUnknownFlags: false, flags: { foo: { - type: 'string' - } - } + type: 'string', + }, + }, }); console.log(cli.flags.foo); diff --git a/test/fixtures/fixture-required-function.js b/test/fixtures/fixture-required-function.js index 1d4129b..2f2cc7d 100755 --- a/test/fixtures/fixture-required-function.js +++ b/test/fixtures/fixture-required-function.js @@ -11,17 +11,15 @@ const cli = meow({ flags: { trigger: { type: 'boolean', - alias: 't' + alias: 't', }, withTrigger: { type: 'string', - isRequired: (flags, _) => { - return flags.trigger; - } + isRequired: (flags, _) => flags.trigger, }, allowError: { type: 'boolean', - alias: 'a' + alias: 'a', }, shouldError: { type: 'boolean', @@ -31,9 +29,9 @@ const cli = meow({ } return false; - } - } - } + }, + }, + }, }); console.log(`${cli.flags.trigger},${cli.flags.withTrigger}`); diff --git a/test/fixtures/fixture-required-multiple.js b/test/fixtures/fixture-required-multiple.js index 7fa3bd3..cf3325a 100755 --- a/test/fixtures/fixture-required-multiple.js +++ b/test/fixtures/fixture-required-multiple.js @@ -13,9 +13,9 @@ const cli = meow({ type: 'number', alias: 't', isRequired: true, - isMultiple: true - } - } + isMultiple: true, + }, + }, }); console.log(cli.flags.test); diff --git a/test/fixtures/fixture-required.js b/test/fixtures/fixture-required.js index ad2b4a6..5a8a55d 100755 --- a/test/fixtures/fixture-required.js +++ b/test/fixtures/fixture-required.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -'use strict'; import meow from '../../index.js'; const cli = meow({ @@ -13,20 +12,20 @@ const cli = meow({ test: { type: 'string', alias: 't', - isRequired: true + isRequired: true, }, number: { type: 'number', - isRequired: true + isRequired: true, }, kebabCase: { type: 'string', - isRequired: true + isRequired: true, }, notRequired: { - type: 'string' - } - } + type: 'string', + }, + }, }); console.log(`${cli.flags.test},${cli.flags.number}`); diff --git a/test/fixtures/fixture.js b/test/fixtures/fixture.js index dab6eb9..44200bb 100755 --- a/test/fixtures/fixture.js +++ b/test/fixtures/fixture.js @@ -13,8 +13,8 @@ const cli = meow({ flags: { unicorn: {alias: 'u'}, meow: {default: 'dog'}, - camelCaseOption: {default: 'foo'} - } + camelCaseOption: {default: 'foo'}, + }, }); if (cli.flags.camelCaseOption === 'foo') { diff --git a/test/is-required-flag.js b/test/is-required-flag.js index 45f4ca9..b77bf54 100644 --- a/test/is-required-flag.js +++ b/test/is-required-flag.js @@ -29,7 +29,7 @@ test('spawn cli and test specifying all required flags', async t => { '--number', '6', '--kebab-case', - 'test' + 'test', ]); t.is(stdout, 'test,6'); }); diff --git a/test/test.js b/test/test.js index f47dc28..54308d9 100644 --- a/test/test.js +++ b/test/test.js @@ -14,7 +14,7 @@ const NODE_MAJOR_VERSION = process.versions.node.split('.')[0]; test('invalid package url', t => { const error = t.throws(() => { meow({ - importMeta: '/path/to/package' + importMeta: '/path/to/package', }); }); t.is(error.message, 'The `importMeta` option is required. Its value must be `import.meta`.'); @@ -31,8 +31,8 @@ test('return object', t => { flags: { unicorn: {alias: 'u'}, meow: {default: 'dog'}, - '--': true - } + '--': true, + }, }); t.is(cli.input[0], 'foo'); @@ -49,7 +49,7 @@ test('support help shortcut', t => { unicorn cat `, { - importMeta + importMeta, }); t.is(cli.help, indentString('\nCLI app helper\n\nunicorn\ncat\n', 2)); }); @@ -106,8 +106,8 @@ test.serial('pkg.bin as a string should work', t => { pkg: { importMeta, name: 'browser-sync', - bin: 'bin/browser-sync.js' - } + bin: 'bin/browser-sync.js', + }, }); t.is(process.title, 'browser-sync'); @@ -116,7 +116,7 @@ test.serial('pkg.bin as a string should work', t => { test('single character flag casing should be preserved', t => { t.deepEqual(meow({ importMeta, - argv: ['-F'] + argv: ['-F'], }).flags, {F: true}); }); @@ -124,7 +124,7 @@ test('flag declared in kebab-case is an error', t => { const error = t.throws(() => { meow({ importMeta, - flags: {'kebab-case': 'boolean', test: 'boolean', 'another-one': 'boolean'} + flags: {'kebab-case': 'boolean', test: 'boolean', 'another-one': 'boolean'}, }); }); t.is(error.message, 'Flag keys may not contain \'-\': kebab-case, another-one'); @@ -136,26 +136,26 @@ test('type inference', t => { t.is(meow({ importMeta, argv: ['5'], - inferType: true + inferType: true, }).input[0], 5); t.is(meow({ importMeta, argv: ['5'], inferType: true, - flags: {foo: 'string'} + flags: {foo: 'string'}, }).input[0], 5); t.is(meow({ importMeta, argv: ['5'], inferType: true, flags: { - foo: 'string' - } + foo: 'string', + }, }).input[0], 5); t.is(meow({ importMeta, argv: ['5'], - input: 'number' + input: 'number', }).input[0], 5); }); @@ -166,19 +166,19 @@ test('booleanDefault: undefined, filter out unset boolean args', t => { booleanDefault: undefined, flags: { foo: { - type: 'boolean' + type: 'boolean', }, bar: { - type: 'boolean' + type: 'boolean', }, baz: { type: 'boolean', - default: false - } - } + default: false, + }, + }, }).flags, { foo: true, - baz: false + baz: false, }); }); @@ -188,20 +188,20 @@ test('boolean args are false by default', t => { argv: ['--foo'], flags: { foo: { - type: 'boolean' + type: 'boolean', }, bar: { type: 'boolean', - default: true + default: true, }, baz: { - type: 'boolean' - } - } + type: 'boolean', + }, + }, }).flags, { foo: true, bar: true, - baz: false + baz: false, }); }); @@ -211,9 +211,9 @@ test('enforces boolean flag type', t => { argv: ['--cursor=false'], flags: { cursor: { - type: 'boolean' - } - } + type: 'boolean', + }, + }, }); t.deepEqual(cli.flags, {cursor: false}); }); @@ -225,11 +225,11 @@ test('accept help and options', t => { flags: { foo: { type: 'boolean', - alias: 'f' - } - } + alias: 'f', + }, + }, }).flags, { - foo: true + foo: true, }); }); @@ -240,13 +240,13 @@ test('grouped short-flags work', t => { flags: { coco: { type: 'boolean', - alias: 'c' + alias: 'c', }, loco: { type: 'boolean', - alias: 'l' - } - } + alias: 'l', + }, + }, }); const {unnormalizedFlags} = cli; @@ -263,13 +263,13 @@ test('grouped flags work', t => { flags: { coco: { type: 'boolean', - alias: 'c' + alias: 'c', }, loco: { type: 'boolean', - alias: 'l' - } - } + alias: 'l', + }, + }, }); const {flags} = cli; @@ -291,9 +291,9 @@ test('supports `number` flag type', t => { argv: ['--foo=1.3'], flags: { foo: { - type: 'number' - } - } + type: 'number', + }, + }, }).flags.foo; t.is(cli, 1.3); @@ -305,9 +305,9 @@ test('supports `number` flag type - flag but no value', t => { argv: ['--foo'], flags: { foo: { - type: 'number' - } - } + type: 'number', + }, + }, }).flags.foo; t.is(cli, undefined); @@ -320,9 +320,9 @@ test('supports `number` flag type - flag but no value but default', t => { flags: { foo: { type: 'number', - default: 2 - } - } + default: 2, + }, + }, }).flags.foo; t.is(cli, 2); @@ -335,9 +335,9 @@ test('supports `number` flag type - no flag but default', t => { flags: { foo: { type: 'number', - default: 2 - } - } + default: 2, + }, + }, }).flags.foo; t.is(cli, 2); @@ -351,9 +351,9 @@ test('supports `number` flag type - throws on incorrect default value', t => { flags: { foo: { type: 'number', - default: 'x' - } - } + default: 'x', + }, + }, }); }); }); @@ -365,11 +365,11 @@ test('isMultiple - unset flag returns empty array', t => { flags: { foo: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: [] + foo: [], }); }); @@ -380,11 +380,11 @@ test('isMultiple - flag set once returns array', t => { flags: { foo: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: ['bar'] + foo: ['bar'], }); }); @@ -395,11 +395,11 @@ test('isMultiple - flag set multiple times', t => { flags: { foo: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: ['bar', 'baz'] + foo: ['bar', 'baz'], }); }); @@ -410,9 +410,9 @@ test('isMultiple - flag with space separated values', t => { flags: { foo: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }); t.deepEqual(input, ['baz']); @@ -426,11 +426,11 @@ test('isMultiple - flag with comma separated values', t => { flags: { foo: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: ['bar,baz'] + foo: ['bar,baz'], }); }); @@ -441,9 +441,9 @@ test('single flag set more than once => throws', t => { argv: ['--foo=bar', '--foo=baz'], flags: { foo: { - type: 'string' - } - } + type: 'string', + }, + }, }); }, {message: 'The flag --foo can only be set once.'}); }); @@ -454,11 +454,11 @@ test('isMultiple - default to type string', t => { argv: ['--foo=bar'], flags: { foo: { - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: ['bar'] + foo: ['bar'], }); }); @@ -469,11 +469,11 @@ test('isMultiple - boolean flag', t => { flags: { foo: { type: 'boolean', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: [true, false] + foo: [true, false], }); }); @@ -484,11 +484,11 @@ test('isMultiple - boolean flag is false by default', t => { flags: { foo: { type: 'boolean', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: [false] + foo: [false], }); }); @@ -499,11 +499,11 @@ test('isMultiple - number flag', t => { flags: { foo: { type: 'number', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - foo: [1.3, -1] + foo: [1.3, -1], }); }); @@ -515,23 +515,23 @@ test('isMultiple - flag default values', t => { string: { type: 'string', isMultiple: true, - default: ['foo'] + default: ['foo'], }, boolean: { type: 'boolean', isMultiple: true, - default: [true] + default: [true], }, number: { type: 'number', isMultiple: true, - default: [0.5] - } - } + default: [0.5], + }, + }, }).flags, { string: ['foo'], boolean: [true], - number: [0.5] + number: [0.5], }); }); @@ -543,23 +543,23 @@ test('isMultiple - multiple flag default values', t => { string: { type: 'string', isMultiple: true, - default: ['foo', 'bar'] + default: ['foo', 'bar'], }, boolean: { type: 'boolean', isMultiple: true, - default: [true, false] + default: [true, false], }, number: { type: 'number', isMultiple: true, - default: [0.5, 1] - } - } + default: [0.5, 1], + }, + }, }).flags, { string: ['foo', 'bar'], boolean: [true, false], - number: [0.5, 1] + number: [0.5, 1], }); }); @@ -571,11 +571,11 @@ test('isMultiple - handles multi-word flag name', t => { flags: { fooBar: { type: 'string', - isMultiple: true - } - } + isMultiple: true, + }, + }, }).flags, { - fooBar: ['baz'] + fooBar: ['baz'], }); }); @@ -583,7 +583,7 @@ if (NODE_MAJOR_VERSION >= 14) { test('supports es modules', async t => { try { const {stdout} = await execa('node', ['estest/index.js', '--version'], { - importMeta: path.join(__dirname, '..') + importMeta: path.join(__dirname, '..'), }); t.regex(stdout, /1.2.3/); } catch (error) { diff --git a/tsconfig.json b/tsconfig.json index edadef1..c848130 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,11 +6,11 @@ "compilerOptions": { "strict": true, "jsx": "react", - "target": "es2018", + "target": "ES2019", // Node.js 12 "lib": [ - "es2018" + "ES2019" ], - "module": "esnext", + "module": "ES2020", "moduleResolution": "node", "noImplicitAny": true, "strictNullChecks": true,