Skip to content

Commit

Permalink
fix: replace minimist with mri to avoid number conversion issue
Browse files Browse the repository at this point in the history
Previously "npm makes aurelia 123" will fail because minimist converts
string "123" into number 123, this is very annoying. Switch to mri to
bypass this unwanted feature. Thank @kalle for the bug report.
  • Loading branch information
3cp committed Mar 6, 2021
1 parent ca0727b commit c1b5cf6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/get-opts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* eslint-disable no-console */
const minimist = require('minimist');
const mri = require('mri');
const camelCase = require('lodash.camelcase');

module.exports = function(argv, help = '') {
const options = minimist(argv, {
const options = mri(argv, {
alias: {s: 'select', h: 'help'},
string: ['select'],
boolean: ['help', 'here']
boolean: ['help', 'here'],
default: {
help: false,
here: false
}
});

if (options.help) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"isutf8": "^3.1.1",
"lodash.camelcase": "^4.3.0",
"lodash.mergewith": "^4.6.2",
"minimist": "^1.2.5",
"mock-fs": "^4.13.0",
"mri": "^1.1.6",
"nyc": "^15.1.0",
"sisteransi": "^1.0.5",
"standard-changelog": "^2.0.27",
Expand Down
10 changes: 10 additions & 0 deletions test/get-opts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ test('getOpts gets predefined properties', t => {
here: false
});

// minimist converts "123" to number 123.
// We switched to mri to avoid that issue.
t.deepEqual(getOpts(['a', '123']), {
supplier: 'a',
predefinedProperties: {name: '123'},
preselectedFeatures: [],
unattended: false,
here: false
});

t.deepEqual(getOpts(['bitbucket:name/a', 'app', '--foo-bar', 'loo']), {
supplier: 'bitbucket:name/a',
predefinedProperties: {name: 'app', 'foo-bar': 'loo', 'fooBar': 'loo'},
Expand Down

0 comments on commit c1b5cf6

Please sign in to comment.