Skip to content

Commit 11691a6

Browse files
genepaulbcoe
authored andcommitted
feat: extend *.rc files in addition to json (#1080)
1 parent a04678c commit 11691a6

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/apply-extends.js

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

2222
if (config.hasOwnProperty('extends')) {
2323
if (typeof config.extends !== 'string') return defaultConfig
24-
const isPath = /\.json$/.test(config.extends)
24+
const isPath = /\.json|\..*rc$/.test(config.extends)
2525
let pathToDefault = null
2626
if (!isPath) {
2727
try {

test/fixtures/extends/.myotherrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./config_1.json",
3+
"c": 201
4+
}

test/fixtures/extends/.myrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./.myotherrc",
3+
"a": 5
4+
}

test/yargs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,20 @@ describe('yargs dsl tests', () => {
12841284
argv.a.should.equal(2)
12851285
argv.extends.should.equal('batman')
12861286
})
1287+
1288+
it('allows files with .*rc extension to be extended', () => {
1289+
const argv = yargs()
1290+
.config({
1291+
extends: './test/fixtures/extends/.myrc',
1292+
a: 3
1293+
})
1294+
.argv
1295+
1296+
argv.a.should.equal(3)
1297+
argv.b.should.equal(22)
1298+
argv.c.should.equal(201)
1299+
argv.z.should.equal(15)
1300+
})
12871301
})
12881302
})
12891303

0 commit comments

Comments
 (0)