diff --git a/@commitlint/load/fixtures/parser-preset-conventional-without-factory/commitlint.config.js b/@commitlint/load/fixtures/parser-preset-conventional-without-factory/commitlint.config.js new file mode 100644 index 0000000000..46aa41e38f --- /dev/null +++ b/@commitlint/load/fixtures/parser-preset-conventional-without-factory/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + parserPreset: 'conventional-changelog-conventionalcommits' +}; diff --git a/@commitlint/load/fixtures/parser-preset-conventional-without-factory/package.json b/@commitlint/load/fixtures/parser-preset-conventional-without-factory/package.json new file mode 100644 index 0000000000..79b0cb69fe --- /dev/null +++ b/@commitlint/load/fixtures/parser-preset-conventional-without-factory/package.json @@ -0,0 +1,7 @@ +{ + "name": "parser-preset-conventional-without-factory", + "version": "1.0.0", + "devDependencies": { + "conventional-changelog-conventionalcommits": "4.1.0" + } +} diff --git a/@commitlint/load/src/index.js b/@commitlint/load/src/index.js index 23030ce3d9..e3f74d0d27 100644 --- a/@commitlint/load/src/index.js +++ b/@commitlint/load/src/index.js @@ -137,9 +137,17 @@ async function loadParserOpts(parserName, pendingParser) { startsWith(parserName, 'conventional-changelog-') ) { return await new Promise(resolve => { - parser.parserOpts((_, opts) => { + const result = parser.parserOpts((_, opts) => { resolve(opts.parserOpts); }); + + // If result has data or a promise, the parser doesn't support factory-init + // due to https://github.com/nodejs/promises-debugging/issues/16 it just quits, so let's use this fallback + if (result) { + Promise.resolve(result).then(opts => { + resolve(opts.parserOpts); + }); + } }); } diff --git a/@commitlint/load/src/index.test.js b/@commitlint/load/src/index.test.js index 67eb5bd2c3..35c35e384f 100644 --- a/@commitlint/load/src/index.test.js +++ b/@commitlint/load/src/index.test.js @@ -368,3 +368,17 @@ test('recursive resolves parser preset from conventional atom', async t => { t.is(typeof actual.parserPreset.parserOpts, 'object'); t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(:.*?:) (.*)$/); }); + +test('resolves parser preset from conventional commits without factory support', async t => { + const cwd = await npm.bootstrap( + 'fixtures/parser-preset-conventional-without-factory' + ); + const actual = await load({}, {cwd}); + + t.is(actual.parserPreset.name, 'conventional-changelog-conventionalcommits'); + t.is(typeof actual.parserPreset.parserOpts, 'object'); + t.deepEqual( + actual.parserPreset.parserOpts.headerPattern, + /^(\w*)(?:\((.*)\))?!?: (.*)$/ + ); +});