Skip to content

Commit

Permalink
fix: support merging deeply nested configuration (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored and bcoe committed Sep 12, 2019
1 parent a05a49c commit bae66fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/apply-extends.js
Expand Up @@ -56,7 +56,7 @@ function applyExtends (config, cwd, mergeExtends) {

defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
delete config.extends
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), mergeExtends)
}

previouslyVisitedConfigs = []
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/extends/config_deep_2.json
@@ -0,0 +1,7 @@
{
"extends": "./config_deep.json",
"a": {
"b": 12,
"g": 1
}
}
17 changes: 17 additions & 0 deletions test/yargs.js
Expand Up @@ -1402,6 +1402,23 @@ describe('yargs dsl tests', () => {
argv.test.yes.should.equal(1)
})

it('deep merges multiple configs when extending when deep-merge-config=true', () => {
const argv = yargs()
.parserConfiguration({ 'deep-merge-config': true })
.config({
extends: './test/fixtures/extends/config_deep_2.json',
a: {
g: 3
}
})
.parse()

argv.test.yes.should.equal(1)
argv.a.b.should.equal(12)
argv.a.c.should.equal(12)
argv.a.g.should.equal(3)
})

it('does not deep merge objects by default', () => {
const argv = yargs()
.config({
Expand Down

0 comments on commit bae66fe

Please sign in to comment.