Skip to content

Commit 3ed8009

Browse files
authored
fix(load): add support for non-factory conventional parsers (#839)
1 parent 0382070 commit 3ed8009

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
parserPreset: 'conventional-changelog-conventionalcommits'
3+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "parser-preset-conventional-without-factory",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"conventional-changelog-conventionalcommits": "4.1.0"
6+
}
7+
}

@commitlint/load/src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ async function loadParserOpts(parserName, pendingParser) {
137137
startsWith(parserName, 'conventional-changelog-')
138138
) {
139139
return await new Promise(resolve => {
140-
parser.parserOpts((_, opts) => {
140+
const result = parser.parserOpts((_, opts) => {
141141
resolve(opts.parserOpts);
142142
});
143+
144+
// If result has data or a promise, the parser doesn't support factory-init
145+
// due to https://github.com/nodejs/promises-debugging/issues/16 it just quits, so let's use this fallback
146+
if (result) {
147+
Promise.resolve(result).then(opts => {
148+
resolve(opts.parserOpts);
149+
});
150+
}
143151
});
144152
}
145153

@commitlint/load/src/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,17 @@ test('recursive resolves parser preset from conventional atom', async t => {
368368
t.is(typeof actual.parserPreset.parserOpts, 'object');
369369
t.deepEqual(actual.parserPreset.parserOpts.headerPattern, /^(:.*?:) (.*)$/);
370370
});
371+
372+
test('resolves parser preset from conventional commits without factory support', async t => {
373+
const cwd = await npm.bootstrap(
374+
'fixtures/parser-preset-conventional-without-factory'
375+
);
376+
const actual = await load({}, {cwd});
377+
378+
t.is(actual.parserPreset.name, 'conventional-changelog-conventionalcommits');
379+
t.is(typeof actual.parserPreset.parserOpts, 'object');
380+
t.deepEqual(
381+
actual.parserPreset.parserOpts.headerPattern,
382+
/^(\w*)(?:\((.*)\))?!?: (.*)$/
383+
);
384+
});

0 commit comments

Comments
 (0)