yargs 8.0.0-candidate.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,22 +15,33 @@ function getPathToDefaultConfig (cwd, pathToExtend) {
15
15
  return path.resolve(cwd, pathToExtend)
16
16
  }
17
17
 
18
- function applyExtends (config, cwd, subKey) {
18
+ function applyExtends (config, cwd) {
19
19
  var defaultConfig = {}
20
20
 
21
21
  if (config.hasOwnProperty('extends')) {
22
- var pathToDefault = getPathToDefaultConfig(cwd, config.extends)
22
+ if (typeof config.extends !== 'string') return defaultConfig
23
+ var isPath = /\.json$/.test(config.extends)
24
+ var pathToDefault = null
25
+ if (!isPath) {
26
+ try {
27
+ pathToDefault = require.resolve(config.extends)
28
+ } catch (err) {
29
+ // most likely this simply isn't a module.
30
+ }
31
+ } else {
32
+ pathToDefault = getPathToDefaultConfig(cwd, config.extends)
33
+ }
34
+ // maybe the module uses key for some other reason,
35
+ // err on side of caution.
36
+ if (!pathToDefault && !isPath) return config
23
37
 
24
38
  checkForCircularExtends(pathToDefault)
25
39
 
26
40
  previouslyVisitedConfigs.push(pathToDefault)
27
- delete config.extends
28
41
 
29
- defaultConfig = JSON.parse(fs.readFileSync(pathToDefault, 'utf8'))
30
- if (subKey) {
31
- defaultConfig = defaultConfig[subKey] || {}
32
- }
33
- defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), subKey)
42
+ defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
43
+ delete config.extends
44
+ defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
34
45
  }
35
46
 
36
47
  previouslyVisitedConfigs = []
package/lib/command.js CHANGED
@@ -15,6 +15,8 @@ module.exports = function (yargs, usage, validation) {
15
15
  var defaultCommand
16
16
  self.addHandler = function (cmd, description, builder, handler) {
17
17
  var aliases = []
18
+ handler = handler || function () {}
19
+
18
20
  if (Array.isArray(cmd)) {
19
21
  aliases = cmd.slice(1)
20
22
  cmd = cmd[0]
package/lib/validation.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const objFilter = require('./obj-filter')
2
+ const specialKeys = ['$0', '--', '_']
2
3
 
3
4
  // validation-type-stuff, missing params,
4
5
  // bad implications, custom checks.
@@ -131,7 +132,7 @@ module.exports = function (yargs, usage, y18n) {
131
132
  })
132
133
 
133
134
  Object.keys(argv).forEach(function (key) {
134
- if (key !== '$0' && key !== '_' &&
135
+ if (specialKeys.indexOf(key) === -1 &&
135
136
  !descriptions.hasOwnProperty(key) &&
136
137
  !demandedOptions.hasOwnProperty(key) &&
137
138
  !positionalMap.hasOwnProperty(key) &&
@@ -167,7 +168,7 @@ module.exports = function (yargs, usage, y18n) {
167
168
  if (!Object.keys(options.choices).length) return
168
169
 
169
170
  Object.keys(argv).forEach(function (key) {
170
- if (key !== '$0' && key !== '_' &&
171
+ if (specialKeys.indexOf(key) === -1 &&
171
172
  options.choices.hasOwnProperty(key)) {
172
173
  [].concat(argv[key]).forEach(function (value) {
173
174
  // TODO case-insensitive configurability
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "8.0.0-candidate.0",
3
+ "version": "8.0.2",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.js",
6
6
  "files": [
@@ -12,19 +12,19 @@
12
12
  "LICENSE"
13
13
  ],
14
14
  "dependencies": {
15
- "camelcase": "^3.0.0",
15
+ "camelcase": "^4.1.0",
16
16
  "cliui": "^3.2.0",
17
17
  "decamelize": "^1.1.1",
18
18
  "get-caller-file": "^1.0.1",
19
- "os-locale": "^1.4.0",
20
- "read-pkg-up": "^1.0.1",
19
+ "os-locale": "^2.0.0",
20
+ "read-pkg-up": "^2.0.0",
21
21
  "require-directory": "^2.1.1",
22
22
  "require-main-filename": "^1.0.1",
23
23
  "set-blocking": "^2.0.0",
24
- "string-width": "^1.0.2",
25
- "which-module": "^1.0.0",
24
+ "string-width": "^2.0.0",
25
+ "which-module": "^2.0.0",
26
26
  "y18n": "^3.2.1",
27
- "yargs-parser": "^5.0.0"
27
+ "yargs-parser": "^7.0.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "chai": "^3.4.1",
@@ -35,11 +35,12 @@
35
35
  "es6-promise": "^4.0.2",
36
36
  "hashish": "0.0.4",
37
37
  "mocha": "^3.0.1",
38
- "nyc": "^10.0.0",
38
+ "nyc": "^10.3.0",
39
39
  "rimraf": "^2.5.0",
40
40
  "standard": "^8.6.0",
41
- "standard-version": "^3.0.0",
42
- "which": "^1.2.9"
41
+ "standard-version": "^4.2.0",
42
+ "which": "^1.2.9",
43
+ "yargs-test-extends": "^1.0.1"
43
44
  },
44
45
  "scripts": {
45
46
  "pretest": "standard",
@@ -69,12 +70,5 @@
69
70
  "license": "MIT",
70
71
  "engine": {
71
72
  "node": ">=0.10"
72
- },
73
- "greenkeeper": {
74
- "ignore": [
75
- "string-width",
76
- "read-pkg-up",
77
- "camelcase"
78
- ]
79
73
  }
80
74
  }
package/yargs.js CHANGED
@@ -126,7 +126,6 @@ function Yargs (processArgs, cwd, parentRequire) {
126
126
  command = command ? command.reset() : Command(self, usage, validation)
127
127
  if (!completion) completion = Completion(self, usage, command)
128
128
 
129
- if (!strictGlobal) strict = false
130
129
  completionCommand = null
131
130
  output = ''
132
131
  exitError = null
@@ -479,7 +478,7 @@ function Yargs (processArgs, cwd, parentRequire) {
479
478
 
480
479
  // If an object exists in the key, add it to options.configObjects
481
480
  if (obj[key] && typeof obj[key] === 'object') {
482
- conf = applyExtends(obj[key], path || cwd, key)
481
+ conf = applyExtends(obj[key], path || cwd)
483
482
  options.configObjects = (options.configObjects || []).concat(conf)
484
483
  }
485
484
 
@@ -695,11 +694,9 @@ function Yargs (processArgs, cwd, parentRequire) {
695
694
  }
696
695
 
697
696
  var strict = false
698
- var strictGlobal = false
699
- self.strict = function (global) {
700
- argsert('[boolean]', [global], arguments.length)
701
- strict = true
702
- strictGlobal = global !== false
697
+ self.strict = function (enabled) {
698
+ argsert('[boolean]', [enabled], arguments.length)
699
+ strict = enabled !== false
703
700
  return self
704
701
  }
705
702
  self.getStrict = function () {
@@ -1005,7 +1002,7 @@ function Yargs (processArgs, cwd, parentRequire) {
1005
1002
 
1006
1003
  // recommend a command if recommendCommands() has
1007
1004
  // been enabled, and no commands were found to execute
1008
- if (recommendCommands && firstUnknownCommand) {
1005
+ if (recommendCommands && firstUnknownCommand && !argv[helpOpt]) {
1009
1006
  validation.recommendCommands(firstUnknownCommand, handlerKeys)
1010
1007
  }
1011
1008
  }