Repository: yargs/yargs-parser
Pull request #236 (2020-02-09 07:14:56)

feat!: boolean arguments will not be collected into an implicit array
This reverts behavior to match yargs@14. If an argument is configured as a `bool` we will not coerce it into an array.

@SimenB could I get you to try out this branch if you have a moment.

Refs: https://github.com/facebook/jest/issues/9517
BREAKING CHANGE: this reverts parsing behavior of booleans to yargs@14

SimenB: Yeah, this works as expected. Thanks!

Patch:
diff --git a/index.js b/index.js
index 0e2381d..658b679 100644
--- a/index.js
+++ b/index.js
@@ -713,7 +713,11 @@ function parse (args, opts) {
       }
     } else if (o[key] === undefined && isTypeArray) {
       o[key] = isValueArray ? value : [value]
-    } else if (duplicate && !(o[key] === undefined || checkAllAliases(key, flags.counts))) {
+    } else if (duplicate && !(
+      o[key] === undefined ||
+        checkAllAliases(key, flags.counts) ||
+        checkAllAliases(key, flags.bools)
+    )) {
       o[key] = [ o[key], value ]
     } else {
       o[key] = value
@@ -823,7 +827,7 @@ function parse (args, opts) {
     // e.g. '-a-'
     const flagEndingInHyphen = /^-+([^=]+?)-$/
     // e.g. '-abc123'
-    const flagEndingInDigits = /^-+([^=]+?)\d+$/
+    const flagEndingInDigits = /^-+([^=]+?\d+)$/
     // e.g. '-a/usr/local'
     const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/
     // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
diff --git a/package.json b/package.json
index 1b3f7b0..c9cdda9 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,10 @@
   "description": "the mighty option parser used by yargs",
   "main": "index.js",
   "scripts": {
+    "fix": "standard --fix",
     "test": "c8 --reporter=text --reporter=html  mocha test/*.js",
     "posttest": "standard",
-    "coverage": "c8 report --reporter=text-lcov | coveralls",
-    "release": "standard-version"
+    "coverage": "c8 report --reporter=text-lcov | coveralls"
   },
   "repository": {
     "url": "git@github.com:yargs/yargs-parser.git"
@@ -29,9 +29,8 @@
     "c8": "^7.0.1",
     "chai": "^4.2.0",
     "coveralls": "^3.0.2",
-    "mocha": "^5.2.0",
-    "standard": "^12.0.1",
-    "standard-version": "^6.0.0"
+    "mocha": "^7.0.0",
+    "standard": "^12.0.1"
   },
   "dependencies": {
     "camelcase": "^5.0.0",
diff --git a/renovate.json b/renovate.json
new file mode 100644
index 0000000..f6dd45e
--- /dev/null
+++ b/renovate.json
@@ -0,0 +1,8 @@
+{
+  "extends": [
+    "config:base"
+  ],
+  "pinVersions": false,
+  "rebaseStalePrs": true,
+  "gitAuthor": null
+}


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index ebe0c89..30a0c6f 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -2557,7 +2557,8 @@ describe('yargs-parser', function () {
           })
         })
         describe('type=boolean', function () {
-          it('[-x true -x true -x false] => [true, true, false]', function () {
+          // in the casse of boolean arguments, only the last argument is used:
+          it('[-x true -x true -x false] => false', function () {
             var parsed = parser('-x true -x true -x false', {
               boolean: ['x'],
               configuration: {
@@ -2565,7 +2566,7 @@ describe('yargs-parser', function () {
                 'flatten-duplicate-arrays': true
               }
             })
-            parsed['x'].should.deep.equal([true, true, false])
+            parsed['x'].should.deep.equal(false)
           })
         })
       })
@@ -2605,7 +2606,7 @@ describe('yargs-parser', function () {
           })
         })
         describe('type=boolean', function () {
-          it('[-x true -x true -x false] => [true, true, false]', function () {
+          it('[-x true -x true -x false] => false', function () {
             var parsed = parser('-x true -x true -x false', {
               boolean: ['x'],
               configuration: {
@@ -2613,7 +2614,7 @@ describe('yargs-parser', function () {
                 'flatten-duplicate-arrays': false
               }
             })
-            parsed['x'].should.deep.equal([true, true, false])
+            parsed['x'].should.deep.equal(false)
           })
         })
       })
@@ -3011,6 +3012,22 @@ describe('yargs-parser', function () {
         })
       })
     })
+
+    // See: https://github.com/yargs/yargs-parser/issues/231
+    it('should collect unknown options terminated with digit', function () {
+      const argv = parser('--known-arg=1 --num2', {
+        alias: { 'num': ['n'] },
+        number: ['known-arg'],
+        configuration: {
+          'unknown-options-as-args': true
+        }
+      })
+      argv.should.deep.equal({
+        _: ['--num2'],
+        'known-arg': 1,
+        'knownArg': 1
+      })
+    })
   })
 
   // addresses: https://github.com/yargs/yargs-parser/issues/41
@@ -3514,4 +3531,12 @@ describe('yargs-parser', function () {
       parse.toString.should.equal(66)
     })
   })
+
+  // See: https://github.com/facebook/jest/issues/9517
+  it('does not collect arguments configured as booleans into implicit array', () => {
+    var parse = parser(['--infinite', 'true', '--infinite', 'true', '--no-infinite'], {
+      boolean: 'infinite'
+    })
+    parse.infinite.should.equal(false)
+  })
 })