Skip to content

Commit 4b5300a

Browse files
authored
feat(config-conventional): use parser with short breaking change support (#821)
* feat(load): add parser preset factory support The latest conventional changelog parser options is loaded using a secondary promise. Load it before using the parserOpts property. * refactor(config-conventional): use preset with short breaking change * fix(config-conventional): define new parser as dependency
1 parent ecac29f commit 4b5300a

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

@commitlint/config-conventional/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
parserPreset: 'conventional-changelog-conventionalcommits',
23
rules: {
34
'body-leading-blank': [1, 'always'],
45
'footer-leading-blank': [1, 'always'],

@commitlint/config-conventional/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@
3333
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
3434
"devDependencies": {
3535
"@commitlint/utils": "^8.2.0"
36+
},
37+
"dependencies": {
38+
"conventional-changelog-conventionalcommits": "^4.1.0"
3639
}
3740
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
parserOpts: {
3+
parserPreset: './conventional-changelog-factory'
4+
}
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = Promise.resolve().then(
2+
() =>
3+
function factory() {
4+
return {
5+
parserOpts: {
6+
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
7+
}
8+
};
9+
}
10+
);

@commitlint/load/src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => {
3333
// Resolve parserPreset key
3434
if (typeof config.parserPreset === 'string') {
3535
const resolvedParserPreset = resolveFrom(base, config.parserPreset);
36+
let resolvedParserConfig = await require(resolvedParserPreset);
37+
38+
// Resolve loaded parser preset if its a factory
39+
if (typeof resolvedParserConfig === 'function') {
40+
resolvedParserConfig = await resolvedParserConfig();
41+
}
3642

3743
config.parserPreset = {
3844
name: config.parserPreset,
3945
path: resolvedParserPreset,
40-
parserOpts: (await require(resolvedParserPreset)).parserOpts
46+
parserOpts: resolvedParserConfig.parserOpts
4147
};
4248
}
4349

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

+14
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ test('uses seed with parserPreset', async t => {
8484
});
8585
});
8686

87+
test('uses seed with parserPreset factory', async t => {
88+
const cwd = await git.bootstrap('fixtures/parser-preset-factory');
89+
const {parserPreset: actual} = await load(
90+
{
91+
parserPreset: './conventional-changelog-factory'
92+
},
93+
{cwd}
94+
);
95+
t.is(actual.name, './conventional-changelog-factory');
96+
t.deepEqual(actual.parserOpts, {
97+
headerPattern: /^(\w*)(?:\((.*)\))?-(.*)$/
98+
});
99+
});
100+
87101
test('invalid extend should throw', async t => {
88102
const cwd = await git.bootstrap('fixtures/extends-invalid');
89103
await t.throws(load({}, {cwd}));

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,14 @@ conventional-changelog-angular@^5.0.3:
37073707
compare-func "^1.3.1"
37083708
q "^1.5.1"
37093709

3710+
conventional-changelog-conventionalcommits@^4.1.0:
3711+
version "4.1.0"
3712+
resolved "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.1.0.tgz#eb7d47a9c5f1a6f9846a649482294e4ac50d7683"
3713+
integrity sha512-J3xolGrH8PTxpCqueHOuZtv3Cp73SQOWiBQzlsaugZAZ+hZgcJBonmC+1bQbfGs2neC2S18p2L1Gx+nTEglJTQ==
3714+
dependencies:
3715+
compare-func "^1.3.1"
3716+
q "^1.5.1"
3717+
37103718
conventional-changelog-core@^3.1.6:
37113719
version "3.1.6"
37123720
resolved "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-3.1.6.tgz#ac1731a461c50d150d29c1ad4f33143293bcd32f"

0 commit comments

Comments
 (0)