Repository: yargs/yargs-parser
Pull request #22 (2016-04-06 18:57:14)

Exclude tests from publication
This came up recently in https://github.com/yargs/yargs/issues/468#issuecomment-206442013.

Would be nice to trim the package size a bit by excluding tests, and I prefer whitelisting files in `package.json` over blacklisting files in `.npmignore`.

Here is the result of `npm pack` before and after this change:

```
# BEFORE
x package/package.json
x package/.npmignore
x package/README.md
x package/example.js
x package/index.js
x package/appveyor.yml
x package/.travis.yml
x package/lib/tokenize-arg-string.js
x package/test/tokenize-arg-string.js
x package/test/yargs-parser.js
x package/test/fixtures/settings.js
x package/test/fixtures/config.json
x package/test/fixtures/config.txt
x package/test/fixtures/nested_config.json
x package/LICENSE.txt

# AFTER
x package/package.json
x package/README.md
x package/index.js
x package/lib/tokenize-arg-string.js
x package/LICENSE.txt
```

coveralls: 
[![Coverage Status](https://coveralls.io/builds/5688592/badge)](https://coveralls.io/builds/5688592)

Coverage remained the same at 100.0% when pulling **5d8b364428036a759c612aec45c8e576942f4a8e on nexdrew:dont-publish-test** into **48b1e6a338f80417b3fd0fc3e39ae181332fdcb5 on yargs:master**.


Patch:
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index a399f75..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,5 +0,0 @@
-.nyc_output
-node_modules
-.DS_Store
-yargs-logo.png
-./test/fixtures/package.json
diff --git a/index.js b/index.js
index 834f8da..2594350 100644
--- a/index.js
+++ b/index.js
@@ -335,6 +335,11 @@ function parse (args, opts) {
       value = increment
     }
 
+    // Set normalized value when key is in 'normalize' and in 'arrays'
+    if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
+      value = path.normalize(val)
+    }
+
     var splitKey = key.split('.')
     setKey(argv, splitKey, value)
 
@@ -361,20 +366,18 @@ function parse (args, opts) {
       setKey(argv, x, value)
     })
 
-    var keys = [key].concat(flags.aliases[key] || [])
-    for (var i = 0, l = keys.length; i < l; i++) {
-      if (flags.normalize[keys[i]]) {
-        keys.forEach(function (key) {
-          argv.__defineSetter__(key, function (v) {
-            val = path.normalize(v)
-          })
-
-          argv.__defineGetter__(key, function () {
-            return typeof val === 'string' ? path.normalize(val) : val
-          })
+    // Set normalize getter and setter when key is in 'normalize' but isn't an array
+    if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
+      var keys = [key].concat(flags.aliases[key] || [])
+      keys.forEach(function (key) {
+        argv.__defineSetter__(key, function (v) {
+          val = path.normalize(v)
         })
-        break
-      }
+
+        argv.__defineGetter__(key, function () {
+          return typeof val === 'string' ? path.normalize(val) : val
+        })
+      })
     }
   }
 
diff --git a/package.json b/package.json
index c2429e4..228265f 100644
--- a/package.json
+++ b/package.json
@@ -34,5 +34,9 @@
   "dependencies": {
     "camelcase": "^2.1.1",
     "lodash.assign": "^4.0.6"
-  }
+  },
+  "files": [
+    "lib",
+    "index.js"
+  ]
 }


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index ca1476c..00e5b53 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -236,6 +236,19 @@ describe('yargs-parser', function () {
       a.s = ['', 'path', 'to', 'new', 'dir', '..', '..', ''].join(path.sep)
       a.s.should.equal(['', 'path', 'to', ''].join(path.sep))
     })
+
+    it('should normalize when key is also an array', function () {
+      var a = parser([ '-s', ['', 'tmp', '..', ''].join(path.sep), ['', 'path', 'to', 'new', 'dir', '..', '..', ''].join(path.sep) ], {
+        alias: {
+          s: ['save']
+        },
+        normalize: 's',
+        array: 's'
+      })
+      var expected = [path.sep, ['', 'path', 'to', ''].join(path.sep)]
+      a.should.have.property('s').and.deep.equal(expected)
+      a.should.have.property('save').and.deep.equal(expected)
+    })
   })
 
   describe('alias', function () {