diff --git a/@commitlint/load/fixtures/recursive-parser-preset-factory/commitlint.config.js b/@commitlint/load/fixtures/recursive-parser-preset-factory/commitlint.config.js new file mode 100644 index 0000000000..62804e2b03 --- /dev/null +++ b/@commitlint/load/fixtures/recursive-parser-preset-factory/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./first-extended'] +}; diff --git a/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/index.js b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/index.js new file mode 100644 index 0000000000..6ec50f348e --- /dev/null +++ b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/index.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['./second-extended'] +}; diff --git a/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/conventional-changelog-factory.js b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/conventional-changelog-factory.js new file mode 100644 index 0000000000..7ac0b81719 --- /dev/null +++ b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/conventional-changelog-factory.js @@ -0,0 +1,10 @@ +module.exports = Promise.resolve().then( + () => + function factory() { + return { + parserOpts: { + headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/ + } + }; + } +); diff --git a/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/index.js b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/index.js new file mode 100644 index 0000000000..bb423b3f4e --- /dev/null +++ b/@commitlint/load/fixtures/recursive-parser-preset-factory/first-extended/second-extended/index.js @@ -0,0 +1,3 @@ +module.exports = { + parserPreset: './conventional-changelog-factory' +}; diff --git a/@commitlint/load/src/index.js b/@commitlint/load/src/index.js index 6845172940..0167c53ded 100644 --- a/@commitlint/load/src/index.js +++ b/@commitlint/load/src/index.js @@ -30,12 +30,12 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => { pick(config, 'extends', 'plugins', 'ignores', 'defaultIgnores') ); - // Resolve parserPreset key + // Resolve parserPreset key from flat-non-extended config if (typeof config.parserPreset === 'string') { const resolvedParserPreset = resolveFrom(base, config.parserPreset); let resolvedParserConfig = await require(resolvedParserPreset); - // Resolve loaded parser preset if its a factory + // Resolve loaded parser preset factory if (typeof resolvedParserConfig === 'function') { resolvedParserConfig = await resolvedParserConfig(); } @@ -61,8 +61,14 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => { typeof preset.parserPreset.parserOpts === 'object' && typeof preset.parserPreset.parserOpts.then === 'function' ) { - preset.parserPreset.parserOpts = (await preset.parserPreset - .parserOpts).parserOpts; + let parserPreset = await preset.parserPreset.parserOpts; + + // Resolve loaded parser preset factory from extended config + if (typeof parserPreset === 'function') { + parserPreset = await parserPreset(); + } + + preset.parserPreset.parserOpts = parserPreset.parserOpts; } // Resolve config-relative formatter module diff --git a/@commitlint/load/src/index.test.js b/@commitlint/load/src/index.test.js index c2b16719fa..14c6398436 100644 --- a/@commitlint/load/src/index.test.js +++ b/@commitlint/load/src/index.test.js @@ -228,6 +228,16 @@ test('recursive extends with parserPreset', async t => { ); }); +test('recursive extends with parserPreset factory', async t => { + const cwd = await git.bootstrap('fixtures/recursive-parser-preset-factory'); + const actual = await load({}, {cwd}); + + t.is(actual.parserPreset.name, './conventional-changelog-factory'); + t.deepEqual(actual.parserPreset.parserOpts, { + headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/ + }); +}); + test('ignores unknow keys', async t => { const cwd = await git.bootstrap('fixtures/trash-file'); const actual = await load({}, {cwd});