Skip to content

Commit 21b5c91

Browse files
removes null from booleanDefault type
- this was introduced in sindresorhus#77, likely due to compatibility with minimist - `booleanDefault: null` causes minimist-options to error - even in 2019, this was a confusing type: sindresorhus#116 (comment)
1 parent 96d6f6b commit 21b5c91

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would
213213

214214
##### booleanDefault
215215

216-
Type: `boolean | null | undefined`\
216+
Type: `boolean | undefined`\
217217
Default: `false`
218218

219219
Value of `boolean` flags not defined in `argv`.

source/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const buildParserFlags = ({flags, booleanDefault}: ParsedOptions): ParserFlags =
2929
? (flag.type ? `${flag.type}-array` as const : 'array' as const)
3030
: flag.type,
3131
default: shouldUseBooleanDefault
32-
? (flag.isMultiple ? [booleanDefault] : booleanDefault) // TODO: can this be null?
32+
? (flag.isMultiple ? [booleanDefault] : booleanDefault)
3333
: (flag.default ?? (flag.isMultiple ? [] : undefined)),
3434
alias: aliases,
3535
};

source/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ export type Options<Flags extends AnyFlags = AnyFlags> = {
296296
//}
297297
```
298298
*/
299-
// eslint-disable-next-line @typescript-eslint/ban-types
300-
readonly booleanDefault?: boolean | null | undefined;
299+
readonly booleanDefault?: boolean;
301300

302301
// TODO: Remove this in meow 14.
303302
/**

test/test.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import path from 'node:path';
21
import process from 'node:process';
32
import test from 'ava';
43
import indentString from 'indent-string';
5-
import {execa} from 'execa';
6-
import {readPackage} from 'read-pkg';
74
import meow from '../source/index.js';
8-
import {spawnFixture, __dirname} from './_utils.js';
5+
import {spawnFixture, __dirname, _meowThrows} from './_utils.js';
96

107
const importMeta = import.meta;
8+
const meowThrows = _meowThrows(importMeta);
9+
1110
const NODE_MAJOR_VERSION = process.versions.node.split('.').at(0); // eslint-disable-line @typescript-eslint/naming-convention
1211

1312
test('return object', t => {
@@ -40,27 +39,11 @@ test('return object', t => {
4039
});
4140
});
4241

43-
test('spawn cli and show version', async t => {
44-
const pkg = await readPackage();
45-
const {stdout} = await spawnFixture(['--version']);
46-
t.is(stdout, pkg.version);
47-
});
48-
4942
test('spawn cli and disabled autoVersion and autoHelp', async t => {
5043
const {stdout} = await spawnFixture(['--version', '--help']);
5144
t.is(stdout, 'version\nhelp\nmeow\ncamelCaseOption');
5245
});
5346

54-
test('spawn cli and disabled autoVersion', async t => {
55-
const {stdout} = await spawnFixture(['--version', '--no-auto-version']);
56-
t.is(stdout, 'version\nautoVersion\nmeow\ncamelCaseOption');
57-
});
58-
59-
test('spawn cli and not show version', async t => {
60-
const {stdout} = await spawnFixture(['--version=beta']);
61-
t.is(stdout, 'version\nmeow\ncamelCaseOption');
62-
});
63-
6447
test('spawn cli and test input', async t => {
6548
const {stdout} = await spawnFixture(['-u', 'cat']);
6649
t.is(stdout, 'unicorn\nmeow\ncamelCaseOption');
@@ -88,9 +71,7 @@ test('setting pkg.bin should work', t => {
8871
t.like(cli, {
8972
pkg: {
9073
name: 'browser-sync',
91-
bin: {
92-
'browser-sync': './bin/browser-sync.js',
93-
},
74+
bin: './bin/browser-sync.js',
9475
},
9576
version: undefined,
9677
});
@@ -162,6 +143,23 @@ test('booleanDefault: undefined, filter out unset boolean args', t => {
162143
});
163144
});
164145

146+
test('booleanDefault: null throws', meowThrows, {
147+
argv: ['--foo'],
148+
booleanDefault: null,
149+
flags: {
150+
foo: {
151+
type: 'boolean',
152+
},
153+
bar: {
154+
type: 'boolean',
155+
},
156+
baz: {
157+
type: 'boolean',
158+
default: false,
159+
},
160+
},
161+
}, {message: 'Expected "foo" default value to be of type "boolean", got "null"'});
162+
165163
test('boolean args are false by default', t => {
166164
const cli = meow({
167165
importMeta,

0 commit comments

Comments
 (0)