Skip to content

Commit 24d5e9c

Browse files
Target Node 16 (#235)
1 parent a94476a commit 24d5e9c

File tree

9 files changed

+32
-30
lines changed

9 files changed

+32
-30
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 19
1314
- 18
1415
- 16
15-
- 14
1616
steps:
1717
- uses: actions/checkout@v3
1818
- uses: actions/setup-node@v3

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ const cli = meow(`
404404
// ...
405405
//}
406406
407-
foo(cli.input[0], cli.flags);
407+
foo(cli.input.at(0), cli.flags);
408408
```
409409
*/
410410
export default function meow<Flags extends AnyFlags>(helpMessage: string, options?: Options<Flags>): Result<Flags>;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"default": "./source/index.js"
1717
},
1818
"engines": {
19-
"node": ">=14.16"
19+
"node": ">=16.10"
2020
},
2121
"scripts": {
2222
"test": "xo && ava && tsd"

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const cli = meow(`
6060
}
6161
*/
6262

63-
foo(cli.input[0], cli.flags);
63+
foo(cli.input.at(0), cli.flags);
6464
```
6565

6666
## API

source/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ import {validate, checkUnknownFlags, checkMissingRequiredFlags} from './validate
1212
const buildResult = (options, parserOptions) => {
1313
const {pkg: package_} = options;
1414
const argv = parseArguments(options.argv, parserOptions);
15-
let help = trimNewlines((options.help || '').replace(/\t+\n*$/, ''));
15+
let help = '';
1616

17-
if (help.includes('\n')) {
18-
help = redent(help, 2);
17+
if (options.help) {
18+
help = trimNewlines((options.help || '').replace(/\t+\n*$/, ''));
19+
20+
if (help.includes('\n')) {
21+
help = redent(help, 2);
22+
}
23+
24+
help = `\n${help}`;
1925
}
2026

2127
normalizePackageData(package_);
@@ -25,12 +31,8 @@ const buildResult = (options, parserOptions) => {
2531
({description} = package_);
2632
}
2733

28-
// Change to `&&=` when targeting Node 15+
29-
if (description) {
30-
description = help ? `\n ${description}\n` : `\n${description}`;
31-
}
32-
33-
help = (description || '') + (help ? `\n${help}\n` : '\n');
34+
description &&= help ? `\n ${description}\n` : `\n${description}`;
35+
help = `${description || ''}${help}\n`;
3436

3537
const showHelp = code => {
3638
console.log(help);
@@ -95,7 +97,7 @@ const meow = (helpText, options = {}) => {
9597
const parserOptions = buildParserOptions(parsedOptions);
9698
const result = buildResult(parsedOptions, parserOptions);
9799

98-
process.title = result.pkg.bin ? Object.keys(result.pkg.bin)[0] : result.pkg.name;
100+
process.title = result.pkg.bin ? Object.keys(result.pkg.bin).at(0) : result.pkg.name;
99101

100102
return result;
101103
};

source/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const validateOptions = options => {
1212
message: flagKeys => `Flag keys may not contain '-'. Invalid flags: ${joinFlagKeys(flagKeys, '')}`,
1313
},
1414
aliasIsSet: {
15-
filter: ([, flag]) => flag.alias !== undefined,
15+
filter: ([, flag]) => Object.hasOwn(flag, 'alias'),
1616
message: flagKeys => `The option \`alias\` has been renamed to \`shortFlag\`. The following flags need to be updated: ${joinFlagKeys(flagKeys)}`,
1717
},
1818
choicesNotAnArray: {
19-
filter: ([, flag]) => flag.choices !== undefined && !Array.isArray(flag.choices),
19+
filter: ([, flag]) => Object.hasOwn(flag, 'choices') && !Array.isArray(flag.choices),
2020
message: flagKeys => `The option \`choices\` must be an array. Invalid flags: ${joinFlagKeys(flagKeys)}`,
2121
},
2222
choicesNotMatchFlagType: {

source/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const buildParserFlags = ({flags, booleanDefault}) => {
1616
if (
1717
typeof booleanDefault !== 'undefined'
1818
&& flag.type === 'boolean'
19-
&& !Object.prototype.hasOwnProperty.call(flag, 'default')
19+
&& !Object.hasOwn(flag, 'default')
2020
) {
2121
flag.default = flag.isMultiple ? [booleanDefault] : booleanDefault;
2222
}

test/test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import meow from '../source/index.js';
88
import {spawnFixture, __dirname} from './_utils.js';
99

1010
const importMeta = import.meta;
11-
const NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
11+
const NODE_MAJOR_VERSION = process.versions.node.split('.').at(0);
1212

1313
test('return object', t => {
1414
const cli = meow({
@@ -25,7 +25,7 @@ test('return object', t => {
2525
},
2626
});
2727

28-
t.is(cli.input[0], 'foo');
28+
t.is(cli.input.at(0), 'foo');
2929
t.true(cli.flags.fooBar);
3030
t.is(cli.flags.meow, 'dog');
3131
t.is(cli.flags.unicorn, 'cat');
@@ -92,32 +92,32 @@ test('single character flag casing should be preserved', t => {
9292
});
9393

9494
test('type inference', t => {
95-
t.is(meow({importMeta, argv: ['5']}).input[0], '5');
96-
t.is(meow({importMeta, argv: ['5']}, {input: 'string'}).input[0], '5');
95+
t.is(meow({importMeta, argv: ['5']}).input.at(0), '5');
96+
t.is(meow({importMeta, argv: ['5']}, {input: 'string'}).input.at(0), '5');
9797
t.is(meow({
9898
importMeta,
9999
argv: ['5'],
100100
inferType: true,
101-
}).input[0], 5);
101+
}).input.at(0), 5);
102102
t.is(meow({
103103
importMeta,
104104
argv: ['5'],
105105
inferType: true,
106106
flags: {foo: 'string'},
107-
}).input[0], 5);
107+
}).input.at(0), 5);
108108
t.is(meow({
109109
importMeta,
110110
argv: ['5'],
111111
inferType: true,
112112
flags: {
113113
foo: 'string',
114114
},
115-
}).input[0], 5);
115+
}).input.at(0), 5);
116116
t.is(meow({
117117
importMeta,
118118
argv: ['5'],
119119
input: 'number',
120-
}).input[0], 5);
120+
}).input.at(0), 5);
121121
});
122122

123123
test('booleanDefault: undefined, filter out unset boolean args', t => {
@@ -241,9 +241,9 @@ test('grouped flags work', t => {
241241
});
242242

243243
test('disable autoVersion/autoHelp if `cli.input.length > 0`', t => {
244-
t.is(meow({importMeta, argv: ['bar', '--version']}).input[0], 'bar');
245-
t.is(meow({importMeta, argv: ['bar', '--help']}).input[0], 'bar');
246-
t.is(meow({importMeta, argv: ['bar', '--version', '--help']}).input[0], 'bar');
244+
t.is(meow({importMeta, argv: ['bar', '--version']}).input.at(0), 'bar');
245+
t.is(meow({importMeta, argv: ['bar', '--help']}).input.at(0), 'bar');
246+
t.is(meow({importMeta, argv: ['bar', '--version', '--help']}).input.at(0), 'bar');
247247
});
248248

249249
test('supports `number` flag type', t => {

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"compilerOptions": {
77
"strict": true,
88
"jsx": "react",
9-
"target": "ES2020", // Node.js 14
9+
"target": "ES2021", // Node.js 16
1010
"lib": [
11-
"ES2020"
11+
"ES2021"
1212
],
1313
"module": "ES2020",
1414
"moduleResolution": "node",

0 commit comments

Comments
 (0)