Skip to content

Commit

Permalink
refactor!: remove package.json-based parserConfiguration (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 27, 2019
1 parent 9adf22e commit 0d3642b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 34 deletions.
7 changes: 0 additions & 7 deletions test/fixtures/configured-bin.js

This file was deleted.

5 changes: 4 additions & 1 deletion test/fixtures/no-extension
Expand Up @@ -4,4 +4,7 @@

var parser = require('../../yargs.js')(process.argv.slice(2))

console.log(parser.argv)
console.log(parser.parserConfiguration({
'dot-notation': false,
'boolean-negation': false
}).argv)
5 changes: 4 additions & 1 deletion test/fixtures/no-require-main.js
Expand Up @@ -7,4 +7,7 @@ delete require.main

var parser = require('../../yargs.js')(process.argv.slice(2), undefined, require)

console.log(parser.argv)
console.log(parser.parserConfiguration({
'dot-notation': false,
'boolean-negation': false
}).argv)
6 changes: 5 additions & 1 deletion test/fixtures/normal-bin.js
@@ -1,6 +1,10 @@
#!/usr/bin/env node
var argv = require('./yargs/index.js')
var argv = require('../../index.js')
.help('help')
.version()
.parserConfiguration({
'dot-notation': false,
'boolean-negation': false
})
.argv
console.log(argv)
5 changes: 2 additions & 3 deletions test/fixtures/package.json
Expand Up @@ -3,8 +3,7 @@
"repository": {
"type": "svn"
},
"yargs": {
"dot-notation": false,
"boolean-negation": false
"blerg": {
"dot-notation": false
}
}
4 changes: 4 additions & 0 deletions test/fixtures/symlink-bin.js
Expand Up @@ -2,5 +2,9 @@
var argv = require('./yargs-symlink/index.js')
.help('help')
.version()
.parserConfiguration({
'dot-notation': false,
'boolean-negation': false
})
.argv
console.log(argv)
12 changes: 0 additions & 12 deletions test/integration.js
Expand Up @@ -191,18 +191,6 @@ describe('integration tests', () => {
return done()
})
})

it('is overridden by yargs.parserConfiguration', (done) => {
testCmd('./configured-bin.js', [ '--foo.bar', '--no-baz' ], (code, stdout) => {
if (code) {
return done(new Error(`cmd exited with code ${code}`))
}

stdout.should.not.match(/foo\.bar/)
stdout.should.match(/noBaz/)
return done()
})
})
})

after(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/yargs.js
Expand Up @@ -1678,7 +1678,7 @@ describe('yargs dsl tests', () => {

it('allows an alternative cwd to be specified', () => {
const argv = yargs('--foo a')
.pkgConf('yargs', './test/fixtures')
.pkgConf('blerg', './test/fixtures')
.parse()

argv.foo.should.equal('a')
Expand Down
10 changes: 2 additions & 8 deletions yargs.js
@@ -1,4 +1,5 @@
'use strict'

const argsert = require('./lib/argsert')
const fs = require('fs')
const Command = require('./lib/command')
Expand Down Expand Up @@ -603,7 +604,7 @@ function Yargs (processArgs, cwd, parentRequire) {

const demand = opt.demand || opt.required || opt.require

// deprecated, use 'demandOption' instead
// A required option can be specified via "demand: true".
if (demand) {
self.demand(key, demand)
}
Expand Down Expand Up @@ -1032,13 +1033,6 @@ function Yargs (processArgs, cwd, parentRequire) {
options.__ = y18n.__
options.configuration = self.getParserConfiguration()

// Deprecated
let pkgConfig = pkgUp()['yargs']
if (pkgConfig) {
console.warn('Configuring yargs through package.json is deprecated and will be removed in a future major release, please use the JS API instead.')
options.configuration = Object.assign({}, pkgConfig, options.configuration)
}

const parsed = Parser.detailed(args, options)
let argv = parsed.argv
if (parseContext) argv = Object.assign({}, argv, parseContext)
Expand Down

0 comments on commit 0d3642b

Please sign in to comment.