Skip to content

Commit bae66fe

Browse files
soulgaloreBenjamin E. Coe
authored andcommitted
fix: support merging deeply nested configuration (#1423)
1 parent a05a49c commit bae66fe

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎lib/apply-extends.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function applyExtends (config, cwd, mergeExtends) {
5656

5757
defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
5858
delete config.extends
59-
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
59+
defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), mergeExtends)
6060
}
6161

6262
previouslyVisitedConfigs = []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./config_deep.json",
3+
"a": {
4+
"b": 12,
5+
"g": 1
6+
}
7+
}

‎test/yargs.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,23 @@ describe('yargs dsl tests', () => {
14021402
argv.test.yes.should.equal(1)
14031403
})
14041404

1405+
it('deep merges multiple configs when extending when deep-merge-config=true', () => {
1406+
const argv = yargs()
1407+
.parserConfiguration({ 'deep-merge-config': true })
1408+
.config({
1409+
extends: './test/fixtures/extends/config_deep_2.json',
1410+
a: {
1411+
g: 3
1412+
}
1413+
})
1414+
.parse()
1415+
1416+
argv.test.yes.should.equal(1)
1417+
argv.a.b.should.equal(12)
1418+
argv.a.c.should.equal(12)
1419+
argv.a.g.should.equal(3)
1420+
})
1421+
14051422
it('does not deep merge objects by default', () => {
14061423
const argv = yargs()
14071424
.config({

0 commit comments

Comments
 (0)