Skip to content

Commit

Permalink
fix(load): add support for non-factory conventional parsers (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Oct 22, 2019
1 parent 0382070 commit 3ed8009
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
parserPreset: 'conventional-changelog-conventionalcommits'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "parser-preset-conventional-without-factory",
"version": "1.0.0",
"devDependencies": {
"conventional-changelog-conventionalcommits": "4.1.0"
}
}
10 changes: 9 additions & 1 deletion @commitlint/load/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});
}

Expand Down
14 changes: 14 additions & 0 deletions @commitlint/load/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*)(?:\((.*)\))?!?: (.*)$/
);
});

0 comments on commit 3ed8009

Please sign in to comment.