Skip to content

Commit 76cee1f

Browse files
authored
fix: environment variables should take precedence over config file (#81)
BREAKING CHANGE: environment variables will now override config files (args, env, config-file, config-object)
1 parent 924b014 commit 76cee1f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ function parse (args, opts) {
273273

274274
// order of precedence:
275275
// 1. command line arg
276-
// 2. value from config file
277-
// 3. value from config objects
278-
// 4. value from env var
276+
// 2. value from env var
277+
// 3. value from config file
278+
// 4. value from config objects
279279
// 5. configured default value
280280
applyEnvVars(argv, true) // special case: check env vars that point to config file
281+
applyEnvVars(argv, false)
281282
setConfig(argv)
282283
setConfigObjects()
283-
applyEnvVars(argv, false)
284284
applyDefaultsAndAliases(argv, flags.aliases, defaults)
285285
applyCoercions(argv)
286286

test/yargs-parser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ describe('yargs-parser', function () {
16971697
})
16981698

16991699
var jsonPath = path.resolve(__dirname, './fixtures/config.json')
1700-
it('should prefer config file value over env var', function () {
1700+
it('should prefer environment variables over config file', function () {
17011701
process.env.CFG_HERP = 'zerp'
17021702
var result = parser(['--cfg', jsonPath], {
17031703
envPrefix: 'CFG',
@@ -1708,7 +1708,7 @@ describe('yargs-parser', function () {
17081708
}
17091709
})
17101710

1711-
result.herp.should.equal('derp')
1711+
result.herp.should.equal('zerp')
17121712
})
17131713

17141714
it('should support an env var value as config file option', function () {

0 commit comments

Comments
 (0)