Skip to content

Commit 629af48

Browse files
authoredMay 17, 2020
Update minimist-options and remove type coercion patch (#152)
1 parent 1c251e8 commit 629af48

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed
 

‎index.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
const path = require('path');
33
const buildParserOptions = require('minimist-options');
44
const parseArguments = require('yargs-parser');
5-
const camelCase = require('camelcase');
65
const camelCaseKeys = require('camelcase-keys');
76
const decamelizeKeys = require('decamelize-keys');
87
const trimNewlines = require('trim-newlines');
98
const redent = require('redent');
109
const readPkgUp = require('read-pkg-up');
1110
const hardRejection = require('hard-rejection');
1211
const normalizePackageData = require('normalize-package-data');
13-
const arrify = require('arrify');
1412

1513
// Prevent caching of this module so module.parent is always accurate
1614
delete require.cache[__filename];
@@ -69,7 +67,7 @@ const buildParserFlags = ({flags, booleanDefault}) =>
6967
}
7068

7169
if (flag.isMultiple) {
72-
flag.type = 'array';
70+
flag.type = flag.type ? `${flag.type}-array` : 'array';
7371
delete flag.isMultiple;
7472
}
7573

@@ -78,15 +76,6 @@ const buildParserFlags = ({flags, booleanDefault}) =>
7876
return parserFlags;
7977
}, {});
8078

81-
/**
82-
Convert to alternative syntax for coercing values to expected type, according to https://github.com/yargs/yargs-parser#requireyargs-parserargs-opts.
83-
*/
84-
const convertToTypedArrayOption = (arrayOption, flags) =>
85-
arrify(arrayOption).map(flagKey => ({
86-
key: flagKey,
87-
[flags[camelCase(flagKey, '-')].type || 'string']: true
88-
}));
89-
9079
const validateFlags = (flags, options) => {
9180
for (const [flagKey, flagValue] of Object.entries(options.flags)) {
9281
if (flagKey !== '--' && !flagValue.isMultiple && Array.isArray(flags[flagKey])) {
@@ -142,13 +131,6 @@ const meow = (helpText, options) => {
142131
};
143132
}
144133

145-
if (parserOptions.array !== undefined) {
146-
// `yargs` supports 'string|number|boolean' arrays,
147-
// but `minimist-options` only support 'string' as element type.
148-
// Open issue to add support to `minimist-options`: https://github.com/vadimdemedes/minimist-options/issues/18.
149-
parserOptions.array = convertToTypedArrayOption(parserOptions.array, options.flags);
150-
}
151-
152134
const {pkg} = options;
153135
const argv = parseArguments(options.argv, parserOptions);
154136
let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2);

‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@
4141
],
4242
"dependencies": {
4343
"@types/minimist": "^1.2.0",
44-
"arrify": "^2.0.1",
45-
"camelcase": "^6.0.0",
4644
"camelcase-keys": "^6.2.2",
4745
"decamelize-keys": "^1.1.0",
4846
"hard-rejection": "^2.1.0",
49-
"minimist-options": "^4.0.2",
47+
"minimist-options": "4.1.0",
5048
"normalize-package-data": "^2.5.0",
5149
"read-pkg-up": "^7.0.1",
5250
"redent": "^3.0.0",

‎test/test.js

+13
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,19 @@ test('single flag set more than once => throws', t => {
367367
}, {message: 'The flag --foo can only be set once.'});
368368
});
369369

370+
test('isMultiple - default to type string', t => {
371+
t.deepEqual(meow({
372+
argv: ['--foo=bar'],
373+
flags: {
374+
foo: {
375+
isMultiple: true
376+
}
377+
}
378+
}).flags, {
379+
foo: ['bar']
380+
});
381+
});
382+
370383
test('isMultiple - boolean flag', t => {
371384
t.deepEqual(meow({
372385
argv: ['--foo', '--foo=false'],

0 commit comments

Comments
 (0)
Please sign in to comment.